use of com.googlecode.htmlcompressor.compressor.XmlCompressor in project yui-compressor-ant-task by n0ha.
the class YuiCompressorTask method compressFile.
private void compressFile(final File inFile, final File outFile, final String fileType) throws EvaluatorException, BuildException {
// always recompress when outFile and inFile are exactly the same file
if (outFile.isFile() && !inFile.getAbsolutePath().equals(outFile.getAbsolutePath())) {
if (outFile.lastModified() >= inFile.lastModified()) {
return;
}
}
try {
// prepare input file
Reader in = openFile(inFile);
// prepare output file
outFile.getParentFile().mkdirs();
Writer out = new OutputStreamWriter(new FileOutputStream(outFile), charset);
if (fileType.equals(FileType.JS_FILE)) {
final JavaScriptCompressor compressor = createJavaScriptCompressor(in);
compressor.compress(out, lineBreakPosition, munge, warn, preserveAllSemiColons, !optimize);
} else if (fileType.equals(FileType.CSS_FILE)) {
final CssCompressor compressor = new CssCompressor(in);
compressor.compress(out, lineBreakPosition);
} else if (fileType.equals(FileType.HTML_FILE) || fileType.equals(FileType.XHTML_FILE)) {
final HtmlCompressor compressor = new HtmlCompressor();
out.write(compressor.compress(readerToString(in)));
} else if (fileType.equals(FileType.XML_FILE)) {
final XmlCompressor compressor = new XmlCompressor();
out.write(compressor.compress(readerToString(in)));
}
// close all streams
in.close();
in = null;
out.close();
out = null;
if (verbose) {
log(stats.getFileStats(inFile, outFile, fileType));
}
} catch (final IOException ioe) {
throw new BuildException("I/O Error when compressing file", ioe);
}
}
Aggregations