一、前言
关于htmlcompressor源码包中com.googlecode.htmlcompressor.compressor.YuiCssCompressor、com.googlecode.htmlcompressor.compressor.Compressor定义css样式文本压缩接口及实现类,可以对空格、回车、换行及注释等进行过滤压缩处理。
二、源码说明
1.Compressor接口
package com.googlecode.htmlcompressor.compressor;@b@@b@public abstract interface Compressor@b@{@b@ public abstract String compress(String paramString);@b@}
2.YuiCssCompressor实现类
package com.googlecode.htmlcompressor.compressor;@b@@b@import com.yahoo.platform.yui.compressor.CssCompressor;@b@import java.io.IOException;@b@import java.io.StringReader;@b@import java.io.StringWriter;@b@@b@public class YuiCssCompressor@b@ implements Compressor@b@{@b@ private int lineBreak = -1;@b@@b@ public String compress(String source)@b@ {@b@ StringWriter result = new StringWriter();@b@ try@b@ {@b@ CssCompressor compressor = new CssCompressor(new StringReader(source));@b@ compressor.compress(result, this.lineBreak);@b@ } catch (IOException e) {@b@ result.write(source);@b@ e.printStackTrace();@b@ }@b@@b@ return result.toString();@b@ }@b@@b@ public int getLineBreak()@b@ {@b@ return this.lineBreak;@b@ }@b@@b@ public void setLineBreak(int lineBreak)@b@ {@b@ this.lineBreak = lineBreak;@b@ }@b@}