コード例 #1
0
  @Override
  public Object exec(List args) throws TemplateModelException {
    // old way: resourcePath = FreemarkerUtil.getDataModel("_r.pathInfo",String.class);
    RequestContext rc = FreemarkerUtil.getDataModel("_r.rc", RequestContext.class);
    String resourcePath = rc.getResourcePath();

    String pathInfoMatch = FreemarkerUtil.getParamAs(args.get(0), String.class);

    /*--------- Get the eventual true/false values ---------*/
    String trueValue = null;
    String falseValue = null;
    if (args.size() > 1) {
      trueValue = FreemarkerUtil.getParamAs(args.get(1), String.class);
      falseValue = ""; // by default the false value will be empty
    }

    if (args.size() > 2) {
      falseValue = FreemarkerUtil.getParamAs(args.get(2), String.class);
    }
    /*--------- /Get the eventual true/false values ---------*/

    /*--------- Match the string ---------*/
    boolean match = false;
    switch (mode) {
      case IS:
        if (resourcePath.equals(pathInfoMatch)) {
          match = true;
        }
        break;
      case STARTS_WITH:
        if (resourcePath.startsWith(pathInfoMatch)) {
          match = true;
        }
        break;
    }
    /*--------- /Match the string ---------*/

    /*--------- Return the value ---------*/
    if (trueValue != null) {
      return match ? trueValue : falseValue;
    } else {
      return match;
    }
  }
コード例 #2
0
  @Override
  public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    Object result;

    String name =
        methodInvocation.getMethod().getDeclaringClass().getSimpleName()
            + "."
            + methodInvocation.getMethod().getName();

    RequestContext rc = (crch != null) ? crch.getCurrentRequestContext() : null;
    RcPerf rcPerf = (rc != null) ? rc.getData(RcPerf.class) : null;

    PerfContext requestPerfContext = (rcPerf != null) ? rcPerf.start(name) : null;
    PerfContext methodPerfContext = (perfManager != null) ? perfManager.startMethod(name) : null;
    try {
      result = methodInvocation.proceed();
    } finally {
      if (methodPerfContext != null) methodPerfContext.end();
      if (requestPerfContext != null) requestPerfContext.end();
    }
    return result;
  }