From 057252f0e43755dede48f295e98ea01f657af751 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 4 Apr 2006 13:18:44 +0000 Subject: [PATCH] . Generic "command servlet" implementation - Replaces specific command servlets, such as the WorkflowActionServlet with a generic CommandServlet git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2619 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/templates/workflow_details.ftl | 4 +- config/alfresco/web-client-config.xml | 18 ++- .../org/alfresco/web/app/Application.java | 13 +++ .../config/CommandServletConfigElement.java | 105 ++++++++++++++++++ .../config/CommandServletElementReader.java | 73 ++++++++++++ source/web/WEB-INF/web_TEMPLATE.xml | 8 +- 6 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 source/java/org/alfresco/web/config/CommandServletConfigElement.java create mode 100644 source/java/org/alfresco/web/config/CommandServletElementReader.java diff --git a/config/alfresco/templates/workflow_details.ftl b/config/alfresco/templates/workflow_details.ftl index d48124c939..bcafc4c0b0 100644 --- a/config/alfresco/templates/workflow_details.ftl +++ b/config/alfresco/templates/workflow_details.ftl @@ -5,7 +5,7 @@ <#assign ref=document.nodeRef> <#assign workspace=ref[0..ref?index_of("://")-1]> <#assign storenode=ref[ref?index_of("://")+3..]> -   Approve Step: ${document.properties["app:approveStep"]}
+   Approve Step: ${document.properties["app:approveStep"]}
<#if document.properties["app:approveFolder"]?exists>   Approve Folder: ${document.properties["app:approveFolder"].name}
@@ -14,7 +14,7 @@ <#assign ref=document.nodeRef> <#assign workspace=ref[0..ref?index_of("://")-1]> <#assign storenode=ref[ref?index_of("://")+3..]> -   Reject Step: ${document.properties["app:rejectStep"]}
+   Reject Step: ${document.properties["app:rejectStep"]}
<#if document.properties["app:rejectFolder"]?exists>   Reject Folder: ${document.properties["app:rejectFolder"].name}
diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index 1f8cd1492d..95095d9d28 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -10,6 +10,7 @@ + @@ -60,9 +61,10 @@ English - - - + French + German + Japanese + Thailand @@ -124,6 +126,16 @@ --> + + + + + + + + + + diff --git a/source/java/org/alfresco/web/app/Application.java b/source/java/org/alfresco/web/app/Application.java index 90736d6ae7..d6661fae5c 100644 --- a/source/java/org/alfresco/web/app/Application.java +++ b/source/java/org/alfresco/web/app/Application.java @@ -573,6 +573,19 @@ public class Application Application.BEAN_CONFIG_SERVICE); } + /** + * Helper to get the ConfigService instance + * + * @param context ServletContext + * + * @return ConfigService + */ + public static ConfigService getConfigService(ServletContext context) + { + return (ConfigService)WebApplicationContextUtils.getRequiredWebApplicationContext(context).getBean( + Application.BEAN_CONFIG_SERVICE); + } + /** * Helper to get the client config element from the config service * diff --git a/source/java/org/alfresco/web/config/CommandServletConfigElement.java b/source/java/org/alfresco/web/config/CommandServletConfigElement.java new file mode 100644 index 0000000000..58cfa57485 --- /dev/null +++ b/source/java/org/alfresco/web/config/CommandServletConfigElement.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.config; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.config.ConfigElement; +import org.alfresco.config.ConfigException; +import org.alfresco.config.element.ConfigElementAdapter; + +/** + * @author Kevin Roast + */ +public class CommandServletConfigElement extends ConfigElementAdapter +{ + public static final String CONFIG_ELEMENT_ID = "command-servlet"; + + private Map commandProcessors = new HashMap(4, 1.0f); + + /** + * Default constructor + */ + public CommandServletConfigElement() + { + super("command-servlet"); + } + + /** + * Constructor + * + * @param name Name of the element this config element represents + */ + public CommandServletConfigElement(String name) + { + super(name); + } + + /** + * @see org.alfresco.config.element.ConfigElementAdapter#getChildren() + */ + public List getChildren() + { + throw new ConfigException("Reading the Command Servlet config via the generic interfaces is not supported"); + } + + /** + * @see org.alfresco.config.element.ConfigElementAdapter#combine(org.alfresco.config.ConfigElement) + */ + public ConfigElement combine(ConfigElement configElement) + { + CommandServletConfigElement existingElement = (CommandServletConfigElement)configElement; + CommandServletConfigElement newElement = new CommandServletConfigElement(); + + for (String name : commandProcessors.keySet()) + { + newElement.addCommandProcessor(name, commandProcessors.get(name)); + } + for (String name : existingElement.commandProcessors.keySet()) + { + newElement.addCommandProcessor(name, existingElement.commandProcessors.get(name)); + } + + return newElement; + } + + /*package*/ void addCommandProcessor(String name, String className) + { + try + { + Class clazz = Class.forName(className); + commandProcessors.put(name, clazz); + } + catch (Throwable err) + { + throw new ConfigException("Unable to load command proccessor class: " + + className + " due to " + err.getMessage()); + } + } + + private void addCommandProcessor(String name, Class clazz) + { + commandProcessors.put(name, clazz); + } + + public Class getCommandProcessor(String name) + { + return commandProcessors.get(name); + } +} diff --git a/source/java/org/alfresco/web/config/CommandServletElementReader.java b/source/java/org/alfresco/web/config/CommandServletElementReader.java new file mode 100644 index 0000000000..f61afd1496 --- /dev/null +++ b/source/java/org/alfresco/web/config/CommandServletElementReader.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.config; + +import java.util.Iterator; + +import org.alfresco.config.ConfigElement; +import org.alfresco.config.ConfigException; +import org.alfresco.config.xml.elementreader.ConfigElementReader; +import org.dom4j.Element; + +/** + * @author Kevin Roast + */ +public class CommandServletElementReader implements ConfigElementReader +{ + public static final String ELEMENT_COMMANDPROCESSOR = "command-processor"; + public static final String ATTRIBUTE_NAME = "name"; + public static final String ATTRIBUTE_CLASS = "class"; + + /** + * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) + */ + @SuppressWarnings("unchecked") + public ConfigElement parse(Element element) + { + CommandServletConfigElement configElement = new CommandServletConfigElement(); + + if (element != null) + { + if (CommandServletConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false) + { + throw new ConfigException("CommandServletElementReader can only parse config elements of type 'command-servlet'"); + } + + Iterator itr = element.elementIterator(ELEMENT_COMMANDPROCESSOR); + while (itr.hasNext()) + { + Element procElement = itr.next(); + + String name = procElement.attributeValue(ATTRIBUTE_NAME); + String className = procElement.attributeValue(ATTRIBUTE_CLASS); + + if (name == null || name.length() == 0) + { + throw new ConfigException("'name' attribute is mandatory for command processor config element."); + } + if (className == null || className.length() == 0) + { + throw new ConfigException("'class' attribute is mandatory for command processor config element."); + } + + configElement.addCommandProcessor(name, className); + } + } + + return configElement; + } +} diff --git a/source/web/WEB-INF/web_TEMPLATE.xml b/source/web/WEB-INF/web_TEMPLATE.xml index 9c25b5f0c9..de3b94029a 100644 --- a/source/web/WEB-INF/web_TEMPLATE.xml +++ b/source/web/WEB-INF/web_TEMPLATE.xml @@ -151,8 +151,8 @@ - workflowAction - org.alfresco.web.app.servlet.WorkflowActionServlet + commandServlet + org.alfresco.web.app.servlet.CommandServlet @@ -201,8 +201,8 @@ - workflowAction - /workflow/* + commandServlet + /command/*