Package com.jfinal.core

Examples of com.jfinal.core.Controller


2012-9-6 下午8:32:53
*/
public class ManagerPowerInterceptor implements Interceptor {

  public void intercept(ActionInvocation ai) {
    Controller ctrl=ai.getController();
    ctrl.setAttr("root",ctrl.getRequest().getContextPath());
    ctrl.setAttr("StaticCfg", new StaticCfg());
    String user_token=ctrl.getCookie("user_token");
    Record po=(Record)MemcacheTool.mcc.get(user_token);
    if(po==null){
      /*String ckey=ai.getControllerKey();
      if(ckey.contains("webadmin")){
        ctrl.redirect(ctrl.getRequest().getContextPath()+"/webadmin");
      }else*/
      ctrl.renderText("{\"statusCode\":301,\"message\":\"登录超时,请重新登录!\"}");
    }else{
      /*boolean v=true;
      String code=null;
      PowerBind p=ai.getController().getClass().getAnnotation(PowerBind.class);
      if(p!=null){
View Full Code Here


    ReentrantLock previousLock = lockMap.putIfAbsent(key, lock);
    return previousLock == null ? lock : previousLock;
  }
 
  final public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    String cacheName = buildCacheName(ai, controller);
    String cacheKey = buildCacheKey(ai, controller);
    Map<String, Object> cacheData = CacheKit.get(cacheName, cacheKey);
    if (cacheData == null) {
      Lock lock = getLock(cacheName);
View Full Code Here

   * PUT    /user/id    --->  update
   * DELECT  /user/id    --->  delete
   */
  public void intercept(ActionInvocation ai) {
    // 阻止 JFinal 原有规则 action 请求
    Controller controller = ai.getController();
    Boolean isRestfulForward = controller.getAttr(isRestfulForwardKey);
    String methodName = ai.getMethodName();
    if (set.contains(methodName) && isRestfulForward== null) {
      ai.getController().renderError(404);
      return ;
    }
   
    if (isRestfulForward != null && isRestfulForward) {
      ai.invoke();
      return ;
    }
   
    String controllerKey = ai.getControllerKey();
    String method = controller.getRequest().getMethod().toUpperCase();
    String urlPara = controller.getPara();
    if ("GET".equals(method)) {
      if (urlPara != null && !"edit".equals(methodName)) {
        controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
        controller.forwardAction(controllerKey + "/show/" + urlPara);
        return ;
      }
    }
    else if ("POST".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/save");
      return ;
    }
    else if ("PUT".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/update/" + urlPara);
      return ;
    }
    else if ("DELETE".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/delete/" + urlPara);
      return ;
    }
   
    ai.invoke();
  }
View Full Code Here

/**
* Accept GET method only.
*/
public class GET implements Interceptor {
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    if ("GET".equalsIgnoreCase(controller.getRequest().getMethod()))
      ai.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

/**
* Accept POST method only.
*/
public class POST implements Interceptor {
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    if ("POST".equalsIgnoreCase(controller.getRequest().getMethod().toUpperCase()))
      ai.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

 
  @SuppressWarnings({"rawtypes", "unchecked"}) 
  public void intercept(ActionInvocation ai) {
    ai.invoke();
   
    Controller c = ai.getController();
    HttpSession hs = c.getSession(createSession);
    if (hs != null) {
      Map session = new JFinalSession(hs);
      for (Enumeration<String> names=hs.getAttributeNames(); names.hasMoreElements();) {
        String name = names.nextElement();
        session.put(name, hs.getAttribute(name));
      }
      c.setAttr("session", session);
    }
  }
View Full Code Here

public class IocInterceptor implements Interceptor {
 
  static ApplicationContext ctx;
 
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    Field[] fields = controller.getClass().getDeclaredFields();
    for (Field field : fields) {
      Object bean = null;
      if (field.isAnnotationPresent(Inject.BY_NAME.class))
        bean = ctx.getBean(field.getName());
      else if (field.isAnnotationPresent(Inject.BY_TYPE.class))
View Full Code Here

/**
* Force action no urlPara, otherwise render error 404 to client.
*/
public class NoUrlPara implements Interceptor {
  public void intercept(ActionInvocation invocation) {
    Controller controller = invocation.getController();
    if (controller.getPara() == null)
      invocation.invoke();
    else
      controller.renderError(404);
  }
View Full Code Here

* Created by wangrenhui on 14-4-16.
*/
public class UrlInterceptor implements Interceptor {
  @Override
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    HttpServletRequest request = controller.getRequest();
    //webRoot
    controller.setAttr("_webRootPath", request.getScheme() + "://"
        + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort())
        + request.getContextPath());

    ai.invoke();

    if (!ThreadLocalKit.isJson(controller)) {
      //local 数据
      controller.setAttr("_localParas", request.getQueryString());
      controller.setAttr("_localUri", ai.getActionKey());
    }

    controller.keepPara("_webRootPath", "_localParas", "_localUri");
    //i18n
//    String tmp = controller.getCookie(Const.I18N_LOCALE);
//    String i18n = controller.getRequest().getLocale().toString();
//    if (!i18n.equals(tmp)) {
//      ai.getController().setCookie(Const.I18N_LOCALE, i18n, Const.DEFAULT_I18N_MAX_AGE_OF_COOKIE);
View Full Code Here

* Created by wangrenhui on 14-4-16.
*/
public class UrlInterceptor implements Interceptor {
  @Override
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    HttpServletRequest request = controller.getRequest();
    //webRoot
    controller.setAttr("_webRootPath", request.getScheme() + "://"
        + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort())
        + request.getContextPath());

    ai.invoke();

    if (!ThreadLocalUtil.isJson(controller)) {
      //local 数据
      controller.setAttr("_localParas", request.getQueryString());
      controller.setAttr("_localUri", ai.getActionKey());
    }

    controller.keepPara("_webRootPath", "_localParas", "_localUri");
    //i18n
//    String tmp = controller.getCookie(Const.I18N_LOCALE);
//    String i18n = controller.getRequest().getLocale().toString();
//    if (!i18n.equals(tmp)) {
//      ai.getController().setCookie(Const.I18N_LOCALE, i18n, Const.DEFAULT_I18N_MAX_AGE_OF_COOKIE);
View Full Code Here

TOP

Related Classes of com.jfinal.core.Controller

Copyright © 2018 www.massapicom. 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.