本文整理汇总了Java中com.googlecode.htmlcompressor.compressor.HtmlCompressor.compress方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlCompressor.compress方法的具体用法?Java HtmlCompressor.compress怎么用?Java HtmlCompressor.compress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.htmlcompressor.compressor.HtmlCompressor
的用法示例。
在下文中一共展示了HtmlCompressor.compress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.googlecode.htmlcompressor.compressor.HtmlCompressor; //导入方法依赖的package包/类
public String process(String src) {
HtmlCompressor compressor = new HtmlCompressor();
compressor.setEnabled(true);
compressor.setCompressCss(false);
compressor.setCompressJavaScript(false);
compressor.setGenerateStatistics(false);
compressor.setRemoveComments(options.isRemoveComments());
compressor.setRemoveMultiSpaces(options.isRemoveMutliSpaces());
compressor.setRemoveIntertagSpaces(options.isRemoveIntertagSpaces());
compressor.setRemoveQuotes(options.isRemoveQuotes());
compressor.setSimpleDoctype(options.isSimpleDoctype());
compressor.setRemoveScriptAttributes(options.isRemoveScriptAttributes());
compressor.setRemoveStyleAttributes(options.isRemoveStyleAttributes());
compressor.setRemoveLinkAttributes(options.isRemoveLinkAttributes());
compressor.setRemoveFormAttributes(options.isRemoveFormAttributes());
compressor.setRemoveInputAttributes(options.isRemoveInputAttributes());
compressor.setSimpleBooleanAttributes(options.isSimpleBooleanAttributes());
compressor.setRemoveJavaScriptProtocol(options.isRemoveJavaScriptProtocol());
compressor.setRemoveHttpProtocol(options.isRemoveHttpProtocol());
compressor.setRemoveHttpsProtocol(options.isRemoveHttpsProtocol());
compressor.setPreserveLineBreaks(options.isPreserveLineBreaks());
return compressor.compress(src);
}
示例2: save
import com.googlecode.htmlcompressor.compressor.HtmlCompressor; //导入方法依赖的package包/类
public void save() throws IOException {
String content = core.toString();
if (JRenderConfig.Server.View.useMinified) {
HtmlCompressor html = new HtmlCompressor();
html.setRemoveIntertagSpaces(true);
content = html.compress(content);
}
FileUtils.createFile(content, jrenderPath + "/core.js");
}
示例3: close
import com.googlecode.htmlcompressor.compressor.HtmlCompressor; //导入方法依赖的package包/类
public void close() throws IOException {
if (closed) {
throw new IOException(
"This output stream has already been closed");
}
String contentType = response.getContentType();
if (contentType != null && contentType.startsWith("text/html")) {
String html = baos.toString();
// { extract JSON-LD before compression, HtmlCompressor cannot
// handle them
ArrayList<String> jsonLd = new ArrayList<String>();
while (true) {
Matcher m = JSON_LD.matcher(html);
if (!m.find())
break;
jsonLd.add(m.group(2).replace("\n", "").replace("\r", ""));
html = m.replaceFirst("");
}
// }
HtmlCompressor compressor = new HtmlCompressor();
compressor.setCompressJavaScript(true);
compressor.setCompressCss(true);
html = compressor.compress(html);
// insert JSON-LD back to before </head> or </body>
if (jsonLd.size() > 0) {
StringBuffer sb = new StringBuffer();
for (String str : jsonLd)
sb.append("<script type=\"application/ld+json\">")
.append(str).append("</script>");
String lower = html.toLowerCase();
int idx = lower.indexOf("</head>");
if (idx <= 0)
idx = lower.indexOf("</body>");
if (idx > 0)
html = html.substring(0, idx) + sb.toString()
+ html.substring(idx);
}
output.write(html.getBytes());
} else
output.write(baos.toByteArray());
output.flush();
output.close();
closed = true;
}