[gatein-commits] gatein SVN: r3897 - in portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform: portal/resource/compressor/impl and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 23 22:51:29 EDT 2010


Author: hoang_to
Date: 2010-08-23 22:51:28 -0400 (Mon, 23 Aug 2010)
New Revision: 3897

Added:
   portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/InputReaderBridge.java
   portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/OutputWriterBridge.java
Modified:
   portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/ResourceCompressorException.java
   portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/JSMinCompressorPlugin.java
   portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
Log:
GTNPORTAL-1423: Convert JSMin module into a plugin of compressor service

Modified: portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/ResourceCompressorException.java
===================================================================
--- portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/ResourceCompressorException.java	2010-08-24 02:44:43 UTC (rev 3896)
+++ portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/ResourceCompressorException.java	2010-08-24 02:51:28 UTC (rev 3897)
@@ -26,4 +26,8 @@
 public class ResourceCompressorException extends RuntimeException
 {
 
+   public ResourceCompressorException(String message)
+   {
+      super(message);
+   }
 }

Added: portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/InputReaderBridge.java
===================================================================
--- portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/InputReaderBridge.java	                        (rev 0)
+++ portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/InputReaderBridge.java	2010-08-24 02:51:28 UTC (rev 3897)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.resource.compressor.impl;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
+ * Aug 24, 2010
+ */
+
+public class InputReaderBridge extends InputStreamReader
+{
+
+   private InputStream input;
+   
+   public InputReaderBridge(InputStream _input)
+   {
+      super(_input);
+      this.input = _input;
+   }
+   
+   public InputStream getInputStream()
+   {
+      return input;
+   }
+   
+}

Modified: portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/JSMinCompressorPlugin.java
===================================================================
--- portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/JSMinCompressorPlugin.java	2010-08-24 02:44:43 UTC (rev 3896)
+++ portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/JSMinCompressorPlugin.java	2010-08-24 02:51:28 UTC (rev 3897)
@@ -19,6 +19,8 @@
 package org.exoplatform.portal.resource.compressor.impl;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Writer;
 
@@ -27,6 +29,7 @@
 import org.exoplatform.portal.resource.compressor.BaseResourceCompressorPlugin;
 import org.exoplatform.portal.resource.compressor.ResourceCompressorException;
 import org.exoplatform.portal.resource.compressor.ResourceType;
+import org.exoplatform.web.application.javascript.JSMin;
 
 /**
  * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
@@ -71,6 +74,38 @@
    @Override
    public void compress(Reader input, Writer output) throws ResourceCompressorException, IOException
    {
+      if (input instanceof InputReaderBridge && output instanceof OutputWriterBridge)
+      {
+         try
+         {
+            compress((InputReaderBridge) input, (OutputWriterBridge) output);
+         }
+         catch (IOException IOEx)
+         {
+            throw IOEx;
+         }
+         catch (Exception ex)
+         {
+            throw new ResourceCompressorException(ex.getMessage());
+         }
+      }
       super.compress(input, output);
    }
+   
+   private void compress(InputReaderBridge reader, OutputWriterBridge writer) throws IOException
+   {
+      InputStream inputStream = reader.getInputStream();
+      OutputStream outputStream = writer.getOutputStream();
+      try
+      {
+         new JSMin(inputStream, outputStream).jsmin();
+      }
+      catch (Exception ex)
+      {
+         if (ex instanceof IOException)
+         {
+            throw (IOException) ex;
+         }
+      }
+   }
 }

Added: portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/OutputWriterBridge.java
===================================================================
--- portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/OutputWriterBridge.java	                        (rev 0)
+++ portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/OutputWriterBridge.java	2010-08-24 02:51:28 UTC (rev 3897)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.portal.resource.compressor.impl;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+/**
+ * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
+ * Aug 24, 2010
+ */
+
+public class OutputWriterBridge extends OutputStreamWriter
+{
+   private OutputStream output;
+   
+   public OutputWriterBridge(OutputStream _output)
+   {
+      super(_output);
+      this.output = _output;
+   }
+
+   public OutputStream getOutputStream()
+   {
+      return this.output;
+   }
+   
+}

Modified: portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
===================================================================
--- portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java	2010-08-24 02:44:43 UTC (rev 3896)
+++ portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java	2010-08-24 02:51:28 UTC (rev 3897)
@@ -21,6 +21,10 @@
 
 import org.exoplatform.commons.utils.Safe;
 import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.portal.resource.compressor.ResourceType;
+import org.exoplatform.portal.resource.compressor.impl.InputReaderBridge;
+import org.exoplatform.portal.resource.compressor.impl.OutputWriterBridge;
+import org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService;
 import org.gatein.common.logging.Logger;
 import org.gatein.common.logging.LoggerFactory;
 import org.gatein.wci.impl.DefaultServletContainerFactory;
@@ -284,8 +288,13 @@
          {
             ByteArrayInputStream input = new ByteArrayInputStream(bytes);
             ByteArrayOutputStream jsStream = new ByteArrayOutputStream();
-            JSMin jsMin = new JSMin(input, jsStream);
-            jsMin.jsmin();
+            
+            ResourceCompressorService compressorService = (ResourceCompressorService) ExoContainerContext
+                  .getCurrentContainer().getComponentInstanceOfType(ResourceCompressorService.class);
+            Reader readerBridge = new InputReaderBridge(input);
+            Writer outputBridge = new OutputWriterBridge(jsStream);
+            compressorService.compress(readerBridge, outputBridge, ResourceType.JAVASCRIPT);
+            
             jsBytes = jsStream.toByteArray();
          }
          catch (Exception e)



More information about the gatein-commits mailing list