Author: hoang_to
Date: 2009-11-09 05:41:01 -0500 (Mon, 09 Nov 2009)
New Revision: 526
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDependentManager.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
Log:
GTNPORTAL-131: Javascript deployment
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
09:24:53 UTC (rev 525)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2009-11-09
10:41:01 UTC (rev 526)
@@ -30,6 +30,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.servlet.ServletContext;
@@ -50,6 +52,9 @@
private JavascriptDeployer deployer;
private JavascriptRemoval removal;
+
+ /** Used to clear merged Javascript on undeploying an webapp */
+ private Map<String, List<String>> object_view_of_merged_JS;
public JavascriptConfigService(ExoContainerContext context)
{
@@ -58,6 +63,7 @@
extendedJavascripts = new HashMap<String, String>();
deployer = new JavascriptDeployer(context.getPortalContainerName(), this);
removal = new JavascriptRemoval(context.getPortalContainerName(), this);
+ object_view_of_merged_JS = new HashMap<String, List<String>>();
}
/**
@@ -94,6 +100,13 @@
String servletContextName = scontext.getServletContextName();
availableScripts_.add(module);
availableScriptsPaths_.add("/" + servletContextName + scriptPath);
+
+ List<String> mergedJS_list = object_view_of_merged_JS.get("/" +
servletContextName);
+ if(mergedJS_list == null){
+ mergedJS_list = new ArrayList<String>();
+ object_view_of_merged_JS.put("/" + servletContextName,
mergedJS_list);
+ }
+
StringBuffer sB = new StringBuffer();
String line = "";
try
@@ -103,7 +116,9 @@
{
while ((line = reader.readLine()) != null)
{
- sB.append(line + "\n");
+ line = line + "\n";
+ sB.append(line);
+ mergedJS_list.add(line);
}
}
catch (Exception ex)
@@ -126,15 +141,28 @@
e.printStackTrace();
}
sB.append("\n");
+ mergedJS_list.add("\n");
+
mergedJavascript = mergedJavascript.concat(sB.toString());
}
public void removeJavascript(JavascriptKey key, ServletContext scontext){
-
+ String contextPath = scontext.getContextPath();
+ availableScripts_.remove(key.getModule());
+ availableScriptsPaths_.remove(contextPath + key.getScriptPath());
+ object_view_of_merged_JS.remove(contextPath);
}
+ /** Refresh the mergedJavascript **/
public void refreshMergedJavascript(){
-
+ mergedJavascript = "";
+ 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();
}
public byte[] getMergedJavascript()
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDependentManager.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDependentManager.java
(rev 0)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDependentManager.java 2009-11-09
10:41:01 UTC (rev 526)
@@ -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.web.application.javascript;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+public class JavascriptDependentManager
+{
+ private static Map<String, List<JavascriptKey>> webApp_JScripts_map = new
HashMap<String, List<JavascriptKey>>();
+
+ public static void addJavascriptDependent(String webApp, List<JavascriptKey>
jsKeys)
+ {
+ List<JavascriptKey> deployedJSs = webApp_JScripts_map.get(webApp);
+ if (deployedJSs == null)
+ {
+ deployedJSs = new ArrayList<JavascriptKey>();
+ webApp_JScripts_map.put(webApp, deployedJSs);
+ }
+ for(JavascriptKey key : jsKeys){
+ deployedJSs.add(key);
+ }
+ }
+
+ public static void clearAssociatedJScripts(String webApp)
+ {
+ webApp_JScripts_map.remove(webApp);
+ }
+
+ public static List<JavascriptKey> getDeployedJScripts(String webApp)
+ {
+ return webApp_JScripts_map.get(webApp);
+ }
+
+}
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
(rev 0)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java 2009-11-09
10:41:01 UTC (rev 526)
@@ -0,0 +1,64 @@
+/*
+ * 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 String module;
+
+ private String scriptPath;
+
+ public JavascriptKey(String _module, String _scriptPath) throws
IllegalArgumentException{
+ if(_module == null || _scriptPath == null){
+ throw new IllegalArgumentException("Module and scriptPath are mandatory for
JavascriptKey");
+ }
+ this.module = _module;
+ this.scriptPath = _scriptPath;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if(this == null || obj == null){
+ return this == null && obj == null;
+ }
+
+ if(!(obj instanceof JavascriptKey)){
+ return false;
+ }else{
+ JavascriptKey target = (JavascriptKey)obj;
+ return module.equals(target.module) &&
scriptPath.equals(target.scriptPath);
+ }
+
+ }
+
+ public String getModule(){
+ return module;
+ }
+
+ public String getScriptPath(){
+ return scriptPath;
+ }
+}