Author: trong.tran
Date: 2010-08-25 23:35:58 -0400 (Wed, 25 Aug 2010)
New Revision: 3938
Added:
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/MockCompressorPlugin.java
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/TestResourceCompressorService.java
portal/branches/branched-r3845/component/web/resources/src/test/resources/
portal/branches/branched-r3845/component/web/resources/src/test/resources/conf/
portal/branches/branched-r3845/component/web/resources/src/test/resources/conf/resource-compressor-service-configuration.xml
portal/branches/branched-r3845/component/web/resources/src/test/resources/javascript.js
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml
Removed:
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
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/compressor-configuration.xml
Modified:
portal/branches/branched-r3845/component/web/resources/pom.xml
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.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/portal/resource/compressor/impl/ResourceCompressorService.java
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JSMin.java
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/configuration.xml
Log:
GTNPORTAL-1420 Improve and add junit test for the resource compressor service and JSMin
Compressor plugin
Modified: portal/branches/branched-r3845/component/web/resources/pom.xml
===================================================================
--- portal/branches/branched-r3845/component/web/resources/pom.xml 2010-08-26 01:21:16 UTC
(rev 3937)
+++ portal/branches/branched-r3845/component/web/resources/pom.xml 2010-08-26 03:35:58 UTC
(rev 3938)
@@ -48,6 +48,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.test.core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -18,11 +18,9 @@
*/
package org.exoplatform.portal.resource.compressor;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-
import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
@@ -31,23 +29,23 @@
public abstract class BaseResourceCompressorPlugin extends BaseComponentPlugin implements
ResourceCompressorPlugin
{
+ private int priority;
- abstract public ResourceType getResourceType();
-
- @Override
- public int getPriority()
+ public BaseResourceCompressorPlugin(InitParams params)
{
- return 0;
+ ValueParam priorityParam = params.getValueParam("plugin.priority");
+ try
+ {
+ this.priority = Integer.parseInt(priorityParam.getValue());
+ }
+ catch (NumberFormatException NBFEx)
+ {
+ this.priority = -1;
+ }
}
- @Override
- public void compress(Reader input, Writer output) throws ResourceCompressorException,
IOException
+ public int getPriority()
{
+ return priority;
}
-
- @Override
- public String getName()
- {
- return this.getClass().getCanonicalName().toString();
- }
}
Deleted:
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 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/InputReaderBridge.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -1,45 +0,0 @@
-/*
- * 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@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-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/JSMinCompressorPlugin.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -18,19 +18,16 @@
*/
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;
-
import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.ValueParam;
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;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* Aug 19, 2010
@@ -39,73 +36,29 @@
public class JSMinCompressorPlugin extends BaseResourceCompressorPlugin
{
- private int priority;
-
public JSMinCompressorPlugin(InitParams params) throws Exception
{
- ValueParam priorityParam = params.getValueParam("plugin.priority");
- try
- {
- this.priority = Integer.parseInt(priorityParam.getValue());
- }
- catch (NumberFormatException NBFEx)
- {
- this.priority = -1;
- }
+ super(params);
}
-
- @Override
- public String getName()
- {
- return "JSMinCompressorPlugin";
- }
-
- public int getPriority()
- {
- return priority;
- }
-
- @Override
+
public ResourceType getResourceType()
{
return ResourceType.JAVASCRIPT;
}
-
- @Override
+
public void compress(Reader input, Writer output) throws ResourceCompressorException,
IOException
{
- if (input instanceof InputReaderBridge && output instanceof
OutputWriterBridge)
+ try
{
- try
- {
- compress((InputReaderBridge) input, (OutputWriterBridge) output);
- }
- catch (IOException IOEx)
- {
- throw IOEx;
- }
- catch (Exception ex)
- {
- throw new ResourceCompressorException(ex.getMessage());
- }
+ new JSMin(input, output).jsmin();
}
- super.compress(input, output);
- }
-
- private void compress(InputReaderBridge reader, OutputWriterBridge writer) throws
IOException
- {
- InputStream inputStream = reader.getInputStream();
- OutputStream outputStream = writer.getOutputStream();
- try
+ catch (IOException IOEx)
{
- new JSMin(inputStream, outputStream).jsmin();
+ throw IOEx;
}
catch (Exception ex)
{
- if (ex instanceof IOException)
- {
- throw (IOException) ex;
- }
+ throw new ResourceCompressorException(ex.getMessage());
}
}
}
Deleted:
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 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/OutputWriterBridge.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -1,44 +0,0 @@
-/*
- * 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@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/portal/resource/compressor/impl/ResourceCompressorService.java
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -47,47 +47,52 @@
private Map<ResourceType, List<ResourceCompressorPlugin>> plugins;
- private Map<ResourceType, String> defaultType_Key_Mapping;
-
public ResourceCompressorService(InitParams params) throws Exception
{
plugins = new HashMap<ResourceType, List<ResourceCompressorPlugin>>();
}
- public void loadCompressorPlugin(ComponentPlugin plugin)
+ public void registerCompressorPlugin(ComponentPlugin plugin)
{
- if(plugin != null && plugin instanceof ResourceCompressorPlugin)
+ if (plugin instanceof ResourceCompressorPlugin)
{
- registerCompressorPlugin((ResourceCompressorPlugin)plugin);
+ ResourceCompressorPlugin compressorPlugin = (ResourceCompressorPlugin)plugin;
+ ResourceType type = compressorPlugin.getResourceType();
+ List<ResourceCompressorPlugin> sameResourceTypePlugins =
plugins.get(type);
+
+ if (sameResourceTypePlugins != null)
+ {
+ sameResourceTypePlugins.add(compressorPlugin);
+ log.debug("Loaded compressor plugin: " + compressorPlugin.getName()
+ " for resource type " + type.toString());
+ }
+ else
+ {
+ List<ResourceCompressorPlugin> newListOfPlugins = new
ArrayList<ResourceCompressorPlugin>();
+ newListOfPlugins.add(compressorPlugin);
+ log.debug("Loaded compressor plugin: " + compressorPlugin.getName()
+ " for new resource type " + type.toString());
+ plugins.put(type, newListOfPlugins);
+ }
}
}
- private void registerCompressorPlugin(ResourceCompressorPlugin plugin)
+ public ResourceCompressorPlugin getCompressorPlugin(ResourceType type, String name)
{
- ResourceType type = plugin.getResourceType();
List<ResourceCompressorPlugin> sameResourceTypePlugins = plugins.get(type);
-
- if(sameResourceTypePlugins != null)
+
+ if (sameResourceTypePlugins != null)
{
- sameResourceTypePlugins.add(plugin);
- log.debug("Loaded compressor plugin: " + plugin.getName() + " for
resource type " + type.toString());
+ for (ResourceCompressorPlugin plugin : sameResourceTypePlugins)
+ {
+ if (plugin.getName().equals(name))
+ {
+ return plugin;
+ }
+ }
}
- else{
- List<ResourceCompressorPlugin> newListOfPlugins = new
ArrayList<ResourceCompressorPlugin>();
- newListOfPlugins.add(plugin);
- log.debug("Loaded compressor plugin: " + plugin.getName() + " for
new resource type " + type.toString());
- plugins.put(type, newListOfPlugins);
- }
+ return null;
}
- public void unloadCompressorPlugin(ComponentPlugin plugin)
- {
-
- }
-
-
- @Override
final public void compress(Reader input, Writer output, ResourceType resourceType)
throws ResourceCompressorException,
IOException
{
@@ -96,15 +101,9 @@
{
plugin.compress(input, output);
}
-
- //ResourceCompressorPlugin defaultPlugin =
getDefaultCompressorPlugin(resourceType);
- //if(defaultPlugin != null)
- //{
- // defaultPlugin.compress(input, output);
- //}
}
- private ResourceCompressorPlugin getHighestPriorityCompressorPlugin(ResourceType
resourceType)
+ public ResourceCompressorPlugin getHighestPriorityCompressorPlugin(ResourceType
resourceType)
{
List<ResourceCompressorPlugin> candidates = plugins.get(resourceType);
if(candidates == null || candidates.size() == 0)
@@ -128,37 +127,4 @@
return candidates.get(highestPriorityIndex);
}
-
- private ResourceCompressorPlugin getDefaultCompressorPlugin(ResourceType
resourceType)
- {
- String key = this.defaultType_Key_Mapping.get(resourceType);
- return getDefaultCompressorPlugin(resourceType, key);
- }
-
- private ResourceCompressorPlugin getDefaultCompressorPlugin(ResourceType resourceType,
String key)
- {
- List<ResourceCompressorPlugin> candidates = plugins.get(resourceType);
- if(candidates == null)
- {
- return null;
- }
-
- for(ResourceCompressorPlugin plugin : candidates)
- {
- if(plugin.getName().equals(key))
- {
- return plugin;
- }
- }
-
- if (candidates.size() > 0)
- {
- return candidates.get(0);
- }
- else
- {
- return null;
- }
- }
-
}
Modified:
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JSMin.java
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JSMin.java 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JSMin.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -19,28 +19,29 @@
package org.exoplatform.web.application.javascript;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PushbackInputStream;
+import java.io.PrintWriter;
+import java.io.PushbackReader;
+import java.io.Reader;
+import java.io.Writer;
public class JSMin
{
private static final int EOF = -1;
- private PushbackInputStream in;
+ private PushbackReader in;
- private OutputStream out;
+ private Writer out;
private int theA;
private int theB;
- public JSMin(InputStream in, OutputStream out)
+ public JSMin(Reader in, Writer out)
{
- this.in = new PushbackInputStream(in);
+ this.in = new PushbackReader(in);
this.out = out;
}
@@ -133,9 +134,10 @@
}
/**
- * action -- do something! What you do is determined by the argument: 1 Output
- * A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B. (Delete A).
- * 3 Get the next B. (Delete B). action treats a string as a single character.
+ * action -- do something! What you do is determined by the argument: <br/>
+ * 1. Output A. Copy B to A. Get the next B. <br/>
+ * 2. Copy B to A. Get the next B. (Delete A). <br/>
+ * 3. Get the next B. (Delete B). action treats a string as a single character.
<br/>
* Wow! action recognizes a regular expression if it is preceded by ( or , or =.
*/
@@ -310,7 +312,7 @@
{
try
{
- JSMin jsmin = new JSMin(new FileInputStream(arg[0]), System.out);
+ JSMin jsmin = new JSMin(new FileReader(arg[0]), new PrintWriter(System.out));
jsmin.jsmin();
}
catch (FileNotFoundException e)
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-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -22,16 +22,27 @@
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;
import org.picocontainer.Startable;
-import java.io.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.servlet.ServletContext;
@@ -115,7 +126,6 @@
* @param jsKeys
* new list of JavaScript will replace current available JavaScript
*/
- @SuppressWarnings("unchecked")
public synchronized void addJavascripts(List<Javascript> jsKeys)
{
availableScriptsKey_.addAll(jsKeys);
@@ -286,16 +296,13 @@
// Minify
try
{
- ByteArrayInputStream input = new ByteArrayInputStream(bytes);
- ByteArrayOutputStream jsStream = new ByteArrayOutputStream();
-
ResourceCompressorService compressorService = (ResourceCompressorService)
ExoContainerContext
.getCurrentContainer().getComponentInstanceOfType(ResourceCompressorService.class);
- Reader readerBridge = new InputReaderBridge(input);
- Writer outputBridge = new OutputWriterBridge(jsStream);
- compressorService.compress(readerBridge, outputBridge,
ResourceType.JAVASCRIPT);
+ Reader input = new StringReader(s);
+ StringWriter output = new StringWriter();
+ compressorService.compress(input, output, ResourceType.JAVASCRIPT);
- jsBytes = jsStream.toByteArray();
+ jsBytes = output.toString().getBytes();
}
catch (Exception e)
{
Added:
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/MockCompressorPlugin.java
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/MockCompressorPlugin.java
(rev 0)
+++
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/MockCompressorPlugin.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.portal.resource.compressor.BaseResourceCompressorPlugin;
+import org.exoplatform.portal.resource.compressor.ResourceCompressorException;
+import org.exoplatform.portal.resource.compressor.ResourceType;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * A mock compressor plugin that just copy all characters from input to output
+ *
+ * @author <a href="trong.tran(a)exoplatform.com">Trong Tran</a>
+ * @version $Revision$
+ */
+
+public class MockCompressorPlugin extends BaseResourceCompressorPlugin
+{
+ public MockCompressorPlugin(InitParams params)
+ {
+ super(params);
+ }
+
+ public ResourceType getResourceType()
+ {
+ return ResourceType.JAVASCRIPT;
+ }
+
+ public void compress(Reader input, Writer output) throws ResourceCompressorException,
IOException
+ {
+ int c = input.read();
+ while (c != -1)
+ {
+ output.write(c);
+ c = input.read();
+ }
+ }
+}
Added:
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/TestResourceCompressorService.java
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/TestResourceCompressorService.java
(rev 0)
+++
portal/branches/branched-r3845/component/web/resources/src/test/java/org/exoplatform/portal/resource/compressor/TestResourceCompressorService.java 2010-08-26
03:35:58 UTC (rev 3938)
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import org.exoplatform.component.test.AbstractKernelTest;
+import org.exoplatform.component.test.ConfigurationUnit;
+import org.exoplatform.component.test.ConfiguredBy;
+import org.exoplatform.component.test.ContainerScope;
+import org.exoplatform.portal.resource.compressor.impl.JSMinCompressorPlugin;
+import org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * @author <a href="trong.tran(a)exoplatform.com">Trong Tran</a>
+ * @version $Revision$
+ */
+
+@ConfiguredBy({
+ @ConfigurationUnit(scope = ContainerScope.PORTAL, path =
"conf/resource-compressor-service-configuration.xml")
+})
+public class TestResourceCompressorService extends AbstractKernelTest
+{
+ public void testInitializing()
+ {
+ ResourceCompressorService compressor =
(ResourceCompressorService)getContainer().getComponentInstanceOfType(ResourceCompressor.class);
+ assertNotNull(compressor);
+ assertTrue(compressor instanceof ResourceCompressorService);
+
+ assertNotNull(compressor.getCompressorPlugin(ResourceType.JAVASCRIPT,
"MockCompressorPlugin"));
+
+ assertNotNull(compressor.getCompressorPlugin(ResourceType.JAVASCRIPT,
"JSMinCompressorPlugin"));
+ }
+
+ public void testPriority()
+ {
+ ResourceCompressorService compressor =
(ResourceCompressorService)getContainer().getComponentInstanceOfType(ResourceCompressor.class);
+ ResourceCompressorPlugin plugin =
compressor.getHighestPriorityCompressorPlugin(ResourceType.JAVASCRIPT);
+ assertTrue(plugin instanceof JSMinCompressorPlugin);
+ }
+
+ public void testJSMinCompressing() throws ResourceCompressorException, IOException
+ {
+ File jsFile = new File("src/test/resources/javascript.js");
+ File jsCompressedFile = new File("target/jsmin-compressed-file.js");
+
+ Reader reader = new FileReader(jsFile);
+ Writer writer = new FileWriter(jsCompressedFile);
+
+ ResourceCompressorService compressor =
(ResourceCompressorService)getContainer().getComponentInstanceOfType(ResourceCompressor.class);
+ compressor.compress(reader, writer, ResourceType.JAVASCRIPT);
+ writer.close();
+ assertTrue(jsCompressedFile.length() > 0);
+ assertTrue(jsFile.length() > jsCompressedFile.length());
+ log.info("The javascript is compressed by JSMIN into " +
jsCompressedFile.getAbsolutePath());
+ }
+}
Added:
portal/branches/branched-r3845/component/web/resources/src/test/resources/conf/resource-compressor-service-configuration.xml
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/test/resources/conf/resource-compressor-service-configuration.xml
(rev 0)
+++
portal/branches/branched-r3845/component/web/resources/src/test/resources/conf/resource-compressor-service-configuration.xml 2010-08-26
03:35:58 UTC (rev 3938)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+
<key>org.exoplatform.portal.resource.compressor.ResourceCompressor</key>
+
<type>org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService</type>
+ <component-plugins>
+ <component-plugin>
+ <name>MockCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.MockCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>5</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ <component-plugin>
+ <name>JSMinCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.impl.JSMinCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>9</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ </component-plugins>
+ </component>
+</configuration>
Added:
portal/branches/branched-r3845/component/web/resources/src/test/resources/javascript.js
===================================================================
---
portal/branches/branched-r3845/component/web/resources/src/test/resources/javascript.js
(rev 0)
+++
portal/branches/branched-r3845/component/web/resources/src/test/resources/javascript.js 2010-08-26
03:35:58 UTC (rev 3938)
@@ -0,0 +1,154 @@
+/**
+ * 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.
+ */
+/**
+ * This class contains common js object that used in whole portal
+ */
+var eXo = {
+ animation : { },
+
+ browser : { },
+
+ desktop : { },
+
+ core : { },
+
+ env : { portal: {}, client: {}, server: {} },
+
+ portal : { },
+
+ util : { },
+
+ webui : { },
+
+ gadget : { },
+
+ application : {
+ browser : { }
+ },
+
+ ecm : { },
+
+ calendar : { },
+
+ contact : { },
+
+ forum : { },
+
+ mail : { },
+
+ faq : { },
+
+ session : { },
+
+ i18n : { }
+} ;
+
+/**
+* This method will :
+* 1) dynamically load a javascript module from the server (if no root location is set
+* then use '/eXoResources/javascript/', aka files
+* located in the eXoResources WAR in the application server).
+* The method used underneath is a XMLHttpRequest
+* 2) Evaluate the returned script
+* 3) Cache the script on the client
+*
+*/
+eXo.require = function(module, jsLocation) {
+ try {
+ if(eval(module + ' != null')) return ;
+ } catch(err) {
+ //alert(err + " : " + module);
+ }
+ window.status = "Loading Javascript Module " + module ;
+ if(jsLocation == null) jsLocation = '/eXoResources/javascript/' ;
+ var path = jsLocation + module.replace(/\./g, '/') + '.js' ;
+ eXo.loadJS(path);
+} ;
+
+eXo.loadJS = function(path) {
+ var request = eXo.core.Browser.createHttpRequest() ;
+ request.open('GET', path, false) ;
+ request.setRequestHeader("Cache-Control", "max-age=86400") ;
+
+ request.send(null) ;
+ eXo.session.itvDestroy() ;
+ if(eXo.session.canKeepState && eXo.session.isOpen &&
eXo.env.portal.accessMode == 'private') {
+ eXo.session.itvInit() ;
+ }
+ try {
+ eval(request.responseText) ;
+ } catch(err) {
+ alert(err + " : " + request.responseText) ;
+ }
+} ;
+/**
+ * Make url portal request with parameters
+ *
+ * @param targetComponentId identifier of component
+ * @param actionName name of action
+ * @param useAjax indicate Ajax request or none
+ * @param params array contains others parameters
+ * @return full url request
+ */
+eXo.env.server.createPortalURL = function(targetComponentId, actionName, useAjax, params)
{
+ var href = eXo.env.server.portalBaseURL + "?portal:componentId=" +
targetComponentId + "&portal:action=" + actionName ;
+
+ if(params != null) {
+ var len = params.length ;
+ for(var i = 0 ; i < len ; i++) {
+ href += "&" + params[i].name + "=" + params[i].value ;
+ }
+ }
+ if(useAjax) href += "&ajaxRequest=true" ;
+ return href ;
+} ;
+/**
+ * log out of user session
+ */
+eXo.portal.logout = function() {
+ window.location = eXo.env.server.createPortalURL("UIPortal",
"Logout", false) ;
+} ;
+
+eXo.session.openUrl = null ;
+eXo.session.itvTime = null ;
+eXo.session.itvObj = null;
+
+eXo.session.itvInit = function() {
+ if(!eXo.session.openUrl) eXo.session.openUrl =
eXo.env.server.createPortalURL("UIPortal", "Ping", false) ;
+ if(!eXo.session.itvTime) eXo.session.itvTime = 1800;
+ if(eXo.session.itvTime > 0) eXo.session.itvObj =
window.setTimeout("eXo.session.itvOpen()", (eXo.session.itvTime - 10)*1000) ;
+} ;
+
+eXo.session.itvOpen = function() {
+ var result = ajaxAsyncGetRequest(eXo.session.openUrl, false) ;
+ if(!isNaN(result)) eXo.session.itvTime = parseInt(result) ;
+} ;
+
+eXo.session.itvDestroy = function() {
+ window.clearTimeout(eXo.session.itvObj) ;
+ eXo.session.itvObj = null ;
+} ;
+
+eXo.debug = function(message) {
+ if(!eXo.developing) return;
+ if(eXo.webui.UINotification) {
+ message = "DEBUG: " + message;
+ eXo.webui.UINotification.addMessage(message);
+ }
+}
\ No newline at end of file
Deleted:
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/compressor-configuration.xml
===================================================================
---
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/compressor-configuration.xml 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/compressor-configuration.xml 2010-08-26
03:35:58 UTC (rev 3938)
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-
- 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.
-
--->
-
-<configuration
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
-
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
-
-
- <component>
- <key>org.exoplatform.portal.resource.compressor.ResourceCompressor</key>
-
<type>org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService</type>
- <component-plugins>
- <component-plugin>
- <name>JSMinCompressorPlugin</name>
- <set-method>loadCompressorPlugin</set-method>
-
<type>org.exoplatform.portal.resource.compressor.impl.JSMinCompressorPlugin</type>
- <description>Javascript Compressor Plugin leveraging
JSMin</description>
- <init-params>
- <value-param>
- <name>plugin.priority</name>
- <value>1</value>
- </value-param>
- </init-params>
- </component-plugin>
- </component-plugins>
- <init-params>
- <value-param>
- <name>JAVASCRIPT</name>
- <value>JSMinCompressorPlugin</value>
- </value-param>
- <value-param>
- <name>STYLESHEET</name>
- <value>CSSMinCompressorPlugin</value>
- </value-param>
- </init-params>
-
- </component>
-
-
-</configuration>
Copied:
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml
(from rev 3923,
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/compressor-configuration.xml)
===================================================================
---
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml
(rev 0)
+++
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml 2010-08-26
03:35:58 UTC (rev 3938)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+
<key>org.exoplatform.portal.resource.compressor.ResourceCompressor</key>
+
<type>org.exoplatform.portal.resource.compressor.impl.ResourceCompressorService</type>
+ <component-plugins>
+ <component-plugin>
+ <name>JSMinCompressorPlugin</name>
+ <set-method>registerCompressorPlugin</set-method>
+
<type>org.exoplatform.portal.resource.compressor.impl.JSMinCompressorPlugin</type>
+ <init-params>
+ <value-param>
+ <name>plugin.priority</name>
+ <value>1</value>
+ </value-param>
+ </init-params>
+ </component-plugin>
+ </component-plugins>
+ </component>
+
+</configuration>
Modified:
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/configuration.xml
===================================================================
---
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/configuration.xml 2010-08-26
01:21:16 UTC (rev 3937)
+++
portal/branches/branched-r3845/web/portal/src/main/webapp/WEB-INF/conf/configuration.xml 2010-08-26
03:35:58 UTC (rev 3938)
@@ -25,7 +25,7 @@
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
<import>war:/conf/common/common-configuration.xml</import>
- <import>war:/conf/common/compressor-configuration.xml</import>
+ <import>war:/conf/common/resource-compressor-configuration.xml</import>
<import>war:/conf/common/portlet-container-configuration.xml</import>
<import
profiles="jboss">war:/conf/wsrp/wsrp-configuration.xml</import>
<import>war:/conf/common/logs-configuration.xml</import>