Example #1
0
  public int doAfterBody() throws JspException {
    CalendarTag calendartag =
        (CalendarTag) TagSupport.findAncestorWithClass(this, CalendarTag.class);
    if (calendartag == null) {
      throw new JspException("Could not find ancestor calendarTag");
    }
    BodyContent bodycontent = getBodyContent();
    String s;
    if (bodycontent == null) {
      s = "";
    } else {
      s = bodycontent.getString();
    }
    s = s.trim();
    if (s.length() > 0) {
      if (day == -1) {
        for (int i = 0; i < 31; i++) {
          calendartag.setDateTarget(i, s);
        }

      } else {
        if (day <= 0 || day > 31) {
          throw new JspException("Invalid day:" + day);
        }
        calendartag.setDateTarget(day - 1, s);
      }
    }
    return 0;
  }
Example #2
0
  /**
   * Return the XPathContext to be used for evaluating expressions.
   *
   * <p>If the child is nested withing a forEach tag its iteration context is used. Otherwise, a new
   * context is created based on an empty Document.
   *
   * @param child the tag whose context should be returned
   * @param pageContext the current page context
   * @return the XPath evaluation context
   */
  public static XPathContext getContext(Tag child, PageContext pageContext) {
    // if within a forEach tag, use its context
    ForEachTag forEachTag = (ForEachTag) TagSupport.findAncestorWithClass(child, ForEachTag.class);
    if (forEachTag != null) {
      return forEachTag.getContext();
    }

    // otherwise, create a new context referring to an empty document
    XPathContext context = new XPathContext(false);
    VariableStack variableStack = new JSTLVariableStack(pageContext);
    context.setVarStack(variableStack);
    int dtm = context.getDTMHandleFromNode(newEmptyDocument());
    context.pushCurrentNodeAndExpression(dtm, dtm);
    return context;
  }
Example #3
0
  /** Add the parameter and its value to the link tag */
  public int doEndTag() throws JspException {
    // parent tag must be a LinkTag, gives access to methods in parent
    LinkTag myparent =
        (LinkTag) javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, LinkTag.class);

    if (myparent == null) throw new JspException("linkparam tag not nested within link tag");
    else {
      BodyContent bodyContent = getBodyContent();
      if (bodyContent != null && !bodyContent.getString().equals("")) {
        setValue(bodyContent.getString());
      } else if (getValue() == null) setValue("null");
      //                throw new JspException("Unable to assign a value to the parameter: '" +
      // getId() + "'");
      myparent.addRequestParameter(getId(), getValue());
    }
    return SKIP_BODY;
  }
 public int doStartTag() throws JspException {
   IterateTag itag = (IterateTag) TagSupport.findAncestorWithClass(this, IterateTag.class);
   if (itag == null) {
     Debug.println("RowTag.doStartTag: no enclosing 'iterate' tag found.");
   } else if (itag.isEmpty()) {
     return Tag.SKIP_BODY;
   } else {
     current_row = itag.currentElement();
     if (current_row != null && itag.getBeanId() != null) {
       // This is so that if the current row is a bean, jsp:useBean will work
       // inside of iterations.
       pageContext.setAttribute(itag.getBeanId(), current_row);
       Debug.println("storing record in page scope: " + current_row);
     }
     return (current_row == null
         ? Tag.SKIP_BODY // no more elements. iteration complete.
         : Tag.EVAL_BODY_INCLUDE);
   }
   return Tag.SKIP_BODY;
 }
Example #5
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());
    }
  }
  @Override
  protected final int doStartTagInternal() throws JspException {
    if (this.value != null) {
      // Find the containing EditorAwareTag (e.g. BindTag), if applicable.
      EditorAwareTag tag =
          (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class);
      if (tag == null) {
        throw new JspException(
            "TransformTag can only be used within EditorAwareTag (e.g. BindTag)");
      }

      // OK, let's obtain the editor...
      String result = null;
      PropertyEditor editor = tag.getEditor();
      if (editor != null) {
        // If an editor was found, edit the value.
        editor.setValue(this.value);
        result = editor.getAsText();
      } else {
        // Else, just do a toString.
        result = this.value.toString();
      }
      result = htmlEscape(result);
      if (this.var != null) {
        pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope));
      } else {
        try {
          // Else, just print it out.
          pageContext.getOut().print(result);
        } catch (IOException ex) {
          throw new JspException(ex);
        }
      }
    }

    return SKIP_BODY;
  }