Java Code Examples for javax.servlet.jsp.tagext.BodyContent#clearBody()

The following examples show how to use javax.servlet.jsp.tagext.BodyContent#clearBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShowNavigationTag.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	// Reset optional attribute value
	declaringPlugin = null;
	extension = null;

	// Emit body content
	try {
		BodyContent currentBodyContent = getBodyContent();

		if (currentBodyContent != null) {
			if (!navigationDataList.isEmpty()) {
				currentBodyContent.writeOut(getPreviousOut());
			}
			currentBodyContent.clearBody();
		}
	} catch (IOException e) {
		logger.error("Error in ShowNavigationTag.doEndTag: " + e.getMessage(), e);
	}
	return EVAL_PAGE;
}
 
Example 2
Source File: ComShowTableTag.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets attribute for the pagecontext.
 */
@Override
public int doAfterBody() throws JspException {
	BodyContent currentBodyContent = getBodyContent();
	if (currentBodyContent != null) {
		try {
			currentBodyContent.getEnclosingWriter().write(currentBodyContent.getString());
		} catch (IOException e) {
			logger.error("Error writing body content", e);
		}
		currentBodyContent.clearBody();
	}

	Map<String, Object> result = getNextRecord();

	if (result != null) {
		setResultInPageContext(result);

		return EVAL_BODY_BUFFERED;
	} else {
		return SKIP_BODY;
	}
}
 
Example 3
Source File: SumBodyTagHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Fill in this method to process the body content of the tag.
 * You only need to do this if the tag's BodyContent property
 * is set to "JSP" or "tagdependent."
 * If the tag's bodyContent is set to "empty," then this method
 * will not be called.
 */
private void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException {
    //
    // TODO: insert code to write html before writing the body content.
    // e.g.:
    //
    out.println("<p>");
    out.println("Sum of " + x + " and " + y + " is " + (x+y));
    out.println("<br/>");
    
    //
    // write the body content (after processing by the JSP engine) on the output Writer
    //
    bodyContent.writeOut(out);
    
    out.println("<br/>");
    out.println("END of sum");
    out.println("</p>");
    
    
    // clear the body content for the next time through.
    bodyContent.clearBody();
}
 
Example 4
Source File: StringTag.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {

  // retrieve parent tag which accepts the result of this operation
  ValueAcceptingTagIF acceptingTag = (ValueAcceptingTagIF)
    findAncestorWithClass(this, ValueAcceptingTagIF.class);

  // get body content which should contain the string we want to set.
  BodyContent body = getBodyContent();
  String content = body.getString();

  // construct new collection which consists of one String entry
  // kick it over to the nearest accepting tag
  acceptingTag.accept( Collections.singleton(content) );

  // reset body contents
  body.clearBody();
  
  return SKIP_BODY;
}
 
Example 5
Source File: AttributeTag.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {
  ElementTag elementTag = (ElementTag)
    findAncestorWithClass(this, ElementTag.class);

  if (elementTag != null) {
    // get body content
    BodyContent body = getBodyContent();
    if (body != null) {
      String content = body.getString();
      // add this attribute to parent element tag 
      elementTag.addAttribute(attrName, content);
      body.clearBody();
    } else {
      log.warn("AttributeTag: body content is null!");
    }
  } else {
    log.warn("AttributeTag: no parent element tag found!");
  }
  
  // only evaluate body once
  return SKIP_BODY;
}
 
Example 6
Source File: AssociationTypeLoopTag.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {
  // put out the evaluated body
  BodyContent body = getBodyContent();
  JspWriter out = null;
  try {
    out = body.getEnclosingWriter();
    out.print(body.getString());
    body.clearBody();
  } catch(IOException ioe) {
    throw new NavigatorRuntimeException("Error in AssociationTypeLoopTag.", ioe);
  }

  // test if we have to repeat the body 
  if (index < assocStore.length) {
    // set to next value in list
    setVariableValues(assocStore[index]);
    index++;
    return EVAL_BODY_AGAIN;
  } else {
    return SKIP_BODY;
  }
  
}
 
Example 7
Source File: ComShowTableTag.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int doEndTag() {
	BodyContent currentBodyContent = getBodyContent();

	if (currentBodyContent != null) {
		currentBodyContent.clearBody();
	}

	return EVAL_PAGE;
}
 
Example 8
Source File: ElementTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {
  BodyContent body = getBodyContent();
  StringBuilder complElem = new StringBuilder(100);
  complElem.append("<").append(elemName);
  // put in attribute-value pairs
  Iterator it = attrnames.iterator();
  String key, val;    
  while (it.hasNext()) {
    key = (String) it.next();
    val = (String) attrs.get(key);
    complElem.append(" ").append(key).append("='").append(val).append("'");
  }
  complElem.append(">");

  // append body content
  complElem.append( body.getString() );
  complElem.append("</").append(elemName).append(">");
  
  // write it out
  try {
    JspWriter out = body.getEnclosingWriter();
    out.print( complElem.toString() );
    body.clearBody();
  } catch (IOException ioe) {
    throw new NavigatorRuntimeException("Error in ElementTag. JspWriter not there.", ioe);
  }
  
  // only evaluate body once
  return SKIP_BODY;
}
 
Example 9
Source File: IfThenTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {
  // we have already checked the condition in doStartTag
  try {
    BodyContent body = getBodyContent();
    JspWriter out = body.getEnclosingWriter();
    out.print( body.getString() );
    body.clearBody();
  } catch (IOException e) {
    throw new NavigatorRuntimeException("Problem occurred when writing to JspWriter in logic:then.", e);
  }

  return SKIP_BODY;
}
 
Example 10
Source File: IfElseTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Actions after some body has been evaluated.
 */
@Override
public int doAfterBody() throws JspTagException {
  // we have already checked the condition in doStartTag
  try {
    BodyContent body = getBodyContent();
    JspWriter out = body.getEnclosingWriter();
    out.print( body.getString() );
    body.clearBody();
  } catch(IOException ioe) {
    throw new JspTagException("Problem occurred when writing to JspWriter in logic:else: " + ioe);
  }

  return SKIP_BODY;
}
 
Example 11
Source File: PutTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public int doAfterBody() throws JspException {
  BodyContent bodyContent = getBodyContent();
  String content = bodyContent.getString();

  // save body content into params after evaluation
  if (log.isDebugEnabled())
    log.debug("doAfterBody: register variable '"+name+"'.");

  putParameter(content, true);

  bodyContent.clearBody();
  return SKIP_BODY;
}
 
Example 12
Source File: JSPPageExecuter.java    From ontopia with Apache License 2.0 4 votes vote down vote up
/**
 * Executes the children of this node.
 */
protected void runTag(TagSupport parentTag, JSPTreeNodeIF node)
  throws JspException, IOException {

  //System.out.println("Running: " + node);
  
  List<JSPTreeNodeIF> children = node.getChildren();
  for (JSPTreeNodeIF curNode : children) {
    TagSupport curTag = curNode.getTag();

    // if content tag just put it out and proceed with next
    if (curTag == null) {
      pageContext.getOut().write(curNode.getContent());
      continue;
    }

    // initialize tag
    //! curTag.setParent(node.getTag());
    curTag.setParent(parentTag);
    curTag.setPageContext(pageContext);
    setAttributeValues(curNode, curTag);
    
    // run tag
    int startTagToken = curTag.doStartTag();
    if (startTagToken != TagSupport.SKIP_BODY) {

      if (startTagToken == BodyTagSupport.EVAL_BODY_BUFFERED) {
        // check if BodyTagSupport instance  
        BodyTagSupport btag = (BodyTagSupport) curTag;
        BodyContent body = pageContext.pushBody();
        body.clearBody(); // TOMCAT MADE ME DO IT :-(
        btag.setBodyContent(body);
        btag.doInitBody();

        loopTag(btag, curNode);

        // Release the body
        pageContext.popBody();
      } else if (startTagToken == BodyTagSupport.EVAL_BODY_INCLUDE) {
        loopTag(curTag, curNode);
      } else {
        throw new OntopiaRuntimeException("Internal error: unknown doStartTag token: " + startTagToken);
      }
      
    }
    // FIXME: Handle SKIP_PAGE;
    curTag.doEndTag();
    //tag.release(); FIXME: having this call here can't possibly be correct
  } // for i
}