mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
URL argument support for the Template and Script servlets
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2905 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -127,7 +127,7 @@ public class CommandServlet extends BaseServlet
|
||||
txn.begin();
|
||||
|
||||
// inform the processor to execute the specified command
|
||||
processor.process(serviceRegistry, req.getSession(), command);
|
||||
processor.process(serviceRegistry, req, command);
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
@@ -166,11 +166,18 @@ public class CommandServlet extends BaseServlet
|
||||
}
|
||||
|
||||
/**
|
||||
* @param procName
|
||||
* Created the specified CommandProcessor instance. The name of the processor is looked up
|
||||
* in the client config, it should find a valid class impl and then create it.
|
||||
*
|
||||
* @param procName Name of the CommandProcessor to lookup in the client config.
|
||||
*
|
||||
* @return CommandProcessor
|
||||
*
|
||||
* @throws InstantiationException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
private CommandProcessor createCommandProcessor(String procName) throws InstantiationException, IllegalAccessException
|
||||
private CommandProcessor createCommandProcessor(String procName)
|
||||
throws InstantiationException, IllegalAccessException
|
||||
{
|
||||
Config config = Application.getConfigService(getServletContext()).getConfig("Command Servlet");
|
||||
if (config == null)
|
||||
|
@@ -19,6 +19,8 @@ package org.alfresco.web.app.servlet;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
@@ -166,7 +168,7 @@ public class TemplateContentServlet extends BaseServlet
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req.getSession(), req.getParameterMap(), nodeRef);
|
||||
Object model = getModel(serviceRegistry, req, nodeRef);
|
||||
|
||||
// process the template against the node content directly to the response output stream
|
||||
// assuming the repo is capable of streaming in chunks, this should allow large files
|
||||
@@ -215,22 +217,31 @@ public class TemplateContentServlet extends BaseServlet
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param session HttpSession for accessing current User
|
||||
* @param paramMap Request parameter map
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
private Object getModel(ServiceRegistry services, HttpSession session, Map paramMap, NodeRef nodeRef)
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(session));
|
||||
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(req.getSession()));
|
||||
|
||||
// put the current NodeRef in as "space" and "document"
|
||||
TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver);
|
||||
root.put("space", node);
|
||||
root.put("document", node);
|
||||
|
||||
// add URL arguments as a map called 'args' to the root of the model
|
||||
Map<String, String> args = new HashMap<String, String>(8, 1.0f);
|
||||
Enumeration names = req.getParameterNames();
|
||||
while (names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
args.put(name, req.getParameter(name));
|
||||
}
|
||||
root.put("args", args);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ package org.alfresco.web.app.servlet.command;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
@@ -60,10 +61,10 @@ public interface CommandProcessor
|
||||
* exception should be thrown to indicate this.
|
||||
*
|
||||
* @param serviceRegistry ServiceRegistry
|
||||
* @param session HttpSession
|
||||
* @param request HttpServletRequest
|
||||
* @param command Name of the command to construct and execute
|
||||
*/
|
||||
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command);
|
||||
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command);
|
||||
|
||||
/**
|
||||
* Output a simple status message to the supplied PrintWriter.
|
||||
|
@@ -39,8 +39,9 @@ public final class ExecuteScriptCommand implements Command
|
||||
public static final String PROP_SCRIPT = "script";
|
||||
public static final String PROP_DOCUMENT = "document";
|
||||
public static final String PROP_USERPERSON = "person";
|
||||
public static final String PROP_ARGS = "args";
|
||||
|
||||
private static final String[] PROPERTIES = new String[] {PROP_SCRIPT, PROP_DOCUMENT, PROP_USERPERSON};
|
||||
private static final String[] PROPERTIES = new String[] {PROP_SCRIPT, PROP_DOCUMENT, PROP_USERPERSON, PROP_ARGS};
|
||||
|
||||
|
||||
/**
|
||||
@@ -90,6 +91,9 @@ public final class ExecuteScriptCommand implements Command
|
||||
spaceRef,
|
||||
DefaultModelHelper.imageResolver);
|
||||
|
||||
// add the url arguments map
|
||||
model.put("args", properties.get(PROP_ARGS));
|
||||
|
||||
// execute the script and return the result
|
||||
return serviceRegistry.getScriptService().executeScript(scriptRef, null, model);
|
||||
}
|
||||
|
@@ -17,12 +17,14 @@
|
||||
package org.alfresco.web.app.servlet.command;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -83,16 +85,27 @@ public final class ScriptCommandProcessor implements CommandProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, java.lang.String)
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String)
|
||||
*/
|
||||
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command)
|
||||
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command)
|
||||
{
|
||||
Map<String, Object> properties = new HashMap<String, Object>(2, 1.0f);
|
||||
Map<String, Object> properties = new HashMap<String, Object>(4, 1.0f);
|
||||
|
||||
properties.put(ExecuteScriptCommand.PROP_SCRIPT, this.scriptRef);
|
||||
properties.put(ExecuteScriptCommand.PROP_DOCUMENT, this.docRef);
|
||||
User user = Application.getCurrentUser(session);
|
||||
User user = Application.getCurrentUser(request.getSession());
|
||||
properties.put(ExecuteScriptCommand.PROP_USERPERSON, user.getPerson());
|
||||
|
||||
// add URL arguments as a special Scriptable Map property called 'args'
|
||||
Map<String, String> args = new ScriptableHashMap<String, String>();
|
||||
Enumeration names = request.getParameterNames();
|
||||
while (names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
args.put(name, request.getParameter(name));
|
||||
}
|
||||
properties.put(ExecuteScriptCommand.PROP_ARGS, args);
|
||||
|
||||
Command cmd = CommandFactory.getInstance().createCommand(command);
|
||||
if (cmd == null)
|
||||
{
|
||||
|
@@ -20,6 +20,7 @@ import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -44,9 +45,9 @@ public final class WorkflowCommandProcessor extends BaseNodeCommandProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, java.lang.String)
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String)
|
||||
*/
|
||||
public void process(ServiceRegistry serviceRegistry, HttpSession session, String command)
|
||||
public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command)
|
||||
{
|
||||
Map<String, Object> properties = new HashMap<String, Object>(1, 1.0f);
|
||||
// all workflow commands use a "target" Node property as an argument
|
||||
|
Reference in New Issue
Block a user