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

The following examples show how to use javax.servlet.jsp.tagext.BodyContent#writeOut() . 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: 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 3
Source File: XmlCompressorTag.java    From htmlcompressor with Apache License 2.0 6 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();
	
	XmlCompressor compressor = new XmlCompressor();
	compressor.setEnabled(enabled);
	compressor.setRemoveComments(removeComments);
	compressor.setRemoveIntertagSpaces(removeIntertagSpaces);
	
	try {
		bodyContent.clear();
		bodyContent.append(compressor.compress(content));
		bodyContent.writeOut(pageContext.getOut());
	} catch (Exception e) {
		throw new JspException("Failed to compress xml",e);
	}
	
	return super.doEndTag();
}
 
Example 4
Source File: AbstractHtmlElementBodyTag.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * The user customised the output of the error messages - flush the
 * buffered content into the main {@link javax.servlet.jsp.JspWriter}.
 */
protected void flushBufferedBodyContent(BodyContent bodyContent) throws JspException {
	try {
		bodyContent.writeOut(bodyContent.getEnclosingWriter());
	}
	catch (IOException ex) {
		throw new JspException("Unable to write buffered body content.", ex);
	}
}
 
Example 5
Source File: AbstractHtmlElementBodyTag.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * The user customised the output of the error messages - flush the
 * buffered content into the main {@link javax.servlet.jsp.JspWriter}.
 */
protected void flushBufferedBodyContent(BodyContent bodyContent) throws JspException {
	try {
		bodyContent.writeOut(bodyContent.getEnclosingWriter());
	}
	catch (IOException ex) {
		throw new JspException("Unable to write buffered body content.", ex);
	}
}
 
Example 6
Source File: AbstractHtmlElementBodyTag.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The user customised the output of the error messages - flush the
 * buffered content into the main {@link javax.servlet.jsp.JspWriter}.
 */
protected void flushBufferedBodyContent(BodyContent bodyContent) throws JspException {
	try {
		bodyContent.writeOut(bodyContent.getEnclosingWriter());
	}
	catch (IOException ex) {
		throw new JspException("Unable to write buffered body content.", ex);
	}
}
 
Example 7
Source File: AbstractHtmlElementBodyTag.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * The user customised the output of the error messages - flush the
 * buffered content into the main {@link javax.servlet.jsp.JspWriter}.
 */
protected void flushBufferedBodyContent(BodyContent bodyContent) throws JspException {
	try {
		bodyContent.writeOut(bodyContent.getEnclosingWriter());
	}
	catch (IOException e) {
		throw new JspException("Unable to write buffered body content.", e);
	}
}
 
Example 8
Source File: CssCompressorTag.java    From htmlcompressor with Apache License 2.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();

	try {
		if(enabled) {
			//call YUICompressor
			YuiCssCompressor compressor = new YuiCssCompressor();
			compressor.setLineBreak(yuiCssLineBreak);
			String result = compressor.compress(content);

			bodyContent.clear();
			bodyContent.append(result);
			bodyContent.writeOut(pageContext.getOut());
		} else {
			bodyContent.clear();
			bodyContent.append(content);
			bodyContent.writeOut(pageContext.getOut());
		}
	} catch (Exception e) {
		throw new JspException("Failed to compress css",e);
	}
	
	return super.doEndTag();
}
 
Example 9
Source File: NormalizeWhitespaceTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public int doEndTag() throws JspException {
  BodyContent bc = getBodyContent();
  if (bc != null) {
    try {
      NormalizeWhitespaceWriter nww = new NormalizeWhitespaceWriter(getBodyContent().getEnclosingWriter());
      bc.writeOut(nww);
      // make sure orphaned whitespace is flushed
      nww.done();
    } catch (IOException e) {
      throw new JspException(e);
    }
  }
  return EVAL_PAGE;
}
 
Example 10
Source File: HtmlCompressorTag.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();
	
	HtmlCompressor htmlCompressor = new HtmlCompressor();
	htmlCompressor.setEnabled(enabled);
	htmlCompressor.setRemoveComments(removeComments);
	htmlCompressor.setRemoveMultiSpaces(removeMultiSpaces);
	htmlCompressor.setRemoveIntertagSpaces(removeIntertagSpaces);
	htmlCompressor.setRemoveQuotes(removeQuotes);
	htmlCompressor.setPreserveLineBreaks(preserveLineBreaks);
	htmlCompressor.setCompressJavaScript(compressJavaScript);
	htmlCompressor.setCompressCss(compressCss);
	htmlCompressor.setYuiJsNoMunge(yuiJsNoMunge);
	htmlCompressor.setYuiJsPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
	htmlCompressor.setYuiJsDisableOptimizations(yuiJsDisableOptimizations);
	htmlCompressor.setYuiJsLineBreak(yuiJsLineBreak);
	htmlCompressor.setYuiCssLineBreak(yuiCssLineBreak);

	htmlCompressor.setSimpleDoctype(simpleDoctype);
	htmlCompressor.setRemoveScriptAttributes(removeScriptAttributes);
	htmlCompressor.setRemoveStyleAttributes(removeStyleAttributes);
	htmlCompressor.setRemoveLinkAttributes(removeLinkAttributes);
	htmlCompressor.setRemoveFormAttributes(removeFormAttributes);
	htmlCompressor.setRemoveInputAttributes(removeInputAttributes);
	htmlCompressor.setSimpleBooleanAttributes(simpleBooleanAttributes);
	htmlCompressor.setRemoveJavaScriptProtocol(removeJavaScriptProtocol);
	htmlCompressor.setRemoveHttpProtocol(removeHttpProtocol);
	htmlCompressor.setRemoveHttpsProtocol(removeHttpsProtocol);
	
	if(compressJavaScript && jsCompressor.equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
		ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
		if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
			closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
		} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
			closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
		} else {
			closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
		}
		htmlCompressor.setJavaScriptCompressor(closureCompressor);
	}
	
	try {
		bodyContent.clear();
		bodyContent.append(htmlCompressor.compress(content));
		bodyContent.writeOut(pageContext.getOut());
	} catch (Exception e) {
		throw new JspException("Failed to compress html",e);
	}
	
	return super.doEndTag();
}
 
Example 11
Source File: JavaScriptCompressorTag.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();

	try {
		if(enabled) {
			
			String result = content;
			
			if(jsCompressor.equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
				//call Closure compressor
				ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
				if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
					closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
				} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
					closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
				} else {
					closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
				}
				
				result = closureCompressor.compress(content);
				
			} else {
				//call YUICompressor
				YuiJavaScriptCompressor yuiCompressor = new YuiJavaScriptCompressor();
				yuiCompressor.setDisableOptimizations(yuiJsDisableOptimizations);
				yuiCompressor.setLineBreak(yuiJsLineBreak);
				yuiCompressor.setNoMunge(yuiJsNoMunge);
				yuiCompressor.setPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
				
				result = yuiCompressor.compress(content);
			}
			
			bodyContent.clear();
			bodyContent.append(result);
			bodyContent.writeOut(pageContext.getOut());
		} else {
			bodyContent.clear();
			bodyContent.append(content);
			bodyContent.writeOut(pageContext.getOut());
		}

	} catch (Exception e) {
		throw new JspException("Failed to compress javascript",e);
	}
	
	return super.doEndTag();
}