View Javadoc

1   package org.codehaus.mojo.javascript.compress;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  import java.io.FileInputStream;
21  import java.io.FileOutputStream;
22  
23  import org.inconspicuous.jsmin.JSMin;
24  
25  /**
26   * Use the Java version of the JSMin algorithm to compress a set of JS files.
27   * For simplicity, the JSMin code (one class) is included in the plugin.
28   * 
29   * @see http://www.crockford.com/javascript/jsmin.html
30   * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
31   */
32  public class JSMinCompressor
33      implements JSCompressor
34  {
35  
36      /**
37       * {@inheritDoc}
38       * 
39       * @see org.codehaus.mojo.javascript.compress.JSCompressor#compress(java.io.File,
40       * java.io.File, int, int)
41       */
42      public void compress( File input, File output, int level, int language )
43          throws CompressionException
44      {
45          try
46          {
47              new JSMin( new FileInputStream( input ), new FileOutputStream( output ) ).jsmin();
48          }
49          catch ( Exception e )
50          {
51              throw new CompressionException( "Failed to create compressed file", e, input );
52          }
53      }
54  
55      /**
56       * Set a the JSCompressorLogger implementation that will receive logs
57       *
58       * @param logger a logger
59       */
60      public void setLogger(JSCompressorLogger logger) throws CompressionException
61      {
62          // Unused
63      }
64  
65      /**
66       * Return current JSCompressorLogger used for logging
67       *
68       * @return the current JSCompressorLogger used for logging
69       */
70      public JSCompressorLogger getLogger() throws CompressionException
71      {
72          return null;  // Unused
73      }
74  }