Package com.yahoo.platform.yui.compressor

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


        srcChannel.close();
        dstChannel.close();
    }

    private JavaScriptCompressor createJavaScriptCompressor(final Reader in) throws IOException {
        final JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

            public void error(final String message, final String sourceName, final int line, final String lineSource,
                    final int lineOffset) {
                log(getMessage(sourceName, message, line, lineOffset), Project.MSG_ERR);
            }
View Full Code Here


    return out.toString();
  }
  public static String compressJS(Reader in) throws IOException{
    StringWriter out = new StringWriter();
    try {
      JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
        public void warning(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          log.warn("[JAVASCRIPT COMPRESSOR WARN] in file : "+sourceName+"\n"+message+"\n"+line+":"+lineOffset);
        }

        public void error(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          log.warn("[JAVASCRIPT COMPRESSOR ERROR] in file : "+sourceName+"\nLine : "+lineSource+"\n"+message+"\n"+line+":"+lineOffset);
        }

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

      compressor.compress(out, LINE_BREAK_POS, true, true,
          true, true);

    } catch (EvaluatorException e) {
      e.printStackTrace();
    }
View Full Code Here

   * @param out the writer where the data must be written
   * @throws IOException
   */
  public static void compressJS(Reader in, Writer out) throws IOException{
    try {
      JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
        public void warning(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          LOG.warn("[JAVASCRIPT COMPRESSOR WARN] in file : "+sourceName+"\n"+message+"\n"+line+":"+lineOffset);
        }

        public void error(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          LOG.error("[JAVASCRIPT COMPRESSOR ERROR] in file : "+sourceName+"\nLine : "+lineSource+"\n"+message+"\n"+line+":"+lineOffset);
        }

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

      compressor.compress(out, LINE_BREAK_POS, true, true,
          true, true);

    } catch (EvaluatorException e) {
      LOG.error("YUICompressorAdaptor.compressJS Failed!", e);
    }
View Full Code Here

        if (Utils.isBlank(original))
            return original;

        try {
            StringWriter result = new StringWriter();
            JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(original), yuiErrorReporter);
            compressor.compress(result, -1, true, false, false, false);
            result.flush();
            return result.toString();
        } catch (IOException e) {
            log.error("Error compressing javascript with yui-compressor! Returning original javascript", e);
        }
View Full Code Here

    }

    protected void doMinimize(Reader input, Writer output) throws IOException
    {
        JavaScriptCompressor compressor = new JavaScriptCompressor(input, errorReporter);

        compressor.compress(output, -1, true, false, false, false);
    }
View Full Code Here

     */
    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 ");
        }
View Full Code Here

     * @see org.directwebremoting.extend.Compressor#compressJavaScript(java.lang.String)
     */
    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;
    }
View Full Code Here

                    break;
                case YUI:
                    log.debug("Using YUI Compressor engine.");

                    JavaScriptCompressor compressor = new JavaScriptCompressor(reader, new JavaScriptErrorReporter(log,
                            mergedFile.getName()));
                    compressor.compress(writer, yuiConfig.getLineBreak(), yuiConfig.isMunge(), verbose,
                            yuiConfig.isPreserveSemicolons(), yuiConfig.isDisableOptimizations());
                    break;
                default:
                    log.warn("JavaScript engine not supported.");
                    break;
View Full Code Here

              }

              out = new OutputStreamWriter(new FileOutputStream(
                  copyToFile), "UTF-8");
              errorReport.setDefaultFileName(srcFile.getName());
              JavaScriptCompressor compressor = new JavaScriptCompressor(
                  in, errorReport);
              compressor.compress(out, -1, true, false, false,
                  false);
              // zk modified here
            } catch (EvaluatorException e) {
              error = true;
            } finally {
              if (in != null) {
                in.close();
              }
              if (out != null) {
                out.close();
              }
            }
           
            if (error) {
              FileUtils.forceDelete(copyToFile);
              System.exit(-1);
            }
          } else {
            InputStreamReader in = null;
            OutputStreamWriter out = null;
            try {
              // bug fix for UTF8 BOM issue by TonyQ
              in = new UnicodeReader(
                  new FileInputStream(srcFile), "UTF-8");

              out = new OutputStreamWriter(new FileOutputStream(
                  copyToFile), "UTF-8");

              CssCompressor compressor = new CssCompressor(in);
              compressor.compress(out, -1);

              // zk modified here
            } finally {
              if (in != null) {
                in.close();
View Full Code Here

    try {
      Timer timer = new Timer();     
      // logger.debug( "Starting minification for '" + inputFilename + "'...");
      Reader in = new StringReader( input );
      JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {
        public void warning(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          if (line < 0) {
            logger.warn("Minifier Warning: " + message);
          } else {
            logger.warn("Minifier Warning, " + line + ':' + lineOffset + ':' + message);
          }
        }

        public void error(String message, String sourceName,
            int line, String lineSource, int lineOffset) {
          if (line < 0) {
            logger.warn("Minifier Error: " + message);
          } else {
            logger.warn("Minifier Error, " + line + ':' + lineOffset + ':' + message);
          }
        }

        public EvaluatorException runtimeError(String message, String sourceName,
            int line, String lineSource, 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.
      in.close();

      try {
        Writer out = new StringWriter();
        boolean munge = true;
        boolean preserveAllSemiColons = false;
        boolean disableOptimizations = false;
        boolean verbose = false;
        int linebreakpos = 0;

        compressor.compress(out, linebreakpos, munge, verbose,
            preserveAllSemiColons, disableOptimizations);
        out.close();
        String result = out.toString();
        if( logger.isDebugEnabled() ) {
          timer.stop();
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.