Package com.yahoo.platform.yui.compressor

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


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

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(baos, "utf-8");
            out = new BufferedWriter(osw);

            if ("js".equals(type)) {
                JavaScriptCompressor jsc = new JavaScriptCompressor(in, getLogBasedErrorReporter());
                jsc.compress(out, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
            } else if ("css".equals(type)) {
                CssCompressor cssc = new CssCompressor(in);
                cssc.compress(out, 100);
            }
            out.flush();
View Full Code Here

                String out = null;
                String in = fileHelper.readFileToString(f);             // must use our reader
               
                // process compressible files               
                if (".js".equals(ext)) {
          JavaScriptCompressor compressor = new JavaScriptCompressor(in, reporter); in=null;  
          out = compressor.compress(linebreakpos, munge, ycVerbose,
              preserveAllSemiColons, disableOptimizations);         
                 
        } else if (".css".equals(ext) && yuiCompressCss) {              
          CssCompressor compressor = new CssCompressor(in); in=null// under the covers YUI just appends to a new SB
          out = compressor.compress(linebreakpos);          // their final product is just a string, just get that directly
        }
                if (out != null)
          fileHelper.writeFile(out.getBytes("UTF-8"), new File(outPath), false)// ensure final form not barf in browser by forcing utf8            

            } catch (EvaluatorException e) {   
View Full Code Here

            if("js".equals(extension)) {

                CustomErrorReporter errorReporter = new CustomErrorReporter();

                JavaScriptCompressor compressor = new JavaScriptCompressor(in, errorReporter);
                compressor.compress(out, 10, true, false, false, false);

                if(errorReporter.hasError()) {
                    throw new RuntimeException(errorReporter.getErrorMessage());
                }

            } else if("css".equals(extension)) {

                CssCompressor compressor = new CssCompressor(in);
                compressor.compress(out, 10);
            }
        } catch (Exception e) {
            //如果失败了,直接做个副本,防止加载js/css出错
            try {
                FileUtils.copyFile(new File(fileName), new File(minFileName));
View Full Code Here

public final class JsCompressor {

  public void compress(StringReader jssr, final StringWriter writer,
      final ErrorCollector errorCollector) throws IOException {

    JavaScriptCompressor jsc = new JavaScriptCompressor(jssr, errorCollector);
    int linebreakpos = -1;
    boolean munge = true;
    boolean verbose = false;
    boolean preserveAllSemis = false;
    boolean disableOptimizations = false;
    jsc.compress(writer, linebreakpos, munge, verbose, preserveAllSemis,
        disableOptimizations);
  }
View Full Code Here

    minimizeCSS("table");
    minimizeCSS("menu");
  }
 
  public static void minimizeJS(String name) {
    JavaScriptCompressor compressor;

    try {
      compressor = new JavaScriptCompressor(new InputStreamReader(
          DefaultStyle.class.getResourceAsStream(name+".js")), null);
      FileOutputStream outstream = new FileOutputStream("C://temp/"+name+".min.js");
      OutputStreamWriter writer = new OutputStreamWriter(outstream,
          "UTF-8");
      compressor.compress(writer, -1, false, false, true, false);
      writer.flush();
      writer.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

        // do compression
        Reader in = new BufferedReader(new InputStreamReader(inputStream));
        if (this.key.endsWith(".js?minify") || this.key.endsWith(".json?minify")) {
            try {

                JavaScriptCompressor compressor = new JavaScriptCompressor(in, null);

                // boolean options: munge, verbose, preserveAllSemiColons, disableOptimizations
                compressor.compress(outWriter, MINIFY_LINEBREAKPOS, true, false, false, false);

            } catch (EvaluatorException e) {
                // fail gracefully on malformed javascript: send it without compressing
                normalOutput(inputStream);
                return;
            }
        } else if (this.key.endsWith(".css?minify")) {
            CssCompressor compressor = new CssCompressor(in);
            compressor.compress(outWriter, MINIFY_LINEBREAKPOS);
        } else {
            // or not if not right type
            normalOutput(inputStream);
            return;
        }
View Full Code Here

            StringWriter sw = new StringWriter();
            for (String file : _envFiles) {
                sw.append("/* ").append(file).append(" */\n");
                InputStream input = new FileInputStream(new File(getServletContext().getRealPath(file)));
                try {
                    JavaScriptCompressor compressor = new JavaScriptCompressor(
                            new InputStreamReader(input), null);
                    compressor.compress(sw, -1, false, false, false, false);
                } catch (EvaluatorException e) {
                    _logger.error(e.getMessage(), e);
                } catch (IOException e) {
                    _logger.error(e.getMessage(), e);
                } finally {
View Full Code Here

        StringWriter sw = new StringWriter();
        for (IDiagramPlugin plugin : plugins) {
            sw.append("/* ").append(plugin.getName()).append(" */\n");
            InputStream input = plugin.getContents();
            try {
                JavaScriptCompressor compressor = new JavaScriptCompressor(
                        new InputStreamReader(input), null);
                compressor.compress(sw, -1, false, false, false, false);
            } catch (EvaluatorException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            } finally {
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.