当前位置: 首页>>代码示例>>Java>>正文


Java HtmlCompressor.compress方法代码示例

本文整理汇总了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);
}
 
开发者ID:instant-solutions,项目名称:gradle-website-optimizer,代码行数:27,代码来源:HtmlProcessor.java

示例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");
}
 
开发者ID:mehah,项目名称:jRender,代码行数:10,代码来源:CoreFileJS.java

示例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;
}
 
开发者ID:yangjm,项目名称:winlet,代码行数:54,代码来源:CompressFilter.java


注:本文中的com.googlecode.htmlcompressor.compressor.HtmlCompressor.compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。