Author: hoang_to
Date: 2009-10-30 05:39:55 -0400 (Fri, 30 Oct 2009)
New Revision: 455
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/JavascriptTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/JavascriptConfigParser.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
Log:
GTNPORTAL-131: Javascript deployment
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/JavascriptTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/JavascriptTask.java
(rev 0)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/JavascriptTask.java 2009-10-30
09:39:55 UTC (rev 455)
@@ -0,0 +1,62 @@
+/*
+ * 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.config.tasks;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.exoplatform.web.application.javascript.JavascriptConfigService;
+
+/**
+ * @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>();
+ }
+
+ public void execute(JavascriptConfigService service, ServletContext scontext){
+ for(Parameter param : parameters){
+ service.addJavascript(param.moduleName, param.scriptPath, scontext);
+ }
+ }
+
+ public void addParam(String moduleName, String scriptPath){
+ parameters.add(new Parameter(moduleName, scriptPath));
+ }
+
+ private class Parameter {
+
+ private String moduleName;
+ private String scriptPath;
+
+ Parameter(String _moduleName, String _scriptPath){
+ moduleName = _moduleName;
+ scriptPath = _scriptPath;
+ }
+ }
+}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java 2009-10-30
06:55:23 UTC (rev 454)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java 2009-10-30
09:39:55 UTC (rev 455)
@@ -51,4 +51,12 @@
final public static String STYLE_THEME_TAG = "style-theme";
final public static String THEME_NAME_TAG = "theme-name";
+
+ final public static String JAVA_SCRIPT_TAG = "javascript";
+
+ final public static String JAVA_SCRIPT_PARAM = "param";
+
+ final public static String JAVA_SCRIPT_MODULE = "js-module";
+
+ final public static String JAVA_SCRIPT_PATH = "js-path";
}
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/JavascriptConfigParser.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/JavascriptConfigParser.java
(rev 0)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/JavascriptConfigParser.java 2009-10-30
09:39:55 UTC (rev 455)
@@ -0,0 +1,95 @@
+/*
+ * 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.config.xml;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.exoplatform.portal.resource.config.tasks.JavascriptTask;
+import org.exoplatform.web.application.javascript.JavascriptConfigService;
+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$
+ *
+ */
+public class JavascriptConfigParser
+{
+
+ public static void processConfigResource(InputStream is, JavascriptConfigService
service, ServletContext scontext){
+ List<JavascriptTask> tasks = fetchTasks(is);
+ if(tasks != null){
+ for(JavascriptTask task : tasks){
+ task.execute(service, scontext);
+ }
+ }
+ }
+
+ private static List<JavascriptTask> fetchTasks(InputStream is)
+ {
+ try
+ {
+ DocumentBuilder docBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = docBuilder.parse(is);
+ return fetchTasksFromXMLConfig(document);
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
+ 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);
+
+ for(int i = nodes.getLength() - 1 ; i >= 0; i--){
+ JavascriptTask task = xmlToTask((Element)nodes.item(i));
+ if(task != null){
+ tasks.add(task);
+ }
+ }
+ return tasks;
+ }
+
+ private static JavascriptTask xmlToTask(Element element){
+ try{
+ JavascriptTask task = new JavascriptTask();
+ NodeList nodes =
element.getElementsByTagName(GateinResource.JAVA_SCRIPT_PARAM);
+ for(int i = nodes.getLength() - 1 ; i >= 0; i--){
+ Element param_ele = (Element)nodes.item(i);
+ task.addParam(param_ele.getFirstChild().getNodeValue(),
param_ele.getLastChild().getNodeValue());
+ }
+ return task;
+ }catch(Exception ex){
+ return null;
+ }
+ }
+
+
+}
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2009-10-30
06:55:23 UTC (rev 454)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2009-10-30
09:39:55 UTC (rev 455)
@@ -45,6 +45,8 @@
public class JavascriptDeployer implements WebAppListener, Startable
{
+ private static final String GATEIN_CONFIG_RESOURCE =
"/WEB-INF/gatein-resources.xml";
+
/**
* Logger
*/
@@ -87,6 +89,7 @@
scontext = event.getWebApp().getServletContext();
InputStream is =
scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/JavascriptScript.groovy");
+ //InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
if (is == null)
return;
try
@@ -122,6 +125,7 @@
try
{
is =
scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/JavascriptScript.groovy");
+ //is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
Binding binding = new Binding();
binding.setVariable("JavascriptService", javascriptService);
binding.setVariable("ServletContext", scontext);