Author: trong.tran
Date: 2011-11-11 05:56:18 -0500 (Fri, 11 Nov 2011)
New Revision: 8045
Added:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceService.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/CachedJavascript.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigDeployer.java
Removed:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
Modified:
portal/trunk/component/web/resources/src/main/java/gatein_resources_1_2.xsd
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/Javascript.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/AbstractSkinServiceTest.java
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceResolver.java
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestJavascriptConfigService.java
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestXSDCorruption.java
portal/trunk/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
GTNPORTAL-1213 Need to provide a way to add customer javascript for each site
Modified: portal/trunk/component/web/resources/src/main/java/gatein_resources_1_2.xsd
===================================================================
--- portal/trunk/component/web/resources/src/main/java/gatein_resources_1_2.xsd 2011-11-11
09:44:12 UTC (rev 8044)
+++ portal/trunk/component/web/resources/src/main/java/gatein_resources_1_2.xsd 2011-11-11
10:56:18 UTC (rev 8045)
@@ -102,6 +102,9 @@
<xs:complexType name="param">
<xs:sequence>
+ <!-- The portal name loading particular JavaScript module -->
+ <xs:element name="portal-name" type="xs:string"
minOccurs="0" maxOccurs="1"/>
+
<!-- The javascript module -->
<xs:element name="js-module" type="xs:string"
minOccurs="1" maxOccurs="1"/>
Deleted:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceHandler.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -1,38 +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;
-
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppListener;
-
-/**
- *
- * Created by eXoPlatform SAS
- *
- * Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 16, 2009
- */
-public abstract class AbstractResourceHandler implements WebAppListener
-{
-
- abstract public void onEvent(WebAppEvent event);
-
-}
\ No newline at end of file
Added:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceService.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceService.java
(rev 0)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/AbstractResourceService.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -0,0 +1,76 @@
+/**
+ * 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;
+
+import org.exoplatform.portal.resource.compressor.ResourceCompressor;
+import org.exoplatform.web.application.javascript.JavascriptConfigService;
+
+import javax.servlet.ServletContext;
+
+/**
+ * An abstract class for resource services in Portal like {@link SkinService}
+ * and {@link JavascriptConfigService}
+ *
+ * @author <a href="trongtt(a)gmail.com">Trong Tran</a>
+ * @version $Revision$
+ */
+public abstract class AbstractResourceService
+{
+ protected final MainResourceResolver mainResolver;
+
+ protected final ResourceCompressor compressor;
+
+ public AbstractResourceService(ResourceCompressor compressor)
+ {
+ this.compressor = compressor;
+ this.mainResolver = new MainResourceResolver();
+ }
+
+ /**
+ * Add a resource resolver to plug external resolvers.
+ *
+ * @param resolver
+ * a resolver to add
+ */
+ public void addResourceResolver(ResourceResolver resolver)
+ {
+ mainResolver.resolvers.addIfAbsent(resolver);
+ }
+
+ /**
+ * Registry ServletContext into MainResourceResolver of SkinService
+ * @param sContext
+ * ServletContext will be registried
+ */
+ public void registerContext(ServletContext sContext)
+ {
+ mainResolver.registerContext(sContext);
+ }
+
+ /**
+ * unregister a {@link ServletContext} into {@link MainResourceResolver} of {@link
SkinService}
+ *
+ * @param servletContext ServletContext will unregistered
+ */
+ public void unregisterServletContext(ServletContext servletContext)
+ {
+ mainResolver.removeServletContext(servletContext);
+ }
+}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -28,6 +28,7 @@
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.WebAppEvent;
import org.gatein.wci.WebAppLifeCycleEvent;
+import org.gatein.wci.WebAppListener;
import java.io.InputStream;
import java.net.URL;
@@ -42,7 +43,7 @@
*
* Sep 16, 2009
*/
-public class GateInSkinConfigDeployer extends AbstractResourceHandler
+public class GateInSkinConfigDeployer implements WebAppListener
{
/** . */
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigRemoval.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -25,13 +25,14 @@
import org.gatein.wci.WebAppEvent;
import org.gatein.wci.WebAppLifeCycleEvent;
+import org.gatein.wci.WebAppListener;
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
*
*/
-public class GateInSkinConfigRemoval extends AbstractResourceHandler
+public class GateInSkinConfigRemoval implements WebAppListener
{
private SkinService service;
@@ -41,9 +42,6 @@
this.service = _service;
}
- /**
- * @see
org.exoplatform.portal.resource.AbstractResourceHandler#onEvent(org.gatein.wci.WebAppEvent)
- */
@Override
public void onEvent(WebAppEvent event)
{
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -32,7 +32,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-class MainResourceResolver implements ResourceResolver
+public class MainResourceResolver implements ResourceResolver
{
/** . */
@@ -42,19 +42,12 @@
final CopyOnWriteArrayList<ResourceResolver> resolvers;
/** . */
- final Map<SkinKey, SkinConfig> skins;
-
- /** . */
private final Logger log = LoggerFactory.getLogger(MainResourceResolver.class);
- public MainResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig>
skins)
+ public MainResourceResolver()
{
- this.skins = skins;
this.contexts = new HashMap<String, SimpleResourceContext>();
this.resolvers = new CopyOnWriteArrayList<ResourceResolver>();
-
- //
- resolvers.add(new CompositeResourceResolver(portalContainerName, skins));
}
/**
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SimpleResourceContext.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -20,6 +20,7 @@
package org.exoplatform.portal.resource;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
@@ -49,25 +50,18 @@
int i2 = path.lastIndexOf("/") + 1;
String targetedParentPath = path.substring(0, i2);
String targetedFileName = path.substring(i2);
- try
- {
- final URL url = context.getResource(path);
- if (url != null)
+ final InputStream inputStream = context.getResourceAsStream(path);
+ if (inputStream != null)
{
return new Resource(contextPath, targetedParentPath, targetedFileName)
{
@Override
public Reader read() throws IOException
{
- return new InputStreamReader(url.openStream());
+ return new InputStreamReader(inputStream);
}
};
}
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
return null;
}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/SkinService.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -39,6 +39,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.resources.Orientation;
+import org.gatein.wci.WebAppListener;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.picocontainer.Startable;
@@ -66,7 +67,7 @@
@Property(key = "type", value = "skin")})
@ManagedDescription("Skin service")
@RESTEndpoint(path = "skinservice")
-public class SkinService implements Startable
+public class SkinService extends AbstractResourceService implements Startable
{
protected static Log log = ExoLogger.getLogger("portal.SkinService");
@@ -108,10 +109,10 @@
public static final String DEFAULT_SKIN = "Default";
/** The deployer. */
- private final AbstractResourceHandler deployer;
+ private final WebAppListener deployer;
/** The removal. */
- private final AbstractResourceHandler removal;
+ private final WebAppListener removal;
private final Map<SkinKey, SkinConfig> portalSkins_;
@@ -125,8 +126,6 @@
private final Map<String, Set<String>> portletThemes_;
- private final MainResourceResolver mainResolver;
-
/**
* The name of the portal container
*/
@@ -140,10 +139,9 @@
*/
final String id = Long.toString(System.currentTimeMillis());
- private ResourceCompressor compressor;
-
public SkinService(ExoContainerContext context, ResourceCompressor compressor)
{
+ super(compressor);
Loader<String, CachedStylesheet, Orientation> loader = new Loader<String,
CachedStylesheet, Orientation>()
{
public CachedStylesheet retrieve(Orientation context, String key) throws
Exception
@@ -174,7 +172,6 @@
};
//
- this.compressor = compressor;
portalSkins_ = new LinkedHashMap<SkinKey, SkinConfig>();
skinConfigs_ = new LinkedHashMap<SkinKey, SkinConfig>(20);
availableSkins_ = new HashSet<String>(5);
@@ -182,9 +179,10 @@
rtCache = new FutureMap<String, CachedStylesheet, Orientation>(loader);
portletThemes_ = new HashMap<String, Set<String>>();
portalContainerName = context.getPortalContainerName();
- mainResolver = new MainResourceResolver(portalContainerName, skinConfigs_);
deployer = new GateInSkinConfigDeployer(portalContainerName, this);
removal = new GateInSkinConfigRemoval(this);
+
+ addResourceResolver(new CompositeResourceResolver(portalContainerName,
skinConfigs_));
}
/**
@@ -425,17 +423,6 @@
}
/**
- * Add a resource resolver to plug external resolvers.
- *
- * @param resolver
- * a resolver to add
- */
- public void addResourceResolver(ResourceResolver resolver)
- {
- mainResolver.resolvers.addIfAbsent(resolver);
- }
-
- /**
* Registry theme category with its themes for portlet Theme
* @param categoryName
* category name that will be registried
@@ -999,26 +986,6 @@
}
/**
- * Registry ServletContext into MainResourceResolver of SkinService
- * @param sContext
- * ServletContext will be registried
- */
- public void registerContext(ServletContext sContext)
- {
- mainResolver.registerContext(sContext);
- }
-
- /**
- * unregister a {@link ServletContext} into {@link MainResourceResolver} of {@link
SkinService}
- *
- * @param servletContext ServletContext will unregistered
- */
- public void unregisterServletContext(ServletContext servletContext)
- {
- mainResolver.removeServletContext(servletContext);
- }
-
- /**
* Clean cache, reload all Skins
*/
@Managed
Added:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/CachedJavascript.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/CachedJavascript.java
(rev 0)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/CachedJavascript.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 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.web.application.javascript;
+
+import java.util.Date;
+
+/**
+ * @author <a href="trongtt(a)gmail.com">Trong Tran</a>
+ * @version $Revision$
+ */
+public class CachedJavascript
+{
+ /** . */
+ private final String text;
+
+ private long lastModified;
+
+ public CachedJavascript(String text)
+ {
+ this.text = text;
+
+ // Remove miliseconds because string of date retrieve from Http header doesn't
have miliseconds
+ lastModified = (new Date().getTime() / 1000) * 1000;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/Javascript.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/Javascript.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/Javascript.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -19,58 +19,97 @@
package org.exoplatform.web.application.javascript;
-import javax.servlet.ServletContext;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
public class Javascript
{
-
/** . */
- private final JavascriptKey key;
+ private final String module;
/** . */
- private final ServletContext context;
+ private final String contextPath;
/** . */
private final int priority;
- public Javascript(JavascriptKey key, ServletContext context, Integer priority)
+ private final String path;
+
+ public Javascript(String module, String path, String contextPath, int priority)
{
- this.key = key;
- this.context = context;
- this.priority = priority != null ? priority : -1;
+ this.module = module;
+ if (path.startsWith("http://") || path.startsWith("https://"))
+ {
+ this.path = path;
+ }
+ else
+ {
+ this.path = contextPath + path;
+ }
+ this.contextPath = contextPath;
+ this.priority = priority < 0 ? Integer.MAX_VALUE : priority;
}
public String getPath() {
- if(key.isExternalScript())
- {
- return key.getScriptPath();
- }
- return key.getContextPath() + key.getScriptPath();
+ return this.path;
}
- public JavascriptKey getKey()
+ public String getModule()
{
- return key;
+ return module;
}
- public ServletContext getContext()
+ public String getContextPath()
{
- return context;
+ return this.contextPath;
}
public int getPriority()
{
return priority;
}
+
+ public boolean isExternalScript()
+ {
+ return (path.startsWith("http://") ||
path.startsWith("https://")) ? true : false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Javascript[module=" + module + ", path=" + path
+"]";
+ }
+
+ public static class PortalJScript extends Javascript
+ {
+ private final String portalName;
- public BufferedReader getReader()
+ public PortalJScript(String module, String path, String contextPath, int priority,
String portalName)
+ {
+ super(module, path, contextPath, priority);
+ this.portalName = portalName;
+ }
+
+ public String getPortalName()
+ {
+ return portalName;
+ }
+ }
+
+ public static class ExtendedJScript extends Javascript
{
- return new BufferedReader(new
InputStreamReader(context.getResourceAsStream(key.getScriptPath())));
+ private final String script;
+
+ public ExtendedJScript(String module, String path, String contextPath, String
script)
+ {
+ super(module, path, contextPath, Integer.MAX_VALUE);
+ this.script = script;
+ }
+
+ public String getScript()
+ {
+ return this.script;
+ }
}
}
Added:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigDeployer.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigDeployer.java
(rev 0)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigDeployer.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2011 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.web.application.javascript;
+
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.gatein.wci.WebAppEvent;
+import org.gatein.wci.WebAppLifeCycleEvent;
+import org.gatein.wci.WebAppListener;
+
+import java.io.InputStream;
+
+import javax.servlet.ServletContext;
+
+/**
+ * An listener for listening the ADDED and REMOVED events of the webapp
+ * to deploy/undeploy Javascript configured in
<code>/WEB-INF/gatein-resources.xml</code> file.
+ *
+ * @author <a href="trongtt(a)gmail.com">Trong Tran</a>
+ * @version $Revision$
+ */
+public class JavascriptConfigDeployer implements WebAppListener
+{
+
+ private static final String GATEIN_CONFIG_RESOURCE =
"/WEB-INF/gatein-resources.xml";
+
+ /**
+ * Logger
+ */
+ private static final Log LOG = ExoLogger.getLogger(JavascriptConfigDeployer.class);
+
+ /** . */
+ private final JavascriptConfigService javascriptService;
+
+ /**
+ * The name of the portal container
+ */
+ private final String portalContainerName;
+
+ public JavascriptConfigDeployer(String portalContainerName, JavascriptConfigService
javascriptService)
+ {
+ this.javascriptService = javascriptService;
+ this.portalContainerName = portalContainerName;
+ }
+
+ public void onEvent(WebAppEvent event)
+ {
+ if (event instanceof WebAppLifeCycleEvent)
+ {
+ WebAppLifeCycleEvent lifeCycleEvent = (WebAppLifeCycleEvent)event;
+ ServletContext servletContext = lifeCycleEvent.getWebApp().getServletContext();
+ switch (lifeCycleEvent.getType())
+ {
+ case WebAppLifeCycleEvent.ADDED:
+ add(servletContext);
+ break;
+ case WebAppLifeCycleEvent.REMOVED:
+ remove(servletContext);
+ break;
+ }
+ }
+ }
+
+ private void add(ServletContext scontext)
+ {
+ try
+ {
+ InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ if (is == null)
+ {
+ return;
+ }
+
+ Safe.close(is);
+
+ final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
+ {
+
+ public void execute(ServletContext scontext, PortalContainer
portalContainer)
+ {
+ register(scontext, portalContainer);
+ javascriptService.registerContext(scontext);
+ }
+ };
+ PortalContainer.addInitTask(scontext, task, portalContainerName);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while registering 'Javascript in
gatein-resources.xml' from the context '"
+ + (scontext == null ? "unknown" : scontext.getServletContextName())
+ "'", ex);
+ }
+ }
+
+ private void remove(ServletContext scontext)
+ {
+ javascriptService.unregisterServletContext(scontext);
+ }
+
+ private void register(ServletContext scontext, PortalContainer container)
+ {
+ InputStream is = null;
+ try
+ {
+ is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ JavascriptConfigParser.processConfigResource(is, javascriptService, scontext);
+ }
+ catch (Exception ex)
+ {
+ LOG.error("An error occurs while processing 'Javascript in
gatein-resources.xml' from the context '"
+ + scontext.getServletContextName() + "'", ex);
+ }
+ finally
+ {
+ Safe.close(is);
+ }
+ }
+}
\ No newline at end of file
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -47,6 +47,8 @@
final public static String JAVA_SCRIPT_PATH = "js-path";
final public static String JAVA_SCRIPT_PRIORITY = "js-priority";
+
+ final public static String JAVA_SCRIPT_PORTAL_NAME = "portal-name";
/** . */
private ServletContext context;
@@ -118,19 +120,37 @@
param_ele.getElementsByTagName(JAVA_SCRIPT_MODULE).item(0).getFirstChild().getNodeValue();
String js_path =
param_ele.getElementsByTagName(JAVA_SCRIPT_PATH).item(0).getFirstChild().getNodeValue();
- Integer js_priority = null;
+ int priority;
try
{
- js_priority =
+ priority =
Integer.valueOf(param_ele.getElementsByTagName(JAVA_SCRIPT_PRIORITY).item(0)
- .getFirstChild().getNodeValue());
+ .getFirstChild().getNodeValue()).intValue();
}
catch (Exception e)
{
- //Js_priority still is null;
+ priority = Integer.MAX_VALUE;
}
- JavascriptKey key = new JavascriptKey(js_module, js_path,
context.getContextPath());
- Javascript js = new Javascript(key, context, js_priority);
+ String portalName = null;
+ try
+ {
+ portalName =
param_ele.getElementsByTagName(JAVA_SCRIPT_PORTAL_NAME).item(0)
+ .getFirstChild().getNodeValue();
+ }
+ catch (Exception e)
+ {
+ // portal-name is null
+ }
+
+ Javascript js;
+ if (portalName == null)
+ {
+ js = new Javascript(js_module, js_path, context.getContextPath(),
priority);
+ }
+ else
+ {
+ js = new Javascript.PortalJScript(js_module, js_path,
context.getContextPath(), priority, portalName);
+ }
task.addScript(js);
}
return task;
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -19,256 +19,298 @@
package org.exoplatform.web.application.javascript;
+import org.exoplatform.commons.cache.future.FutureMap;
+import org.exoplatform.commons.cache.future.Loader;
import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.portal.resource.AbstractResourceService;
+import org.exoplatform.portal.resource.MainResourceResolver;
+import org.exoplatform.portal.resource.Resource;
+import org.exoplatform.portal.resource.ResourceResolver;
+import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.resource.compressor.ResourceCompressor;
import org.exoplatform.portal.resource.compressor.ResourceType;
+import org.exoplatform.web.application.javascript.Javascript.ExtendedJScript;
+import org.exoplatform.web.application.javascript.Javascript.PortalJScript;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
+import org.gatein.wci.WebAppListener;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.picocontainer.Startable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
+import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import javax.servlet.ServletContext;
-public class JavascriptConfigService implements Startable
+public class JavascriptConfigService extends AbstractResourceService implements
Startable
{
-
/** Our logger. */
private final Logger log = LoggerFactory.getLogger(JavascriptConfigService.class);
- private Collection<String> availableScripts_;
+ private List<Javascript> commonJScripts;
+
+ private HashMap<String, List<PortalJScript>> portalJScripts;
- private Collection<String> availableScriptsPaths_;
-
- private List<Javascript> availableScriptsKey_;
-
- private String mergedJavascript = "";
-
- private HashMap<String, String> extendedJavascripts;
-
- private byte[] jsBytes = null;
-
private long lastModified = Long.MAX_VALUE;
/** . */
- private JavascriptDeployer deployer;
+ private WebAppListener deployer;
- private JavascriptRemoval removal;
+ private CachedJavascript mergedCommonJScripts;
- private ResourceCompressor compressor;
+ private final FutureMap<String, CachedJavascript, ResourceResolver> cache;
+
+ public JavascriptConfigService(ExoContainerContext context, ResourceCompressor
compressor)
+ {
+ super(compressor);
- /** Used to clear merged Javascript on undeploying an webapp */
- private Map<String, List<String>> object_view_of_merged_JS;
+ Loader<String, CachedJavascript, ResourceResolver> loader = new
Loader<String, CachedJavascript, ResourceResolver>()
+ {
+ @Override
+ public CachedJavascript retrieve(ResourceResolver context, String key) throws
Exception
+ {
+ Resource resource = context.resolve(key);
+ if (resource == null)
+ {
+ return null;
+ }
+
+ StringBuilder sB = new StringBuilder();
+ try
+ {
+ BufferedReader reader = new BufferedReader(resource.read());
+ String line = reader.readLine();
+ try
+ {
+ while (line != null)
+ {
+ sB.append(line);
+ if ((line = reader.readLine()) != null)
+ {
+ sB.append("\n");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ finally
+ {
+ Safe.close(reader);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return new CachedJavascript(sB.toString());
+ }
+ };
+ cache = new FutureMap<String, CachedJavascript, ResourceResolver>(loader);
- public JavascriptConfigService(ExoContainerContext context, ResourceCompressor
compressor)
- {
- this.compressor = compressor;
- availableScripts_ = new ArrayList<String>();
- availableScriptsPaths_ = new ArrayList<String>();
- availableScriptsKey_ = new ArrayList<Javascript>();
- extendedJavascripts = new HashMap<String, String>();
- deployer = new JavascriptDeployer(context.getPortalContainerName(), this);
- removal = new JavascriptRemoval(this);
- object_view_of_merged_JS = new HashMap<String, List<String>>();
+ commonJScripts = new ArrayList<Javascript>();
+ deployer = new JavascriptConfigDeployer(context.getPortalContainerName(), this);
+ portalJScripts = new HashMap<String, List<PortalJScript>>();
+
+ addResourceResolver(new ExtendedJScriptResourceResolver());
}
/**
- * Return a collection list This method should return the availables scripts in the
service
+ * Return a collection list This method should return the availables scripts in the
service
+ *
+ * @deprecated Somehow, it should use {@link #getCommonJScripts()} instead.
* @return
*/
+ @Deprecated
public Collection<String> getAvailableScripts()
{
- return availableScripts_;
+ ArrayList<String> list = new ArrayList<String>();
+ for (Javascript js : commonJScripts)
+ {
+ list.add(js.getModule());
+ }
+ return list;
}
-
+
/**
- * Get a available script paths
- * @return a collection list. This method should return the available script paths
+ * Return a collection of all common JScripts
+ *
+ * @return
*/
- public Collection<String> getAvailableScriptsPaths()
+ public Collection<Javascript> getCommonJScripts()
{
- return availableScriptsPaths_;
+ return commonJScripts;
}
/**
- * Add extended JavaScript into available JavaScript
- * @param module
- * module name
- * @param scriptPath
- * URI path of JavaScript
- * @param scontext
- * the webapp's {@link javax.servlet.ServletContext}
- * @param scriptData
- * Content of JavaScript that will be added into available JavaScript
+ * Return a collection of all available JS paths
+ *
+ * @deprecated Somehow, it should use {@link #getCommonJScripts()} instead.
+ *
+ * @return A collection of all available JS paths
*/
- public synchronized void addExtendedJavascript(String module, String scriptPath,
ServletContext scontext, String scriptData)
+ @Deprecated
+ public Collection<String> getAvailableScriptsPaths()
{
- String servletContextName = scontext.getServletContextName();
- String path = "/" + servletContextName + scriptPath;
- availableScripts_.add(module);
- availableScriptsPaths_.add(path);
- extendedJavascripts.put(path, scriptData);
+ ArrayList<String> list = new ArrayList<String>();
+ for (Javascript js : commonJScripts)
+ {
+ list.add(js.getPath());
+ }
+
+ return list;
}
-
+
/**
- * Clear available JavaScript and add new JavaScripts
- * @param jsKeys
- * new list of JavaScript will replace current available JavaScript
+ * Add a JScript to {@link #commonJScripts} list and re-sort the list.
+ * Then invalidate cache of all merged common JScripts to
+ * ensure they will be newly merged next time.
+ *
+ * @param js
*/
- public synchronized void addJavascripts(List<Javascript> jsKeys)
+ public void addCommonJScript(Javascript js)
{
- availableScriptsKey_.addAll(jsKeys);
-
-
- Collections.sort(availableScriptsKey_, new Comparator<Javascript>()
+ commonJScripts.add(js);
+
+ Collections.sort(commonJScripts, new Comparator<Javascript>()
{
public int compare(Javascript o1, Javascript o2)
{
- if (o1.getPriority() == o2.getPriority())
- return o1.getKey().getModule().compareTo(o2.getKey().getModule());
- else if (o1.getPriority() < 0)
- return 1;
- else if (o2.getPriority() < 0)
- return -1;
- else
- return o1.getPriority() - o2.getPriority();
+ return o1.getPriority() - o2.getPriority();
}
});
+
+ invalidateMergedCommonJScripts();
+ }
- mergedJavascript = "";
- availableScripts_.clear();
- availableScriptsPaths_.clear();
- object_view_of_merged_JS.clear();
- jsBytes = null;
-
- //
- for (Javascript script : availableScriptsKey_) {
- addJavascript(script);
+ /**
+ * Remove a JScript for this module from {@link #commonJScripts}
+ * and invalidates its cache correspondingly
+ *
+ * @param module
+ */
+ public void removeCommonJScript(String module)
+ {
+ Iterator<Javascript> iterator = commonJScripts.iterator();
+ while (iterator.hasNext())
+ {
+ Javascript js = iterator.next();
+ if (js.getModule().equals(module))
+ {
+ iterator.remove();
+ invalidateCachedJScript(js.getPath());
+ invalidateMergedCommonJScripts();
+ }
}
}
/**
- * Add an JavaScript into available JavaScripts
- * @param javascript
- * JavaScript will be added into available JavaScript
+ * Return a collection of all PortalJScripts which belong to the specified
portalName.
+ *
+ * @param portalName
+ * @return list of JavaScript path which will be loaded by particular portal
*/
- private void addJavascript(Javascript javascript)
+ public Collection<PortalJScript> getPortalJScripts(String portalName)
{
- availableScripts_.add(javascript.getKey().getModule());
- availableScriptsPaths_.add(javascript.getPath());
-
- List<String> mergedJS_list =
object_view_of_merged_JS.get(javascript.getKey().getContextPath());
- if (mergedJS_list == null)
+ return portalJScripts.get(portalName);
+ }
+
+ /**
+ * Add a PortalJScript which will be loaded with a specific portal.
+ * <p>
+ * For now, we don't persist it inside the Portal site storage but just in
memory.
+ * Therefore we could somehow remove all PortalJScript for a Portal by using {@link
#removePortalJScripts(String)}
+ * when the portal is being removed.
+ *
+ * @param js
+ */
+ public void addPortalJScript(PortalJScript js)
+ {
+ List<PortalJScript> list = portalJScripts.get(js.getPortalName());
+ if (list == null)
{
- mergedJS_list = new ArrayList<String>();
- object_view_of_merged_JS.put(javascript.getKey().getContextPath(),
mergedJS_list);
+ list = new ArrayList<PortalJScript>();
}
+
+ list.add(js);
- //Merge internal javascripts
- if(!javascript.getKey().isExternalScript()) {
- StringBuffer sB = new StringBuffer();
- String line = "";
- try
+ Collections.sort(list, new Comparator<Javascript>()
+ {
+ public int compare(Javascript o1, Javascript o2)
{
- BufferedReader reader = javascript.getReader();
- try
- {
- while ((line = reader.readLine()) != null)
- {
- line = line + "\n";
- sB.append(line);
- mergedJS_list.add(line);
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- finally
- {
- Safe.close(reader);
- }
+ return o1.getPriority() - o2.getPriority();
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
- sB.append("\n");
- mergedJS_list.add("\n");
-
- mergedJavascript = mergedJavascript.concat(sB.toString());
- }
+ });
+
+ portalJScripts.put(js.getPortalName(), list);
}
/**
- * Remove JavaScripts from availabe JavaScipts by ServletContext
- * @param scontext
- * the webapp's {@link javax.servlet.ServletContext}
- *
+ * Remove portal name from a JavaScript module or remove JavaScript module if it
contains only one portal name
+ *
+ * @param portalName portal's name which you want to remove
*/
- public synchronized void remove(ServletContext context)
+ public void removePortalJScripts(String portalName)
{
- // We clone to avoid concurrent modification exception
- for (Javascript script : new ArrayList<Javascript>(availableScriptsKey_))
+ List<PortalJScript> list = portalJScripts.remove(portalName);
+ for (PortalJScript js : list)
{
- if (script.getContext().getContextPath().equals(context.getContextPath())) {
- removeJavascript(script);
- }
+ invalidateCachedJScript(js.getPath());
}
}
/**
- * Remove JavaScript from available JavaScripts
- * @param script
- * JavaScript will be removed
+ * unregister a {@link ServletContext} into {@link MainResourceResolver} of {@link
SkinService}
+ *
+ * @param servletContext ServletContext will unregistered
*/
- public synchronized void removeJavascript(Javascript script)
+ public void unregisterServletContext(ServletContext servletContext)
{
- availableScripts_.remove(script.getKey().getModule());
- availableScriptsPaths_.remove(script.getPath());
- object_view_of_merged_JS.remove(script.getKey().getContextPath());
-
- // Enlist entries to be removed
- for (Iterator<Javascript> i = availableScriptsKey_.iterator();i.hasNext();)
+ super.unregisterServletContext(servletContext);
+ remove(servletContext);
+ }
+
+ /**
+ * Remove JavaScripts from availabe JavaScipts by ServletContext
+ * @param scontext
+ * the webapp's {@link javax.servlet.ServletContext}
+ *
+ */
+ public synchronized void remove(ServletContext context)
+ {
+ Iterator<Javascript> iterator = commonJScripts.iterator();
+ while (iterator.hasNext())
{
- Javascript _script = i.next();
- if (script.getKey().equals(_script.getKey()))
+ Javascript js = iterator.next();
+ if (js.getContextPath().equals(context.getContextPath()))
{
- i.remove();
+ iterator.remove();
+ invalidateCachedJScript(js.getPath());
+ invalidateMergedCommonJScripts();
}
}
}
/**
- * Refresh the mergedJavascript
+ * @deprecated Use {@link #invalidateMergedCommonJScripts()} instead
*/
+ @Deprecated
public void refreshMergedJavascript()
{
- mergedJavascript = "";
- jsBytes = null;
- StringBuffer buffer = new StringBuffer();
- for (String webApp : object_view_of_merged_JS.keySet())
- {
- for (String jsPath : object_view_of_merged_JS.get(webApp))
- {
- buffer.append(jsPath);
- }
- }
- mergedJavascript = buffer.toString();
+ invalidateMergedCommonJScripts();
}
/**
@@ -277,59 +319,98 @@
* @param out the output stream
* @throws IOException any io exception
*/
+ @Deprecated
public void writeMergedJavascript(OutputStream out) throws IOException
{
- jsBytes = getMergedJavascript();
+ byte[] jsBytes = getMergedJavascript();
//
out.write(jsBytes);
}
-
+
+ public String getJScript(String path)
+ {
+ CachedJavascript cachedJScript = getCachedJScript(path);
+ if (cachedJScript != null)
+ {
+ return cachedJScript.getText();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
/**
- * Return merged javascript in byte array
- * @return byte[]
+ * Return a CachedJavascript which is lazy loaded from a {@link FutureMap} cache
+ *
+ * @param path
+ * @return
*/
- public byte[] getMergedJavascript()
+ public CachedJavascript getCachedJScript(String path)
{
- if (jsBytes == null)
+ return cache.get(mainResolver, path);
+ }
+
+ /**
+ * Returns a string which is merging of all common JScripts
+ *
+ * @return
+ */
+ public CachedJavascript getMergedCommonJScripts()
+ {
+ if (mergedCommonJScripts == null)
{
- // Generate javascript in a buffer
- StringBuffer allJavascript = new StringBuffer();
- allJavascript.append(mergedJavascript);
- for (String script : extendedJavascripts.values())
+ StringBuilder sB = new StringBuilder();
+ for (Javascript js : commonJScripts)
{
- allJavascript.append(script);
+ if (!js.isExternalScript())
+ {
+ String jScript = getJScript(js.getPath());
+ if (jScript != null)
+ {
+ sB.append(jScript).append("\n");
+ }
+
+ }
}
- String s = allJavascript.toString();
- // Get bytes
- byte[] bytes;
- try
- {
- bytes = s.getBytes("UTF-8");
- }
- catch (UnsupportedEncodingException e)
- {
- throw new AssertionError("No access to UTF-8, e");
- }
+ String jScript = sB.toString();
- // Minify
try
{
- String output = compressor.compress(s, ResourceType.JAVASCRIPT);
- jsBytes = output.getBytes();
+ jScript = compressor.compress(jScript, ResourceType.JAVASCRIPT);
}
catch (Exception e)
{
- log.warn("Error when generating minified javascript, will use normal
javascript instead", e);
- jsBytes = bytes;
}
-// Remove miliseconds because string of date retrieve from Http header
doesn't have miliseconds
- lastModified = (new Date().getTime() / 1000) * 1000;
+
+ mergedCommonJScripts = new CachedJavascript(jScript);
+ lastModified = mergedCommonJScripts.getLastModified();
}
- return jsBytes;
+
+ return mergedCommonJScripts;
}
+ /**
+ * @deprecated Use {@link #getMergedCommonJScripts()} instead.
+ * It is more clearly to see what exactly are included in the returned merging
+ *
+ * @return byte[]
+ */
+ @Deprecated
+ public byte[] getMergedJavascript()
+ {
+ String mergedCommonJS = getMergedCommonJScripts().getText();
+
+ return mergedCommonJS.getBytes();
+ }
+
+ /**
+ * @deprecated the last modification should belong to CachedJavascript object
+ * @return
+ */
+ @Deprecated
public long getLastModified()
{
return lastModified;
@@ -342,12 +423,49 @@
*/
public boolean isModuleLoaded(CharSequence module)
{
- return getAvailableScripts().contains(module);
+ for (Javascript js : commonJScripts)
+ {
+ if (js.getModule().equals(module))
+ {
+ return true;
+ }
+ }
+
+ return false;
}
/**
- * Remove JavaScript from available JavaScripts and extended JavaScripts
+ * Add an extended JavaScript to the list of common JScripts which are loaded by
default
+ *
+ * @deprecated This method support was not good in design so it will be unsupported
soon.
+ * Absolutely this usage can be replaced by using combination of {@link
#addCommonJScript(Javascript)} and {@link ResourceResolver}
+ *
* @param module
+ * module name
+ * @param scriptPath
+ * URI path of JavaScript
+ * @param scontext
+ * the webapp's {@link javax.servlet.ServletContext}
+ * @param scriptData
+ * Content of JavaScript that will be added into available JavaScript
+ */
+ @Deprecated
+ public synchronized void addExtendedJavascript(String module, String scriptPath,
ServletContext scontext, String scriptData)
+ {
+ ExtendedJScript js = new ExtendedJScript(module, scriptPath,
scontext.getContextPath(), scriptData);
+ commonJScripts.add(js);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Added an extended javascript " + js);
+ }
+ }
+
+ /**
+ * Remove an extended Javascript from the list of common JScripts
+ *
+ * @deprecated This method is deprecated according to {@link
#addExtendedJavascript(String, String, ServletContext, String)}.
+ * Use {@link #removeCommonJScript(String)} instead.
+ * @param module
* module will be removed
* @param scriptPath
* URI of script that will be removed
@@ -355,19 +473,31 @@
* the webapp's {@link javax.servlet.ServletContext}
*
*/
+ @Deprecated
public void removeExtendedJavascript(String module, String scriptPath, ServletContext
scontext)
{
- String servletContextName = scontext.getServletContextName();
- availableScripts_.remove(module);
- String path = "/" + servletContextName + scriptPath;
- availableScriptsPaths_.remove(path);
- extendedJavascripts.remove(path);
- jsBytes = null;
+ removeCommonJScript(module);
}
-
-
/**
+ * Invalidate cache of merged common JScripts
+ */
+ public void invalidateMergedCommonJScripts()
+ {
+ mergedCommonJScripts = null;
+ }
+
+ /**
+ * Invalidate cache for this <tt>path</tt>
+ *
+ * @param path
+ */
+ public void invalidateCachedJScript(String path)
+ {
+ cache.remove(path);
+ }
+
+ /**
* Start service.
* Registry org.exoplatform.web.application.javascript.JavascriptDeployer,
* org.exoplatform.web.application.javascript.JavascriptRemoval into
ServletContainer
@@ -376,7 +506,6 @@
public void start()
{
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(deployer);
-
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(removal);
}
/**
@@ -388,7 +517,29 @@
public void stop()
{
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
-
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(removal);
}
-
+
+ private class ExtendedJScriptResourceResolver implements ResourceResolver
+ {
+ @Override
+ public Resource resolve(String path) throws NullPointerException
+ {
+ for (final Javascript js : commonJScripts)
+ {
+ if (js instanceof ExtendedJScript && js.getPath().equals(path))
+ {
+ final String jScript = ((ExtendedJScript)js).getScript();
+ return new Resource(path)
+ {
+ @Override
+ public Reader read() throws IOException
+ {
+ return new StringReader(jScript);
+ }
+ };
+ }
+ }
+ return null;
+ }
+ }
}
Deleted:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -1,133 +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.web.application.javascript;
-
-import org.exoplatform.commons.utils.Safe;
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppLifeCycleEvent;
-import org.gatein.wci.WebAppListener;
-import org.gatein.wci.impl.DefaultServletContainerFactory;
-import org.picocontainer.Startable;
-
-import java.io.InputStream;
-
-import javax.servlet.ServletContext;
-
-/**
- * Created by The eXo Platform SAS
- * Jan 19, 2007
- */
-
-public class JavascriptDeployer implements WebAppListener, Startable
-{
-
- private static final String GATEIN_CONFIG_RESOURCE =
"/WEB-INF/gatein-resources.xml";
-
- /**
- * Logger
- */
- private static final Log LOG = ExoLogger.getLogger(JavascriptDeployer.class);
-
- /** . */
- private final JavascriptConfigService javascriptService;
-
- /**
- * The name of the portal container
- */
- private final String portalContainerName;
-
- public JavascriptDeployer(String portalContainerName, JavascriptConfigService
javascriptService)
- {
- this.javascriptService = javascriptService;
- this.portalContainerName = portalContainerName;
- }
-
- public void start()
- {
-
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(this);
- }
-
- public void stop()
- {
-
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(this);
- }
-
- public void onEvent(WebAppEvent event)
- {
- if (event instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
- if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
- {
- InputStream is = null;
- ServletContext scontext = null;
- try
- {
- scontext = event.getWebApp().getServletContext();
- is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- if (is != null)
- {
- final PortalContainerPostInitTask task = new
PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer
portalContainer)
- {
- register(scontext, portalContainer);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
- }
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while registering 'Javascript in
gatein-resources.xml' from the context '"
- + (scontext == null ? "unknown" :
scontext.getServletContextName()) + "'", ex);
- }
- finally
- {
- Safe.close(is);
- }
- }
- }
- }
-
- private void register(ServletContext scontext, PortalContainer container)
- {
- InputStream is = null;
- try
- {
- is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- JavascriptConfigParser.processConfigResource(is, javascriptService, scontext);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while processing 'Javascript in
gatein-resources.xml' from the context '"
- + scontext.getServletContextName() + "'", ex);
- }
- finally
- {
- Safe.close(is);
- }
- }
-}
\ No newline at end of file
Deleted:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -1,83 +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.web.application.javascript;
-
-/**
- * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
- * @version $Id$
- *
- */
-public class JavascriptKey
-{
-
- /** . */
- private final String module;
-
- /** . */
- private final String scriptPath;
-
- /** . */
- private final String contextPath;
-
- public JavascriptKey(String module, String scriptPath, String contextPath) throws
IllegalArgumentException
- {
- if (module == null || scriptPath == null || contextPath == null)
- {
- throw new IllegalArgumentException("Module and scriptPath are mandatory for
JavascriptKey");
- }
- this.module = module;
- this.scriptPath = scriptPath;
- this.contextPath = contextPath;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof JavascriptKey)
- {
- JavascriptKey that = (JavascriptKey)obj;
- return module.equals(that.module) && scriptPath.equals(that.scriptPath)
&& contextPath.equals(that.contextPath);
- }
- return false;
- }
-
- public String getModule()
- {
- return module;
- }
-
- public String getScriptPath()
- {
- return scriptPath;
- }
-
- public String getContextPath()
- {
- return contextPath;
- }
-
- public boolean isExternalScript()
- {
- return (scriptPath.startsWith("http") ||
scriptPath.startsWith("https")) ? true : false;
- }
-}
Deleted:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -1,86 +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.web.application.javascript;
-
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppLifeCycleEvent;
-import org.gatein.wci.WebAppListener;
-import org.gatein.wci.impl.DefaultServletContainerFactory;
-import org.picocontainer.Startable;
-
-import javax.servlet.ServletContext;
-
-/**
- * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
- * @version $Id$
- *
- */
-public class JavascriptRemoval implements WebAppListener, Startable
-{
-
- private JavascriptConfigService javascriptService;
-
- public JavascriptRemoval(JavascriptConfigService _javascriptService)
- {
- this.javascriptService = _javascriptService;
- }
-
- /**
- * @see org.gatein.wci.WebAppListener#onEvent(org.gatein.wci.WebAppEvent)
- */
- public void onEvent(WebAppEvent arg0)
- {
- if (arg0 instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent wevent = (WebAppLifeCycleEvent)arg0;
- if (wevent.getType() == WebAppLifeCycleEvent.REMOVED)
- {
- removeJavascript(wevent.getWebApp().getServletContext());
- refreshJavascript();
- }
- }
- }
-
- /**
- * Removes javascript deployed in this web app.
- *
- * @param scontext the servlet context
- */
- private void removeJavascript(ServletContext scontext)
- {
- String webApp = scontext.getContextPath();
- javascriptService.remove(scontext);
- }
-
- private void refreshJavascript()
- {
- javascriptService.refreshMergedJavascript();
- }
-
- public void start()
- {
-
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(this);
- }
-
- public void stop()
- {
-
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(this);
- }
-
-}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.web.application.javascript;
+import org.exoplatform.web.application.javascript.Javascript.PortalJScript;
+
import java.util.ArrayList;
import java.util.List;
@@ -40,7 +42,17 @@
public void execute(JavascriptConfigService service, ServletContext scontext)
{
- service.addJavascripts(scripts);
+ for (Javascript js : scripts)
+ {
+ if (js instanceof PortalJScript)
+ {
+ service.addPortalJScript((PortalJScript)js);
+ }
+ else
+ {
+ service.addCommonJScript(js);
+ }
+ }
}
public void addScript(Javascript script)
Modified:
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/AbstractSkinServiceTest.java
===================================================================
---
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/AbstractSkinServiceTest.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/AbstractSkinServiceTest.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -79,7 +79,7 @@
assertEquals(1, skinService.getAvailableSkinNames().size());
assertTrue(skinService.getAvailableSkinNames().contains("TestSkin"));
- String css = skinService.getCSS("/path/to/MockResourceResolver.css");
+ String css = skinService.getCSS("/path/to/MockResourceResolver");
assertEquals(MockResourceResolver.class.getName(), css);
}
Modified:
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceResolver.java
===================================================================
---
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceResolver.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/MockResourceResolver.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -40,7 +40,7 @@
public MockResourceResolver()
{
- addResource("/path/to/MockResourceResolver.css",
this.getClass().getName());
+ addResource("/path/to/MockResourceResolver", this.getClass().getName());
}
public void addResource(String path, String value)
Modified:
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestJavascriptConfigService.java
===================================================================
---
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestJavascriptConfigService.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestJavascriptConfigService.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -20,12 +20,14 @@
import org.exoplatform.container.PortalContainer;
import org.exoplatform.test.mocks.servlet.MockServletContext;
+import org.exoplatform.web.application.javascript.Javascript.PortalJScript;
import org.exoplatform.web.application.javascript.JavascriptConfigParser;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -35,44 +37,64 @@
/**
* @author <a href="mailto:phuong.vu@exoplatform.com">Vu Viet
Phuong</a>
* @version $Id$
- *
*/
public class TestJavascriptConfigService extends AbstractWebResourceTest
{
private JavascriptConfigService jsService;
- private ServletContext mockServletContext;
+ private static MockResourceResolver resResolver;
+
+ private static ServletContext mockServletContext;
- private static final String exModule = "extended.js.test";
+ private static boolean isFirstStartup = true;
- private static final String exPath = "/extended/js/test.js";
-
- private static final ServletContext exContext = new
MockJSServletContext("extendedWebApp", null);
-
@Override
protected void setUp() throws Exception
{
final PortalContainer portalContainer = getContainer();
jsService =
(JavascriptConfigService)portalContainer.getComponentInstanceOfType(JavascriptConfigService.class);
-
- Map<String, String> resources = new HashMap<String, String>(4);
- resources.put("/js/test1.js", "aaa;");
- resources.put("/js/test2.js", "bbb;");
- resources.put("/js/test3.js", "ccc;");
- resources.put("/js/test4.js", "ddd;");
- mockServletContext = new MockJSServletContext("mockwebapp", resources);
- URL url =
portalContainer.getPortalClassLoader().getResource("mockwebapp/gatein-resources.xml");
- JavascriptConfigParser.processConfigResource(url.openStream(), jsService,
mockServletContext);
+ if (isFirstStartup)
+ {
+ Map<String, String> resources = new HashMap<String, String>(4);
+ resources.put("/js/test1.js", "aaa; // inline comment");
+ resources.put("/js/test2.js", "bbb;");
+ resources.put("/js/test3.js", "ccc;");
+ resources.put("/js/test4.js", "ddd;");
+ mockServletContext = new MockJSServletContext("mockwebapp",
resources);
+ jsService.registerContext(mockServletContext);
+
+ resResolver = new MockResourceResolver();
+ jsService.addResourceResolver(resResolver);
+ URL url =
portalContainer.getPortalClassLoader().getResource("mockwebapp/gatein-resources.xml");
+ JavascriptConfigParser.processConfigResource(url.openStream(), jsService,
mockServletContext);
+
+ isFirstStartup = false;
+ }
}
- public void testAvailableScripts()
+ public void testResourceResolver()
{
- assertEquals(4, jsService.getAvailableScripts().size());
+ String jScript = jsService.getJScript("/path/to/MockResourceResolver");
+ assertEquals(MockResourceResolver.class.getName(), jScript);
+
+ jScript = jsService.getJScript("/path/to/non-existing.js");
+ assertNull(jScript);
+
+ resResolver.addResource("/path/to/non-existing.js", "foo");
+ jScript = jsService.getJScript("/path/to/non-existing.js");
+ assertNotNull("foo", jScript);
+ }
+
+ public void testCommonJScripts()
+ {
+ assertEquals(5, jsService.getCommonJScripts().size());
assertTrue(jsService.isModuleLoaded("js.test1"));
assertTrue(jsService.isModuleLoaded("js.test2"));
assertTrue(jsService.isModuleLoaded("js.test3"));
assertTrue(jsService.isModuleLoaded("js.test4"));
+ assertTrue(jsService.isModuleLoaded("js.test7"));
+
assertFalse(jsService.isModuleLoaded("js.test5"));
}
@@ -83,11 +105,16 @@
assertEquals(mockServletContext.getContextPath() + "/js/test4.js",
availPaths.next());
assertEquals(mockServletContext.getContextPath() + "/js/test1.js",
availPaths.next());
assertEquals(mockServletContext.getContextPath() + "/js/test3.js",
availPaths.next());
+
assertEquals("http://example.com/test7.js", availPaths.next());
assertFalse(availPaths.hasNext());
}
- public void testExtendedJS() throws Exception
+ public void testAddingExtendedJScript() throws Exception
{
+ ServletContext exContext = new MockJSServletContext("extendedWebApp",
null);
+ String exModule = "extended.js.test";
+ String exPath = "/extended/js/test.js";
+
jsService.addExtendedJavascript(exModule, exPath, exContext,
"extendedJS;");
assertTrue(jsService.isModuleLoaded(exModule));
assertTrue(jsService.getAvailableScriptsPaths().contains(exContext.getContextPath()
+ exPath));
@@ -107,32 +134,57 @@
assertTrue(first < second);
assertTrue(second < System.currentTimeMillis());
}
-
- public void testMergedJS()
- {
+
+ public void testMergingCommonJScripts()
+ {
String mergedJS = new String(jsService.getMergedJavascript());
- assertEquals("\nbbb;ddd;aaa;ccc;", mergedJS);
+ assertEquals("\nbbb;ddd;aaa;ccc;", mergedJS);
+ assertEquals("\nbbb;ddd;aaa;ccc;",
jsService.getMergedCommonJScripts().getText());
assertTrue(jsService.getLastModified() < System.currentTimeMillis());
- }
-
- public void testRemoveJS()
+ }
+
+ public void testCaching()
{
- assertEquals(4, jsService.getAvailableScripts().size());
- assertEquals(4, jsService.getAvailableScriptsPaths().size());
- jsService.remove(mockServletContext);
- assertEquals(0, jsService.getAvailableScripts().size());
- assertEquals(0, jsService.getAvailableScriptsPaths().size());
+ String path = "/path/to/caching";
+ resResolver.addResource(path, "foo");
+ String jScript = jsService.getJScript(path);
+ assertEquals("foo", jScript);
- assertTrue(jsService.getMergedJavascript().length > 0);
- jsService.refreshMergedJavascript();
- assertTrue(jsService.getMergedJavascript().length == 0);
+ resResolver.addResource(path, "bar");
+ jScript = jsService.getJScript(path);
+ assertEquals("foo", jScript);
+
+ // invalidate cache
+ jsService.invalidateCachedJScript(path);
+ jScript = jsService.getJScript(path);
+ assertEquals("bar", jScript);
}
- @Override
- protected void tearDown() throws Exception
+ public void testPortalJScript()
{
- jsService.remove(mockServletContext);
- jsService.removeExtendedJavascript(exModule, exPath, exContext);
+ Collection<PortalJScript> site =
jsService.getPortalJScripts("site1");
+ assertEquals(1, site.size());
+ Iterator<PortalJScript> iterator = site.iterator();
+ assertEquals(mockServletContext.getContextPath() + "/js/test5.js",
iterator.next().getPath());
+
+ site = jsService.getPortalJScripts("site2");
+ assertEquals(2, site.size());
+ iterator = site.iterator();
+ assertEquals(mockServletContext.getContextPath() + "/js/test6.js",
iterator.next().getPath());
+ assertEquals(mockServletContext.getContextPath() + "/js/test5.js",
iterator.next().getPath());
+
+ assertNull(jsService.getPortalJScripts("classic"));
+
+ jsService.removePortalJScripts("site1");
+ assertNull(jsService.getPortalJScripts("site1"));
+
+ PortalJScript portalJScript = new PortalJScript("portal_module1",
"/path/to/portal/jscript1", "/portal", Integer.MAX_VALUE,
"portal1");
+ jsService.addPortalJScript(portalJScript);
+ String jScript = jsService.getJScript(portalJScript.getPath());
+ assertNull(jScript);
+ resResolver.addResource(portalJScript.getPath(), "bar1");
+ jScript = jsService.getJScript(portalJScript.getPath());
+ assertEquals("bar1", jScript);
}
private static class MockJSServletContext extends MockServletContext
@@ -154,7 +206,15 @@
@Override
public InputStream getResourceAsStream(String s)
{
- return new ByteArrayInputStream(resources.get(s).getBytes());
+ String input = resources.get(s);
+ if (input != null)
+ {
+ return new ByteArrayInputStream(input.getBytes());
+ }
+ else
+ {
+ return null;
+ }
}
}
}
Modified:
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestXSDCorruption.java
===================================================================
---
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestXSDCorruption.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/test/java/org/exoplatform/portal/resource/TestXSDCorruption.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -59,6 +59,6 @@
{
assertHash("c68ea6831c3d24a242f63abd2db261a6",
"gatein_resources_1_0.xsd");
assertHash("c55b7e0dc8ae23e2d34430b38260cd96",
"gatein_resources_1_1.xsd");
- assertHash("6d5566a86feb32f30fb9c7551c026042",
"gatein_resources_1_2.xsd");
+ assertHash("56f2ed48327fed8ea506be982ef53730",
"gatein_resources_1_2.xsd");
}
}
\ No newline at end of file
Modified:
portal/trunk/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml
===================================================================
---
portal/trunk/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/component/web/resources/src/test/resources/mockwebapp/gatein-resources.xml 2011-11-11
10:56:18 UTC (rev 8045)
@@ -19,10 +19,8 @@
02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-->
-<gatein-resources
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_2
http://www.gatein.org/xml/ns/gatein_resources_1_2"
-
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_2">
+<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_2
http://www.gatein.org/xml/ns/gatein_resources_1_2"
+
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_2">
<portal-skin>
<skin-name>TestSkin</skin-name>
@@ -110,4 +108,30 @@
<js-priority>2</js-priority>
</param>
</javascript>
+ <javascript>
+ <param>
+ <portal-name>site1</portal-name>
+ <js-module>js.test5</js-module>
+ <js-path>/js/test5.js</js-path>
+ </param>
+ <param>
+ <portal-name>site2</portal-name>
+ <js-module>js.test5</js-module>
+ <js-path>/js/test5.js</js-path>
+ </param>
+ </javascript>
+ <javascript>
+ <param>
+ <portal-name>site2</portal-name>
+ <js-module>js.test6</js-module>
+ <js-path>/js/test6.js</js-path>
+ <js-priority>1</js-priority>
+ </param>
+ </javascript>
+ <javascript>
+ <param>
+ <js-module>js.test7</js-module>
+ <
js-path>http://example.com/test7.js</js-path>
+ </param>
+ </javascript>
</gatein-resources>
Modified:
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
===================================================================
---
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl 2011-11-11
10:56:18 UTC (rev 8045)
@@ -13,6 +13,7 @@
String skin = uicomponent.getSkin();
def portalSkins = uicomponent.getPortalSkins() ;
def portletSkins = uicomponent.getPortletSkins() ;
+ def portalJScripts = uicomponent.getPortalJScripts();
def scriptsPaths = uicomponent.getJavascriptURLs();
def lang = uicomponent.getLocale().getLanguage();
def title = rcontext.getTitle();
@@ -93,8 +94,15 @@
</script>
<script type="text/javascript"
src="/eXoResources/javascript/eXo/i18n/I18NMessage.js"></script>
<script type="text/javascript"
src="/eXoResources/javascript/eXo/i18n/MessageResource_<%=lang%>.js"></script>
-
- <%
+ <%
+ if (portalJScripts != null)
+ {
+ for (jScript in portalJScripts) {
+ %>
+ <script type="text/javascript"
src="<%=jScript.getPath()%>"></script>
+ <%
+ }
+ }
def headerElements = rcontext.getExtraMarkupHeadersAsStrings();
if (headerElements != null)
{
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/javascript/JavascriptServlet.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -22,10 +22,12 @@
import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.application.ResourceRequestFilter;
+import org.exoplatform.web.application.javascript.CachedJavascript;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
import java.io.IOException;
import java.io.OutputStream;
+import java.net.URLDecoder;
import java.util.Date;
import javax.servlet.ServletConfig;
@@ -62,7 +64,15 @@
final JavascriptConfigService service =
(JavascriptConfigService)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(
JavascriptConfigService.class);
- long lastModified = service.getLastModified();
+ final String uri = URLDecoder.decode(request.getRequestURI(), "UTF-8");
+
+ CachedJavascript jScript = service.getCachedJScript(uri);
+ if (jScript == null)
+ {
+ jScript = service.getMergedCommonJScripts();
+ }
+
+ long lastModified = jScript.getLastModified();
long ifModifiedSince =
request.getDateHeader(ResourceRequestFilter.IF_MODIFIED_SINCE);
// Julien: should we also set charset along with the content type ?
@@ -74,8 +84,8 @@
}
}
- byte[] jsBytes = service.getMergedJavascript();
+ String js = jScript.getText();
response.setDateHeader(ResourceRequestFilter.LAST_MODIFIED, lastModified);
- response.getOutputStream().write(jsBytes);
+ response.getWriter().write(js);
}
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2011-11-11
09:44:12 UTC (rev 8044)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2011-11-11
10:56:18 UTC (rev 8045)
@@ -30,8 +30,6 @@
import org.exoplatform.portal.resource.SkinConfig;
import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.resource.SkinURL;
-import org.exoplatform.web.url.MimeType;
-import org.exoplatform.web.url.navigation.NodeURL;
import org.exoplatform.portal.webui.application.UIPortlet;
import org.exoplatform.portal.webui.page.UIPageActionListener.ChangeNodeActionListener;
import org.exoplatform.portal.webui.page.UISiteBody;
@@ -46,7 +44,10 @@
import org.exoplatform.services.resources.LocaleConfigService;
import org.exoplatform.services.resources.LocaleContextInfo;
import org.exoplatform.services.resources.Orientation;
+import org.exoplatform.web.application.javascript.Javascript.PortalJScript;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
+import org.exoplatform.web.url.MimeType;
+import org.exoplatform.web.url.navigation.NodeURL;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
@@ -320,6 +321,16 @@
return service.getAvailableScriptsPaths();
}
+ /**
+ * Get all JavaScript path which available on selected portal site
+ * @return
+ */
+ public Collection<PortalJScript> getPortalJScripts()
+ {
+ JavascriptConfigService service =
getApplicationComponent(JavascriptConfigService.class);
+ return service.getPortalJScripts(Util.getUIPortal().getName());
+ }
+
public Collection<Skin> getPortalSkins()
{
SkinService skinService = getApplicationComponent(SkinService.class);