Package com.jfinal.core

Examples of com.jfinal.core.Controller


* Date: 13-5-7
*/
public class UserCheckInterceptor implements Interceptor {
    @Override
    public void intercept(ActionInvocation ai) {
        Controller controller = ai.getController();
        String userID = controller.getSessionAttr("userID").toString();
        if(StringKit.notBlank(userID) && userID.equals(controller.getPara(0, "0") + "")){
            ai.invoke();
        }else{
            controller.setAttr("msg", "只有该登录用户本人才有权操作");
            controller.renderError(500);
        }
    }
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

*/
public class ManagerPowerInterceptor implements Interceptor {

  @SuppressWarnings("unchecked")
  public void intercept(ActionInvocation ai) {
    Controller ctrl=ai.getController();
    ctrl.setAttr("root","");
    ctrl.setAttr("StaticCfg", new StaticCfg());
//    Record po= (Record)ctrl.getSessionAttr("manager");
    String sid=ctrl.getSession().getId();
    Record po=(Record)MemcacheTool.mcc.get(sid);
    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){
        v=p.v();
        code=p.code();
      }
      p=ai.getMethod().getAnnotation(PowerBind.class);
      if(p!=null){
        v=p.v();
        code=p.code();
      }
      boolean f=false;
      if(v==true){
        /**菜单权限判断*/
        List<Record> menus=(List<Record>)MemcacheTool.mcc.get("menu"+sid);
        if(menus!=null&&menus.isEmpty()==false){
          if(checkPower(menus,ai.getActionKey(),code)){//链接或安全码匹配
            ctrl.setAttr("powersafecodelist",MemcacheTool.mcc.get("powersafecodelist"+sid));
            ai.invoke();//注意 一定要执行此方法
          }else{
            f=true;
          }
        }else{
          f=true;
        }
      }else{
        ai.invoke();//注意 一定要执行此方法
      }
      if(f)
      ctrl.renderText("{\"statusCode\":300,\"message\":\"<font color='red'><B>您未有此操作权限!请勿越权操作!<br>请重新登录获得最新权限设置!</B></font>\"}");
    }
  }
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)
      injectField(controller, field);
   
    ai.invoke();
  }
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

    if (set.contains(methodName)) {
      ai.getController().renderError404();
      return ;
    }
   
    Controller controller = ai.getController();
    String controllerKey = ai.getControllerKey();
    String method = controller.getRequest().getMethod().toUpperCase();
    String urlPara = controller.getPara();
    if ("GET".equals(method)) {
      if (urlPara != null) {
        controller.forwardAction(controllerKey + "/show/" + urlPara);
        return ;
      }
    }
    else if ("POST".equals(method)) {
      controller.forwardAction(controllerKey + "/save");
      return ;
    }
    else if ("PUT".equals(method)) {
      controller.forwardAction(controllerKey + "/update/" + urlPara);
      return ;
    }
    else if ("DELETE".equals(method)) {
      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.renderError404();
  }
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.renderError404();
  }
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.renderError404();
  }
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.