use of com.yahoo.platform.yui.compressor.CssCompressor in project BroadleafCommerce by BroadleafCommerce.
the class ResourceMinificationServiceImpl method minify.
protected void minify(BufferedReader in, BufferedWriter out, String filename, String type) throws IOException {
if (JS_TYPE.equals(type)) {
JavaScriptCompressor jsc = new JavaScriptCompressor(in, getLogBasedErrorReporter(filename));
jsc.compress(out, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
} else if (CSS_TYPE.equals(type)) {
CssCompressor cssc = new CssCompressor(in);
cssc.compress(out, 100);
}
}
use of com.yahoo.platform.yui.compressor.CssCompressor in project scout.rt by eclipse.
the class MinifyCssWithYui method run.
public String run(String content) throws IOException {
try (StringReader reader = new StringReader(content);
StringWriter writer = new StringWriter()) {
CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, -1);
writer.flush();
return writer.toString();
}
}
use of com.yahoo.platform.yui.compressor.CssCompressor 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);
}
}
use of com.yahoo.platform.yui.compressor.CssCompressor in project xwiki-platform by xwiki.
the class CssExtension method getCompressor.
@Override
public SxCompressor getCompressor() {
return new SxCompressor() {
@Override
public String compress(String source) {
try {
CssCompressor compressor = new CssCompressor(new StringReader(source));
StringWriter out = new StringWriter();
compressor.compress(out, -1);
return out.toString();
} catch (IOException ex) {
LOGGER.warn("Exception compressing SSX code", ex);
}
return source;
}
};
}
use of com.yahoo.platform.yui.compressor.CssCompressor in project wombat by PLOS.
the class AssetServiceImpl method compileAsset.
/**
* Minifies the given asset file and returns the file and its contents.
*
* @param uncompiled uncompiled asset file
* @return File that has been minified. The file name will contain a hash reflecting the file's contents.
* @throws IOException
*/
private CompiledAsset compileAsset(AssetType assetType, File uncompiled) throws IOException {
// Compile to memory instead of a file directly, since we will need the raw bytes
// in order to generate a hash (which appears in the filename).
ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
try (InputStreamReader isr = new InputStreamReader(new FileInputStream(uncompiled));
OutputStreamWriter osw = new OutputStreamWriter(baos)) {
if (assetType == AssetType.CSS) {
CssCompressor compressor = new CssCompressor(isr);
compressor.compress(osw, -1);
} else if (assetType == AssetType.JS) {
JavaScriptCompressor compressor = new JavaScriptCompressor(isr, new JsErrorReporter());
compressor.compress(osw, -1, true, false, true, false);
} else {
throw new IllegalArgumentException("Unexpected asset type " + assetType);
}
}
byte[] contents = baos.toByteArray();
String contentHash = CacheKey.createContentHash(contents);
CompiledDigest digest = new CompiledDigest(AssetUrls.COMPILED_NAME_PREFIX + contentHash + assetType.getExtension());
File file = digest.getFile();
// Overwrite if the file already exists.
if (file.exists()) {
file.delete();
}
try (OutputStream os = new FileOutputStream(file)) {
IOUtils.write(contents, os);
}
return new CompiledAsset(digest, contents);
}
Aggregations