public static ReturnDef getReturnDef(ArrayList<ReturnDef> defs) {
    if (defs == null || defs.size() == 0) return null;

    PsnRuleEngine rule = ContextUtils.getPsnRuleEngine(ContextUtils.getRequest());

    for (ReturnDef def : defs) {
      try {
        if (def.getRule() == null) return def;
        if (rule.eval(def.getRule())) return def;
      } catch (Exception e) {
        logger.error("Error evaluating psn rule \"" + def.getRule() + "\"", e);
        return null;
      }
    }

    return null;
  }
Beispiel #2
0
  public int doStartTag() throws JspException {
    boolean result = false;

    try {
      result =
          ContextUtils.getPsnRuleEngine((HttpServletRequest) pageContext.getRequest()).eval(rule);
    } catch (Exception e) {
      logger.error("Error evaluating personalization rule defined in JSP: \"" + rule + "\"", e);
    }

    if (result) return EVAL_BODY_BUFFERED;
    else return SKIP_BODY;
  }
Beispiel #3
0
  public int doStartTag() throws JspException {
    try {
      SiteContext sc =
          (SiteContext) pageContext.getRequest().getAttribute(SiteContext.SITE_CONTEXT_KEY);
      AccessRuleEngine re =
          ContextUtils.getAccessRuleEngine((HttpServletRequest) pageContext.getRequest());

      Page page = null;
      Page currentInTree = sc.getPage();

      if (m_strParent != null) // 直接指定了要展现的根栏目
      page = (Page) pageContext.getAttribute(m_strParent);
      else if (m_iLevel > -1) { // 指定了要展现的级别
        if (m_iLevel <= currentInTree.getLevel()) {
          page = currentInTree;
          while (m_iLevel < page.getLevel()) page = page.getParent();
        }
      } else { // 没有指定根栏目
        TreeTag tt = (TreeTag) TagSupport.findAncestorWithClass(this, TreeTag.class);
        if (tt != null) page = tt.getPage();
        else page = sc.getBranch().getHome(re);
      }

      if (page == null) return SKIP_BODY;

      m_enum = Collections.enumeration(page.getPages(re, false, true));
      Object next = nextElement();
      if (next == null) return SKIP_BODY;

      m_bFirst = true;

      if (m_strName != null) pageContext.setAttribute(m_strName, next);
      return EVAL_BODY_BUFFERED;
    } catch (Exception e) {
      e.printStackTrace();
      throw new JspException(e.getMessage());
    }
  }