Package com.jfinal.core

Source Code of com.jfinal.core.ActionReporter

/**
* Copyright (c) 2011-2013, James Zhan 詹波 (jfinal@126.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.jfinal.core;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.jfinal.aop.Interceptor;

/**
* ActionReporter
*/
final class ActionReporter {
 
  private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
  /**
   * Report action before action invoking when the common request coming
   */
  static final boolean reportCommonRequest(Controller controller, Action action) {
    String content_type = controller.getRequest().getContentType();
    if (content_type == null || content_type.toLowerCase().indexOf("multipart") == -1) {  // if (content_type == null || content_type.indexOf("multipart/form-data") == -1) {
      doReport(controller, action);
      return false;
    }
    return true;
  }
 
  /**
   * Report action after action invoking when the multipart request coming
   */
  static final void reportMultipartRequest(Controller controller, Action action) {
    doReport(controller, action);
  }
 
  private static final void doReport(Controller controller, Action action) {
    StringBuilder sb = new StringBuilder("\nJFinal action report -------- ").append(sdf.format(new Date())).append(" ------------------------------\n");
    Class<? extends Controller> cc = action.getControllerClass();
    sb.append("Controller  : ").append(cc.getName()).append(".(").append(cc.getSimpleName()).append(".java:1)");
    sb.append("\nMethod      : ").append(action.getMethodName()).append("\n");
   
    String urlParas = controller.getPara();
    if (urlParas != null) {
      sb.append("UrlPara     : ").append(urlParas).append("\n");
    }
   
    Interceptor[] inters = action.getInterceptors();
    if (inters.length > 0) {
      sb.append("Interceptor : ");
      for (int i=0; i<inters.length; i++) {
        if (i > 0)
          sb.append("\n              ");
        Interceptor inter = inters[i];
        Class<? extends Interceptor> ic = inter.getClass();
        sb.append(ic.getName()).append(".(").append(ic.getSimpleName()).append(".java:1)");
      }
      sb.append("\n");
    }
   
    // print all parameters
    HttpServletRequest request = controller.getRequest();
    Enumeration<String> e = request.getParameterNames();
    if (e.hasMoreElements()) {
      sb.append("Parameter   : ");
      while (e.hasMoreElements()) {
        String name = e.nextElement();
        String[] values = request.getParameterValues(name);
        if (values.length == 1) {
          sb.append(name).append("=").append(values[0]);
        }
        else {
          sb.append(name).append("[]={");
          for (int i=0; i<values.length; i++) {
            if (i > 0)
              sb.append(",");
            sb.append(values[i]);
          }
          sb.append("}");
        }
        sb.append("  ");
      }
      sb.append("\n");
    }
    sb.append("--------------------------------------------------------------------------------\n");
    System.out.print(sb.toString());
  }
}
TOP

Related Classes of com.jfinal.core.ActionReporter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.