本文整理汇总了Java中com.yahoo.platform.yui.compressor.JavaScriptCompressor类的典型用法代码示例。如果您正苦于以下问题:Java JavaScriptCompressor类的具体用法?Java JavaScriptCompressor怎么用?Java JavaScriptCompressor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaScriptCompressor类属于com.yahoo.platform.yui.compressor包,在下文中一共展示了JavaScriptCompressor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: YahooJSCompressor
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
/**
* Constructor: YahooJSCompressor using the property map passed in.
*
* @param specifiedCompressorParameters
*/
public YahooJSCompressor(Map<String, Object> specifiedCompressorParameters) throws InstantiationException
{
try
{
new JavaScriptCompressor(new StringReader(""), new YahooJSErrorReporter());
}
catch (NoClassDefFoundError ncdf)
{
throw new InstantiationException("com.yahoo.platform.yui.compressor.JavaScriptCompressor is not available, assuming Yahoo Compressor is not here from yuicompressor.jar ");
}
catch (Exception e)
{
// We don't care about this! The instansiation above is just to ensure that the Yahoo compressor is
// on the classpath. If the actual test compression fails we don't need to do anything.
}
setCompressorParameters(specifiedCompressorParameters);
}
示例2: compressJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
public void compressJavaScript(Path input, Path output) throws IOException {
// yui compressor chokes on empty files
long size = Files.size(input);
if (size == 0) {
if (!Files.exists(output)) {
Files.createFile(output);
}
return;
}
Options o = new Options();
try (Reader in = Files.newBufferedReader(input, Charset.forName(o.charset));
Writer out = Files.newBufferedWriter(output, Charset.forName(o.charset))) {
JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
}
}
示例3: minifyJS
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
/**
* Minifies JavaScript by utilising YUI {@link JavaScriptCompressor}.
*
* @param bytes - an array of bytes to minify
* @param linebreak - split long line after a specific column
* @param munge - obfuscate, not only minify
* @param verbose - display informational messages and warnings
* @param preserveAllSemiColons - preserve all semicolons
* @param disableOptimisations - disable micro optimisations
* @return minified content as array of bytes
* @throws IOException
*/
static final byte[] minifyJS(final byte[] bytes, int linebreak, boolean munge, boolean verbose,
boolean preserveAllSemiColons, boolean disableOptimisations) throws IOException {
Reader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
StringWriter writer = new StringWriter();
try {
new JavaScriptCompressor(reader, null).compress(writer, linebreak, munge, verbose,
preserveAllSemiColons, disableOptimisations);
} catch (IndexOutOfBoundsException e) {
// handle YUI bug when file is empty or contains comments only
return new byte[] {};
} finally {
if (reader != null) {
reader.close();
}
if (writer != null) {
writer.close();
}
}
return writer.toString().getBytes("UTF-8");
}
示例4: compressJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
public void compressJavaScript(final File inputFile, final File outputFile, final YuiCompressorOptions o) throws IOException {
Reader in = null;
Writer out = null;
try {
in = new InputStreamReader(new FileInputStream(inputFile), o.charset);
final JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
in.close();
in = null;
out = new OutputStreamWriter(new FileOutputStream(outputFile, true), o.charset);
compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
示例5: cleanupJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
/**
* Javascript compression method, based on yuiCompressor
* @param content uncompressed JavaScript
* @return A compressed JavaScript
*/
public static String cleanupJavaScript(String content) {
int length = content.length();
int firstlinefeed = content.indexOf("\n");
if (firstlinefeed==-1 || (length>255 && firstlinefeed>255)){
//script seems to be already minified=> skip
return content;
}
Reader reader = new StringReader(content);
Writer writer = new StringWriter();
try {
JavaScriptCompressor jsc = new JavaScriptCompressor(reader,jsReporter);
jsc.compress(writer, -1, true, false, false, false);
//options: (int linebreak, boolean munge, boolean verbose, boolean preserveAllSemiColons, boolean disableOptimizations)
} catch (Exception e) {
return content;
}
return writer.toString();
}
示例6: YuiJsMinifier
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
public YuiJsMinifier(MinifyBuilder builder, IFile srcFile, IFile destFile,
OutputStream out, IEclipsePreferences prefs)
throws IOException, CoreException {
super (builder);
preserveSemicolons = prefs.getBoolean(
PrefsAccess.preferenceKey(srcFile, MinifyBuilder.YUI_PRESERVE_SEMICOLONS), true);
disableOptimizations = prefs.getBoolean(
PrefsAccess.preferenceKey(srcFile, MinifyBuilder.YUI_DISABLE_OPTIMIZATIONS), true);
outCharset = destFile.exists() ? destFile.getCharset() : srcFile.getCharset();
writer = new OutputStreamWriter(out, outCharset);
compressor = new JavaScriptCompressor(new BufferedReader(
new InputStreamReader(srcFile.getContents(), srcFile.getCharset())),
new YuiMinifier.MinifyErrorHandler(srcFile));
}
示例7: compressJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
@Override
public String compressJavaScript(String script) throws Exception {
StringReader stringReader = new StringReader(script);
JavaScriptCompressor javaScriptCompressor = new JavaScriptCompressor(stringReader, new YUIErrorReporter());
StringWriter stringWriter = new StringWriter();
javaScriptCompressor.compress(stringWriter, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
String compressedScript = stringWriter.toString();
return compressedScript;
}
示例8: compressJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
public String compressJavaScript(String script) throws IOException
{
StringReader stringReader = new StringReader(script);
JavaScriptCompressor yuiJavaScriptCompressor = new JavaScriptCompressor(stringReader, new YahooJSErrorReporter());
StringWriter stringWriter = new StringWriter();
yuiJavaScriptCompressor.compress(stringWriter, (Integer) compressorParameters.get(PARAMETER_LINEBREAK), (Boolean) compressorParameters.get(PARAMETER_MUNGE),
(Boolean) compressorParameters.get(PARAMETER_VERBOSE), (Boolean) compressorParameters.get(PARAMETER_PRESERVE_ALL_SEMICOLONS),
(Boolean) compressorParameters.get(PARAMETER_DISABLE_OPTIMIZATIONS));
String compressedScript = stringWriter.toString();
return compressedScript;
}
示例9: compressJavaScript
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
public static void compressJavaScript(String inputFilename, String outputFilename, Options o) throws IOException {
Reader in = null;
Writer out = null;
try {
in = new InputStreamReader(new FileInputStream(inputFilename), o.charset);
JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
in.close();
in = null;
out = new OutputStreamWriter(new FileOutputStream(outputFilename), o.charset);
compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
示例10: compressJs
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
private String compressJs(String content) {
StringWriter writer = new StringWriter(1024);
StringReader reader = new StringReader(content);
try {
JavaScriptCompressor jsCompressor = createJavaScriptCompressor(reader);
jsCompressor.compress(writer, _compressorOptions.getLineBreakPosition(), _compressorOptions.isMunge(), _compressorOptions.isWarn(),
_compressorOptions.isPreserveAllSemiColons(), !_compressorOptions.isOptimize());
} catch (IOException ex) {
s_logger.error("Unexpected IOException", ex);
}
return writer.toString();
}
示例11: compress
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
@Override
public String compress(String source) {
StringWriter result = new StringWriter();
try {
JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), errorReporter);
compressor.compress(result, lineBreak, !noMunge, false, preserveAllSemiColons, disableOptimizations);
} catch (IOException e) {
result.write(source);
e.printStackTrace();
}
return result.toString();
}
示例12: minifyJs
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
private String minifyJs(final String jsSourceCode) throws EvaluatorException,
IOException {
JavaScriptCompressor jsc = new JavaScriptCompressor(
new StringReader(jsSourceCode), this.errorReporter);
StringWriter sw = new StringWriter();
jsc.compress(sw, this.jsLinebreakPos, this.jsCompressorMunge,
this.jsCompressorVerbose, this.jsCompressorPreserveAllSemiColons,
this.jsCompressordisableOptimizations);
return sw.toString();
}
示例13: minify
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
protected void minify(BufferedReader in, BufferedWriter out, String filename, String type) throws IOException {
if (JS_TYPE.equals(type)) {
JavaScriptCompressor jsc = new JavaScriptCompressor(in, getLogBasedErrorReporter());
jsc.compress(out, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
} else if (CSS_TYPE.equals(type)) {
CssCompressor cssc = new CssCompressor(in);
cssc.compress(out, 100);
}
}
示例14: processAdminJS
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
private void processAdminJS(final File srcDir) throws Exception {
if (adminJSs.isEmpty()) {
return;
}
final File adminDir = new File(srcDir + File.separator + "admin");
final List<File> adminJSList = new ArrayList<File>();
for (final String adminJS : adminJSs) {
final File adminJSFile = new File(adminDir.getPath() + File.separator + adminJS);
adminJSList.add(adminJSFile);
}
final File latkeAdminJS = merge(adminJSList);
final File latkeMinAdminJS =
new File(getTargetDir() + File.separator + "admin" + File.separator + "latkeAdmin" + getSuffix() + ".js");
getLogger().info("Minimizing [srcPath=" + latkeAdminJS.getPath() + ", targetPath=" + latkeMinAdminJS.getPath() + "]");
final Reader reader = new InputStreamReader(
new FileInputStream(latkeAdminJS), "UTF-8");
final FileOutputStream writerStream = new FileOutputStream(latkeMinAdminJS);
final Writer writer = new OutputStreamWriter(writerStream, "UTF-8");
final JavaScriptCompressor compressor = new JavaScriptCompressor(
reader, new JavaScriptErrorReporter(getLogger(), latkeAdminJS.getName()));
compressor.compress(writer, -1, munge, verbose, preserveAllSemiColons, disableOptimizations);
reader.close();
writer.close();
}
示例15: process
import com.yahoo.platform.yui.compressor.JavaScriptCompressor; //导入依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
throws Exception {
ErrorReporter reporter = reporter(log, filename, name());
JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), reporter);
StringWriter out = new StringWriter();
compressor.compress(out, get("linebreakpos"), get("munge"), get("verbose"),
get("preserve-semi"), get("disable-optimizations"));
return out.toString();
}