Author: hoang_to
Date: 2009-11-09 04:24:53 -0500 (Mon, 09 Nov 2009)
New Revision: 525
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
Log:
GTNPORTAL-131: Javascript deployment
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2009-11-09
08:56:38 UTC (rev 524)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2009-11-09
09:24:53 UTC (rev 525)
@@ -33,20 +33,23 @@
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
- *
+ *
*/
public class JavascriptConfigParser
{
- public static void processConfigResource(InputStream is, JavascriptConfigService
service, ServletContext scontext){
+ public static void processConfigResource(InputStream is, JavascriptConfigService
service, ServletContext scontext)
+ {
List<JavascriptTask> tasks = fetchTasks(is);
- if(tasks != null){
- for(JavascriptTask task : tasks){
+ if (tasks != null)
+ {
+ for (JavascriptTask task : tasks)
+ {
task.execute(service, scontext);
}
}
}
-
+
private static List<JavascriptTask> fetchTasks(InputStream is)
{
try
@@ -60,42 +63,53 @@
return null;
}
}
-
- private static List<JavascriptTask> fetchTasksFromXMLConfig(Document document){
+
+ private static List<JavascriptTask> fetchTasksFromXMLConfig(Document document)
+ {
List<JavascriptTask> tasks = new ArrayList<JavascriptTask>();
Element element = document.getDocumentElement();
- //NodeList nodes = element.getElementsByTagName(GateinResource.JAVA_SCRIPT_TAG);
+ // NodeList nodes =
+ // element.getElementsByTagName(GateinResource.JAVA_SCRIPT_TAG);
NodeList nodes = element.getElementsByTagName("javascript");
int length = nodes.getLength();
- for(int i = 0; i < length; i++){
+ for (int i = 0; i < length; i++)
+ {
JavascriptTask task = xmlToTask((Element)nodes.item(i));
- if(task != null){
+ if (task != null)
+ {
tasks.add(task);
}
}
return tasks;
}
-
- private static JavascriptTask xmlToTask(Element element){
- //if(!GateinResource.JAVA_SCRIPT_TAG.equals(element.getTagName())){
- if(!"javascript".equals(element.getTagName())){
+
+ private static JavascriptTask xmlToTask(Element element)
+ {
+ // if(!GateinResource.JAVA_SCRIPT_TAG.equals(element.getTagName())){
+ if (!"javascript".equals(element.getTagName()))
+ {
return null;
}
- try{
+ try
+ {
JavascriptTask task = new JavascriptTask();
- //NodeList nodes =
element.getElementsByTagName(GateinResource.JAVA_SCRIPT_PARAM);
+ // NodeList nodes =
+ // element.getElementsByTagName(GateinResource.JAVA_SCRIPT_PARAM);
NodeList nodes = element.getElementsByTagName("param");
int length = nodes.getLength();
- for(int i = 0; i < length ; i++){
+ for (int i = 0; i < length; i++)
+ {
Element param_ele = (Element)nodes.item(i);
String js_module =
param_ele.getElementsByTagName("js-module").item(0).getFirstChild().getNodeValue();
String js_path =
param_ele.getElementsByTagName("js-path").item(0).getFirstChild().getNodeValue();
- task.addParam(js_module, js_path);
+ task.addJSKey(js_module, js_path);
}
return task;
- }catch(Exception ex){
+ }
+ catch (Exception ex)
+ {
ex.printStackTrace();
return null;
}
- }
+ }
}
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2009-11-09
08:56:38 UTC (rev 524)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2009-11-09
09:24:53 UTC (rev 525)
@@ -49,17 +49,20 @@
/** . */
private JavascriptDeployer deployer;
+ private JavascriptRemoval removal;
+
public JavascriptConfigService(ExoContainerContext context)
{
availableScripts_ = new ArrayList<String>();
availableScriptsPaths_ = new ArrayList<String>();
extendedJavascripts = new HashMap<String, String>();
deployer = new JavascriptDeployer(context.getPortalContainerName(), this);
+ removal = new JavascriptRemoval(context.getPortalContainerName(), this);
}
/**
- * 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
*
* @return
*/
@@ -81,6 +84,10 @@
availableScriptsPaths_.add(path);
extendedJavascripts.put(path, scriptData);
}
+
+ public void addJavascript(JavascriptKey key, ServletContext scontext){
+ addJavascript(key.getModule(), key.getScriptPath(), scontext);
+ }
public void addJavascript(String module, String scriptPath, ServletContext scontext)
{
@@ -121,6 +128,14 @@
sB.append("\n");
mergedJavascript = mergedJavascript.concat(sB.toString());
}
+
+ public void removeJavascript(JavascriptKey key, ServletContext scontext){
+
+ }
+
+ public void refreshMergedJavascript(){
+
+ }
public byte[] getMergedJavascript()
{
@@ -165,10 +180,13 @@
public void start()
{
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(deployer);
+
DefaultServletContainerFactory.getInstance().getServletContainer().addWebAppListener(removal);
}
public void stop()
{
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
+
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(removal);
}
+
}
\ No newline at end of file
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
(rev 0)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java 2009-11-09
09:24:53 UTC (rev 525)
@@ -0,0 +1,87 @@
+/*
+ * 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 java.util.List;
+
+import javax.servlet.ServletContext;
+
+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;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+public class JavascriptRemoval implements WebAppListener, Startable
+{
+
+ private String portalContainerName;
+
+ private JavascriptConfigService javascriptService;
+
+ public JavascriptRemoval(String _portalContainerName, JavascriptConfigService
_javascriptService)
+ {
+ this.portalContainerName = _portalContainerName;
+ 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();
+ }
+ }
+ }
+
+ /** Remove javascript deployed in this web app **/
+ private void removeJavascript(ServletContext scontext){
+ String webApp = scontext.getContextPath();
+ List<JavascriptKey> jsKeys =
JavascriptDependentManager.getDeployedJScripts(webApp);
+ for(JavascriptKey key : jsKeys){
+ javascriptService.removeJavascript(key, scontext);
+ }
+ JavascriptDependentManager.clearAssociatedJScripts(webApp);
+ }
+
+ 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/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2009-11-09
08:56:38 UTC (rev 524)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2009-11-09
09:24:53 UTC (rev 525)
@@ -23,39 +23,32 @@
import javax.servlet.ServletContext;
-
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
- *
+ *
*/
public class JavascriptTask
{
-
- private List<Parameter> parameters;
-
- public JavascriptTask(){
- parameters = new ArrayList<Parameter>();
+
+ private List<JavascriptKey> jsKeys;
+
+ public JavascriptTask()
+ {
+ jsKeys = new ArrayList<JavascriptKey>();
}
-
- public void execute(JavascriptConfigService service, ServletContext scontext){
- for(Parameter param : parameters){
- service.addJavascript(param.moduleName, param.scriptPath, scontext);
+
+ public void execute(JavascriptConfigService service, ServletContext scontext)
+ {
+ for (JavascriptKey key : jsKeys)
+ {
+ service.addJavascript(key, scontext);
}
+ JavascriptDependentManager.addJavascriptDependent(scontext.getContextPath(),
jsKeys);
}
-
- public void addParam(String moduleName, String scriptPath){
- parameters.add(new Parameter(moduleName, scriptPath));
+
+ public void addJSKey(String moduleName, String scriptPath)
+ {
+ jsKeys.add(new JavascriptKey(moduleName, scriptPath));
}
-
- private class Parameter {
-
- private String moduleName;
- private String scriptPath;
-
- Parameter(String _moduleName, String _scriptPath){
- moduleName = _moduleName;
- scriptPath = _scriptPath;
- }
- }
}