Author: trong.tran
Date: 2010-02-03 02:46:46 -0500 (Wed, 03 Feb 2010)
New Revision: 1508
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/resource/config/xml/GateinResource.java
portal/branches/3.0.0-Beta05-CP/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
Log:
GTNPORTAL-541: Implement priority of Javascripts
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigParser.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -18,6 +18,11 @@
*/
package org.exoplatform.web.application.javascript;
+import org.exoplatform.web.resource.config.xml.GateinResource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -26,11 +31,6 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.exoplatform.web.resource.config.xml.GateinResource;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
@@ -100,7 +100,18 @@
param_ele.getElementsByTagName(GateinResource.JAVA_SCRIPT_MODULE).item(0).getFirstChild().getNodeValue();
String js_path =
param_ele.getElementsByTagName(GateinResource.JAVA_SCRIPT_PATH).item(0).getFirstChild().getNodeValue();
- task.addJSKey(js_module, js_path);
+ Integer js_priority = null;
+ try
+ {
+ js_priority =
+
Integer.valueOf(param_ele.getElementsByTagName(GateinResource.JAVA_SCRIPT_PRIORITY).item(0)
+ .getFirstChild().getNodeValue());
+ }
+ catch (Exception e)
+ {
+ //Js_priority still is null;
+ }
+ task.addJSKey(js_module, js_path, js_priority);
}
return task;
}
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -53,7 +53,7 @@
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;
@@ -91,23 +91,25 @@
availableScriptsPaths_.add(path);
extendedJavascripts.put(path, scriptData);
}
-
- public void addJavascript(JavascriptKey key, ServletContext scontext){
- addJavascript(key.getModule(), key.getScriptPath(), scontext);
+
+ public void addJavascript(JavascriptKey key, ServletContext scontext)
+ {
+ addJavascript(key.getModule(), key.getScriptPath(), key.getPriority(), scontext);
}
- public void addJavascript(String module, String scriptPath, ServletContext scontext)
+ public void addJavascript(String module, String scriptPath, Integer priority,
ServletContext scontext)
{
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){
+ 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
@@ -137,23 +139,27 @@
}
sB.append("\n");
mergedJS_list.add("\n");
-
+
mergedJavascript = mergedJavascript.concat(sB.toString());
}
-
- public void removeJavascript(JavascriptKey key, ServletContext scontext){
+
+ 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(){
+ 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)){
+ for (String webApp : object_view_of_merged_JS.keySet())
+ {
+ for (String jsPath : object_view_of_merged_JS.get(webApp))
+ {
buffer.append(jsPath);
}
}
@@ -211,5 +217,5 @@
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(deployer);
DefaultServletContainerFactory.getInstance().getServletContainer().removeWebAppListener(removal);
}
-
+
}
\ No newline at end of file
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -43,7 +43,7 @@
{
private static final String GATEIN_CONFIG_RESOURCE =
"/WEB-INF/gatein-resources.xml";
-
+
/**
* Logger
*/
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptKey.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -25,40 +25,56 @@
*/
public class JavascriptKey
{
-
+
private String module;
-
+
private String scriptPath;
-
- public JavascriptKey(String _module, String _scriptPath) throws
IllegalArgumentException{
- if(_module == null || _scriptPath == null){
+
+ private int priority;
+
+ public JavascriptKey(String _module, String _scriptPath, Integer priority) throws
IllegalArgumentException
+ {
+ if (_module == null || _scriptPath == null)
+ {
throw new IllegalArgumentException("Module and scriptPath are mandatory for
JavascriptKey");
}
this.module = _module;
this.scriptPath = _scriptPath;
+ this.priority = (priority != null ? priority.intValue() : -1);
}
-
+
@Override
public boolean equals(Object obj)
{
- if(this == null || obj == null){
+ if (this == null || obj == null)
+ {
return this == null && obj == null;
}
-
- if(!(obj instanceof JavascriptKey)){
+
+ if (!(obj instanceof JavascriptKey))
+ {
return false;
- }else{
+ }
+ else
+ {
JavascriptKey target = (JavascriptKey)obj;
return module.equals(target.module) &&
scriptPath.equals(target.scriptPath);
}
-
+
}
-
- public String getModule(){
+
+ public String getModule()
+ {
return module;
}
-
- public String getScriptPath(){
+
+ public String getScriptPath()
+ {
return scriptPath;
}
+
+ public int getPriority()
+ {
+ return priority;
+ }
}
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptRemoval.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -18,16 +18,16 @@
*/
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;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -19,6 +19,8 @@
package org.exoplatform.web.application.javascript;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import javax.servlet.ServletContext;
@@ -40,6 +42,20 @@
public void execute(JavascriptConfigService service, ServletContext scontext)
{
+ Collections.sort(jsKeys, new Comparator<JavascriptKey>()
+ {
+ public int compare(JavascriptKey js1, JavascriptKey js2)
+ {
+ if (js1.getPriority() == js2.getPriority())
+ return js1.getModule().compareTo(js2.getModule());
+ else if (js1.getPriority() < 0)
+ return 1;
+ else if (js2.getPriority() < 0)
+ return -1;
+ else
+ return js1.getPriority() - js2.getPriority();
+ }
+ });
for (JavascriptKey key : jsKeys)
{
service.addJavascript(key, scontext);
@@ -47,8 +63,8 @@
JavascriptDependentManager.addJavascriptDependent(scontext.getContextPath(),
jsKeys);
}
- public void addJSKey(String moduleName, String scriptPath)
+ public void addJSKey(String moduleName, String scriptPath, Integer priority)
{
- jsKeys.add(new JavascriptKey(moduleName, scriptPath));
+ jsKeys.add(new JavascriptKey(moduleName, scriptPath, priority));
}
}
Modified:
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/resource/config/xml/GateinResource.java
===================================================================
---
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/resource/config/xml/GateinResource.java 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/component/web/src/main/java/org/exoplatform/web/resource/config/xml/GateinResource.java 2010-02-03
07:46:46 UTC (rev 1508)
@@ -61,4 +61,6 @@
final public static String JAVA_SCRIPT_MODULE = "js-module";
final public static String JAVA_SCRIPT_PATH = "js-path";
+
+ final public static String JAVA_SCRIPT_PRIORITY = "js-priority";
}
Modified:
portal/branches/3.0.0-Beta05-CP/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
---
portal/branches/3.0.0-Beta05-CP/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-03
07:38:14 UTC (rev 1507)
+++
portal/branches/3.0.0-Beta05-CP/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-03
07:46:46 UTC (rev 1508)
@@ -112,6 +112,7 @@
<param>
<js-module>eXo</js-module>
<js-path>/javascript/eXo.js</js-path>
+ <js-priority>0</js-priority>
</param>
</javascript>
@@ -120,14 +121,17 @@
<param>
<js-module>eXo.core.Utils</js-module>
<js-path>/javascript/eXo/core/Util.js</js-path>
+ <js-priority>0</js-priority>
</param>
<param>
<js-module>eXo.core.DOMUtil</js-module>
<js-path>/javascript/eXo/core/DOMUtil.js</js-path>
+ <js-priority>1</js-priority>
</param>
<param>
<js-module>eXo.core.Browser</js-module>
<js-path>/javascript/eXo/core/Browser.js</js-path>
+ <js-priority>1</js-priority>
</param>
<param>
<js-module>eXo.core.MouseEventManager</js-module>