com.yahoo.platform.yui.compressor.JavaScriptCompressor.compress()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 JavaScript  
字(11.2k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中com.yahoo.platform.yui.compressor.JavaScriptCompressor.compress()方法的一些代码示例,展示了JavaScriptCompressor.compress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaScriptCompressor.compress()方法的具体详情如下:
包路径:com.yahoo.platform.yui.compressor.JavaScriptCompressor
类名称:JavaScriptCompressor
方法名:compress

JavaScriptCompressor.compress介绍

暂无

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public void minifyJs(String filename, Reader reader, Writer writer) throws ResourceMinificationException {
  try {
    JavaScriptCompressor jsc = new JavaScriptCompressor(reader, getLogBasedErrorReporter(filename));
    jsc.compress(writer, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
  } catch (IOException e) {
    throw new ResourceMinificationException("Error minifying js file " + filename, e);
  }
}

代码示例来源:origin: jooby-project/jooby

@Override
public String process(final String filename, final String source, final Config conf,
  final ClassLoader loader) 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();
}

代码示例来源:origin: stackoverflow.com

JavaScriptCompressor compressor = 
  new JavaScriptCompressor(in, new SystemOutErrorReporter());
 compressor.compress(out, 1 << 20, false, false, false, false);

代码示例来源:origin: eclipse/rap

private String compress() throws IOException {
 StringWriter writer = new StringWriter();
 compressor.compress( writer, -1, true, VERBOSE, PRESERVE_ALL_SEMICOLONS, DISABLE_OPTIMIZATIONS );
 writer.flush();
 return writer.getBuffer().toString();
}

代码示例来源:origin: org.jasig/resource-aggregator-core

@Override
public void compress(Reader reader, Writer writer) throws EvaluatorException, IOException {
  final JavaScriptCompressor jsCompressor = new JavaScriptCompressor(reader, JAVA_SCRIPT_ERROR_REPORTER);
  jsCompressor.compress(writer, jsLineBreakColumnNumber, obfuscateJs, displayJsWarnings, preserveAllSemiColons, disableJsOptimizations);
}

代码示例来源:origin: com.github.hazendaz/htmlcompressor

@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);
    logger.error("", e);
  }
  return result.toString();
}

代码示例来源:origin: com.googlecode.htmlcompressor/htmlcompressor

@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();
  
}

代码示例来源:origin: org.jasig.resource-aggregator/resource-aggregator-core

@Override
public void compress(Reader reader, Writer writer) throws EvaluatorException, IOException {
  final JavaScriptCompressor jsCompressor = new JavaScriptCompressor(reader, JAVA_SCRIPT_ERROR_REPORTER);
  jsCompressor.compress(writer, jsLineBreakColumnNumber, obfuscateJs, displayJsWarnings, preserveAllSemiColons, disableJsOptimizations);
}

代码示例来源:origin: riotfamily/riot

/**
 * Reads JavaScript from the the given Reader and writes the compressed
 * code to the specified Writer. Errors are reported to the given 
 * ErrorReorter.
 */
protected void compressInternal(Reader in, Writer out, 
    ErrorReporter errorReporter) 
    throws EvaluatorException, IOException {
  
  JavaScriptCompressor compressor = new JavaScriptCompressor(in, errorReporter);
  compressor.compress(out, linebreak, munge, warn, 
      preserveAllSemiColons, !mergeStringLiterals);
}

代码示例来源:origin: org.directwebremoting/dwr

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;
}

代码示例来源:origin: eclipse/rap

public static String compress( String input ) throws IOException {
 Reader inputReader = new StringReader( input );
 TestErrorReporter errorReporter = new TestErrorReporter();
 JavaScriptCompressor compressor = new JavaScriptCompressor( inputReader, errorReporter );
 StringWriter outputWriter = new StringWriter();
 compressor.compress( outputWriter, -1, true, false, false, false );
 return outputWriter.toString();
}

代码示例来源:origin: fluxtream/fluxtream-app

public static void main(String[] args) {
  try {
    String js = FileUtils.readFileToString(new File("src/main/webapp/js/jquery1.6.1.min.js"));
    js += FileUtils.readFileToString(new File("src/main/webapp/js/raphael.js"));
    js += FileUtils.readFileToString(new File("src/main/webapp/js/plugins.js"));
    js += FileUtils.readFileToString(new File("src/main/webapp/js/datepicker.js"));
    js += FileUtils.readFileToString(new File("src/main/webapp/js/fluxtream.js"));
    JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(js), new YuiCompressorErrorReporter());
    FileWriter fw = new FileWriter("src/main/webapp/js/flx-min.js");
    compressor.compress(fw, 0, false, false, false, false);
    fw.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}
static class YuiCompressorErrorReporter implements ErrorReporter {

代码示例来源:origin: com.atlassian.maven.plugins/amps-maven-plugin

private void yuiJsCompile(File sourceFile, File destFile, Log log, Charset cs) throws MojoExecutionException
{
  try
  {
    FileUtils.forceMkdir(destFile.getParentFile());
    try (InputStreamReader in = new InputStreamReader(new FileInputStream(sourceFile), cs);
       OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(destFile), cs))
    {
      JavaScriptCompressor yui = new JavaScriptCompressor(in, new YUIErrorReporter(log));
      yui.compress(out, -1, true, false, false, false);
    }
  }
  catch (IOException e)
  {
    throw new MojoExecutionException("IOException when compiling JS", e);
  }
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-skin-skinx

@Override
public String compress(String source)
{
  try {
    ErrorReporter reporter = new CustomErrorReporter();
    JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), reporter);
    StringWriter out = new StringWriter();
    compressor.compress(out, -1, true, false, false, false);
    return out.toString();
  } catch (IOException ex) {
    LOGGER.info("Failed to write the compressed output: " + ex.getMessage());
  } catch (EvaluatorException ex) {
    LOGGER.info("Failed to parse the JS extension: " + ex.getMessage());
  } catch (Exception ex) {
    LOGGER.warn("Failed to compress JS extension: " + ex.getMessage());
  }
  return source;
}

代码示例来源:origin: org.odlabs.wiquery/wiquery-compressor

compressor.compress(compressedJs, -1, true, false, false, false);
compressedJs.flush();

代码示例来源:origin: devefx/validator-web

@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;
}

代码示例来源:origin: com.atlassian.maven.plugins/maven-amps-plugin

private void yuiJsCompile(File sourceFile, File destFile, Log log, Charset cs) throws MojoExecutionException
{
  InputStreamReader in = null;
  OutputStreamWriter out = null;
  try
  {
    FileUtils.forceMkdir(destFile.getParentFile());
    in = new InputStreamReader(new FileInputStream(sourceFile), cs);
    out = new OutputStreamWriter(new FileOutputStream(destFile), cs);
    
    JavaScriptCompressor yui = new JavaScriptCompressor(in,new YUIErrorReporter(log));
    yui.compress(out,-1,true,false,false,false);
  }
  catch (IOException e)
  {
    throw new MojoExecutionException("IOException when compiling JS", e);
  }
  finally {
    IOUtils.closeQuietly(in);
    IOUtils.closeQuietly(out);
  }
}

代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.ui.html.scriptprocessor

public String run(String content, boolean munge) throws IOException {
 try (
   StringReader reader = new StringReader(content);
   StringWriter writer = new StringWriter()) {
  // Yui uses a modified version of rhino files (org.mozilla.javascript). If you get any class incompatibility errors this may be the reason.
  ErrorReporter errorReporter = new ErrorReporter() {
   @Override
   public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
    System.out.println(MinifyJsWithYui.class.getSimpleName() + " [warning] " + message + " sourceName:" + sourceName + " line:" + line + "|" + lineOffset);
   }
   @Override
   public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) {
    System.out.println(MinifyJsWithYui.class.getSimpleName() + " [runtime-error] " + message + " sourceName:" + sourceName + " line:" + line + "|" + lineOffset);
    throw new EvaluatorException(message, sourceName, line, lineSource, lineOffset);
   }
   @Override
   public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
    System.out.println(MinifyJsWithYui.class.getSimpleName() + " [error] " + message + " sourceName:" + sourceName + " line:" + line + "|" + lineOffset);
   }
  };
  JavaScriptCompressor compressor = new JavaScriptCompressor(reader, errorReporter);
  boolean verbose = false;
  boolean preserveAllSemicolons = false;
  boolean disableOptimizations = false;
  compressor.compress(writer, -1, munge, verbose, preserveAllSemicolons, disableOptimizations);
  writer.flush();
  return writer.toString();
 }
}

代码示例来源:origin: org.alfresco.surf/spring-surf

@Override
public void compress(Reader reader, Writer writer) throws IOException
{
  JavaScriptCompressor jsc = new JavaScriptCompressor(reader, new YuiCompressorErrorReporter());
  reader.close();
  jsc.compress(writer, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
}

代码示例来源:origin: de.svenkubiak/mangooio-core

private static void minifyJS(File inputFile) {
  InputStreamReader inputStreamReader = null;
  OutputStreamWriter outputStreamWriter = null;
  try {
    File outputFile = getOutputFile(inputFile, JS);
    inputStreamReader = new InputStreamReader(new FileInputStream(inputFile), Charsets.UTF_8);
    outputStreamWriter = new OutputStreamWriter(new FileOutputStream(outputFile), Charsets.UTF_8);
    JavaScriptCompressor compressor = new JavaScriptCompressor(inputStreamReader, new MinificationErrorReporter());
    compressor.compress(outputStreamWriter, LINEBREAK, MUNGE, VERBOSE, PRESERVESEMICOLONS, DISABLEOPTIMIZATION);
    outputStreamWriter.flush();
    logMinification(inputFile, outputFile);
    if (config.getBoolean(Key.APPLICATION_GZIP_JS.toString(), false)) {
      createGzipFile(outputFile);
    }
  } catch (IOException e) {
    LOG.error("Failed to minify JS", e);
  } finally {
    try {
      if (inputStreamReader != null) {
        inputStreamReader.close();
      }
      if (outputStreamWriter != null) {
        outputStreamWriter.close();
      }
    } catch (IOException e) {
      LOG.error("Failed to close reader/writer while minifing JS", e);
    }
  }
}

相关文章

微信公众号