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

The following examples show how to use javax.servlet.jsp.tagext.BodyContent#append() . 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: 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 2
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 3
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 4
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();
}