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:
Kevin Roast
2006-05-17 10:02:07 +00:00
parent e8457fe8f4
commit 3e36796044
6 changed files with 55 additions and 18 deletions

View File

@@ -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;
}