Package com.yahoo.platform.yui.compressor

Examples of com.yahoo.platform.yui.compressor.JavaScriptCompressor


                        (new String(content))
                            .replaceFirst("^/\\*", "/*!")
                            .getBytes(charset)),
                            charset);
        Writer out = new OutputStreamWriter(baos, charset);
        JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
            public void warning(String message, String sourceName,
                    int line, String lineSource, int lineOffset) {
                logger.error("message: " + message + (lineSource != null ? ", line: " + line + ", column: " + lineOffset + ", source: " + lineSource : ""));
            }
            public void error(String message, String sourceName,
                    int line, String lineSource, int lineOffset) {
                logger.error("message: " + message + (lineSource != null ? ", line: " + line + ", column: " + lineOffset + ", source: " + lineSource : ""));
            }
            public EvaluatorException runtimeError(String message, String sourceName,
                    int line, String lineSource, int lineOffset) {
                error(message, sourceName, line, lineSource, lineOffset);
                return new EvaluatorException(message);
            }
        });
        in.close();
        compressor.compress(out, -1, false, false, true, false);
        out.flush();
        content = baos.toByteArray();
        out.close();
    }
View Full Code Here


        Reader reader = toReader(resource);

        try
        {
            JavaScriptCompressor compressor = new JavaScriptCompressor(reader, errorReporter);
            compressor.compress(output, -1, true, false, false, false);
        } catch (EvaluatorException ex)
        {
            logInputLines(resource, errorLines);

            recoverFromException(ex, resource, output);
View Full Code Here

  private void doJSCompression(final Reader in, Writer out, final String outputFilename) throws EvaluatorException, IOException {
    traceVerbose("Start doJSCompression");

    try {
      // JS compressor
      final JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

             public void warning(final String message, final String sourceName,
                     final int line, final String lineSource, final int lineOffset) {
                 if (line < 0) {
                     trace(message);
                 } else {
                     trace(line + ':' + lineOffset + ':' + message);
                 }
             }

             public void error(final String message, final String sourceName,
                     final int line, final String lineSource, final int lineOffset) {
               warning(message, sourceName, line, lineSource, lineOffset);
             }

             public EvaluatorException runtimeError(final String message, final String sourceName,
                     final int line, final String lineSource, final int lineOffset) {
                 error(message, sourceName, line, lineSource, lineOffset);
                 return new EvaluatorException(message);
             }
      });

           // Close the input stream first, and then open the output stream,
           // in case the output file should override the input file
       closeObject(in);

           // Get Writer object for output file
           out = openDataWriter(new File(outputFilename), UTF8);

           // Compress file
           compressor.compress(out, -1, true, false,
                   true, false);
    } finally {
      closeObject(out);
      traceVerbose("End doJSCompression");
    }
View Full Code Here

  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();
View Full Code Here

    }
    return writer.toString();
  }

  private JavaScriptCompressor createJavaScriptCompressor(Reader in) throws IOException {
    return new JavaScriptCompressor(in, new ErrorReporter() {
      private String getMessage(String source, String message, int line, int lineOffset) {
        String logMessage;
        if (line < 0) {
          logMessage = (source != null) ? source + ":" : "" + message;
        } else {
View Full Code Here

            out = new OutputStreamWriter(buildContext.newFileOutputStream(outFileTmp), encoding);
            if (nocompress) {
                getLog().info("No compression is enabled");
                IOUtil.copy(in, out);
            } else if (".js".equalsIgnoreCase(src.getExtension())) {
                JavaScriptCompressor compressor = new JavaScriptCompressor(in, jsErrorReporter_);
                compressor.compress(out, linebreakpos, !nomunge, jswarn, preserveAllSemiColons, disableOptimizations);
            } else if (".css".equalsIgnoreCase(src.getExtension())) {
                compressCss(in, out);
            }
            getLog().debug("end compression");
        } finally {
View Full Code Here

  @Override
  protected void doProcess(Reader reader, Writer writer, ProcessingContext processingContext) throws Exception {

    try {
      JavaScriptCompressor compressor = new JavaScriptCompressor(reader, new YuiCompressorErrorReporter());
      compressor.compress(writer, -1, true, false, true, true);
    }
    catch (EvaluatorException e) {
      LOG.error("YUI compressor can't evaluate the content of {}", processingContext.getAsset().toLog());
      throw DandelionException.wrap(e);
    }
View Full Code Here

TOP

Related Classes of com.yahoo.platform.yui.compressor.JavaScriptCompressor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.