Package com.jfinal.core

Examples of com.jfinal.core.Controller


   * 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

/**
* 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

    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

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

* Date: 13-5-7
*/
public class LoginInterceptor implements Interceptor {
    @Override
    public void intercept(ActionInvocation ai) {
        Controller controller = ai.getController();
        if(controller.getSessionAttr("user") != null){
            ai.invoke();
        }else{
            controller.setAttr("msg", "需要登录才可以进行改操作:)");
            controller.render("/user/login.html");
        }
    }
View Full Code Here

* Date: 13-3-30
*/
public class GlobalInterceptor implements Interceptor {
    @Override
    public void intercept(ActionInvocation ai) {
        Controller controller = ai.getController();

        controller.setAttr("moduleList", Module.dao.getList());
        // validate user info from bbs_id
        if(controller.getSessionAttr("user") == null && StringKit.notBlank(controller.getCookie("bbsID"))){
            String bbsID = controller.getCookie("bbsID");
            if(StringKit.notBlank(bbsID)){
                String[] userAndEmail = bbsID.split(Const.BBS_ID_SEPARATOR);
                User user = null;
                if(userAndEmail != null && userAndEmail.length == 2){
                    user = User.dao.getByEmailAndPassword(userAndEmail[0], userAndEmail[1]);
                }
                if(user != null){
                    controller.getSession().setMaxInactiveInterval(1800);
                    controller.setSessionAttr("user", user);
                    controller.setSessionAttr("userID", user.get("id"));
                }else{
                    ai.getController().removeCookie("bbsID");
                }
            }
        }
        ai.invoke();
        controller.setAttr("v", Const.TIMESTAMP);
    }
View Full Code Here

* Date: 13-4-4
*/
public class AdminInterceptor implements Interceptor {
    @Override
    public void intercept(ActionInvocation ai) {
        Controller controller = ai.getController();
        User user = controller.getSessionAttr("user");
        if (user != null && Const.ADMIN_EMAIL.equals(user.getStr("email"))){
            ai.invoke();
        }else{
            controller.setAttr("msg", "需要管理员权限");
            controller.renderError(500);
        }
    }
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.