Author: tan_pham_dinh
Date: 2010-02-03 02:38:14 -0500 (Wed, 03 Feb 2010)
New Revision: 1507
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/JavascriptTask.java
portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
Log:
GTNPORTAL-541: Refactor ordering Javascript
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 2010-02-03
07:20:09 UTC (rev 1506)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptConfigService.java 2010-02-03
07:38:14 UTC (rev 1507)
@@ -28,11 +28,15 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.AbstractMap.SimpleEntry;
import javax.servlet.ServletContext;
@@ -43,6 +47,8 @@
private Collection<String> availableScriptsPaths_;
+ private List<AbstractMap.SimpleEntry<JavascriptKey, ServletContext>>
availableScriptsKey_;
+
private String mergedJavascript = "";
private HashMap<String, String> extendedJavascripts;
@@ -61,6 +67,7 @@
{
availableScripts_ = new ArrayList<String>();
availableScriptsPaths_ = new ArrayList<String>();
+ availableScriptsKey_ = new ArrayList<AbstractMap.SimpleEntry<JavascriptKey,
ServletContext>>();
extendedJavascripts = new HashMap<String, String>();
deployer = new JavascriptDeployer(context.getPortalContainerName(), this);
removal = new JavascriptRemoval(context.getPortalContainerName(), this);
@@ -75,11 +82,13 @@
*/
public Collection<String> getAvailableScripts()
{
+ serializeKeyPath();
return availableScripts_;
}
public Collection<String> getAvailableScriptsPaths()
{
+ serializeKeyPath();
return availableScriptsPaths_;
}
@@ -94,11 +103,43 @@
public void addJavascript(JavascriptKey key, ServletContext scontext)
{
- addJavascript(key.getModule(), key.getScriptPath(), key.getPriority(), scontext);
+ availableScriptsKey_.add(new SimpleEntry<JavascriptKey, ServletContext>(key,
scontext));
}
- public void addJavascript(String module, String scriptPath, Integer priority,
ServletContext scontext)
+ private void serializeKeyPath()
{
+ Collections.sort(availableScriptsKey_, new
Comparator<SimpleEntry<JavascriptKey, ServletContext>>()
+ {
+ public int compare(SimpleEntry<JavascriptKey, ServletContext> entry1,
+ SimpleEntry<JavascriptKey, ServletContext> entry2)
+ {
+ JavascriptKey js1 = entry1.getKey();
+ JavascriptKey js2 = entry2.getKey();
+
+ 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();
+ }
+ });
+
+ availableScripts_.clear();
+ availableScriptsPaths_.clear();
+ mergedJavascript = "";
+
+ for (SimpleEntry<JavascriptKey, ServletContext> entry :
availableScriptsKey_)
+ {
+ JavascriptKey key = entry.getKey();
+ addJavascript(key.getModule(), key.getScriptPath(), entry.getValue());
+ }
+ }
+
+ private void addJavascript(String module, String scriptPath, ServletContext scontext)
+ {
String servletContextName = scontext.getServletContextName();
availableScripts_.add(module);
availableScriptsPaths_.add("/" + servletContextName + scriptPath);
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 2010-02-03
07:20:09 UTC (rev 1506)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptTask.java 2010-02-03
07:38:14 UTC (rev 1507)
@@ -19,8 +19,6 @@
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;
@@ -42,20 +40,6 @@
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);
Modified: portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-03
07:20:09 UTC (rev 1506)
+++ portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-03
07:38:14 UTC (rev 1507)
@@ -121,7 +121,7 @@
<param>
<js-module>eXo.core.Utils</js-module>
<js-path>/javascript/eXo/core/Util.js</js-path>
- <js-priority>0</js-priority>
+ <js-priority>1</js-priority>
</param>
<param>
<js-module>eXo.core.DOMUtil</js-module>
@@ -131,7 +131,7 @@
<param>
<js-module>eXo.core.Browser</js-module>
<js-path>/javascript/eXo/core/Browser.js</js-path>
- <js-priority>1</js-priority>
+ <js-priority>2</js-priority>
</param>
<param>
<js-module>eXo.core.MouseEventManager</js-module>