Web Scripts:

- support url extension for specifying required response format
- update scriptUrl method to handle various forms of specifying format on url
- refactor web script request hierarchy; remove copy & paste
- add reset web script registry to web script "Test Server"

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5803 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-05-29 17:34:36 +00:00
parent a484e6737f
commit b2a11b9832
16 changed files with 497 additions and 432 deletions

View File

@@ -47,6 +47,7 @@ import org.alfresco.web.scripts.WebScriptMatch;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.alfresco.web.scripts.WebScriptRuntime;
import org.alfresco.web.scripts.WebScriptURLRequest;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -211,7 +212,7 @@ public class WebScriptPortlet implements Portlet
super(registry, transactionService);
this.req = req;
this.res = res;
this.requestUrlParts = WebScriptPortletRequest.getScriptUrlParts(requestUrl);
this.requestUrlParts = WebScriptURLRequest.splitURL(requestUrl);
}
/* (non-Javadoc)

View File

@@ -24,14 +24,10 @@
*/
package org.alfresco.web.scripts.portlet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.portlet.PortletRequest;
import org.alfresco.web.scripts.WebScriptMatch;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptURLRequest;
/**
@@ -39,61 +35,11 @@ import org.alfresco.web.scripts.WebScriptRequest;
*
* @author davidc
*/
public class WebScriptPortletRequest implements WebScriptRequest
public class WebScriptPortletRequest extends WebScriptURLRequest
{
/** Portlet Request */
private PortletRequest req;
/** Script Url components */
private String contextPath;
private String servletPath;
private String pathInfo;
private String queryString;
private Map<String, String> queryArgs;
/** Service bound to this request */
private WebScriptMatch serviceMatch;
/**
* Splits a portlet scriptUrl into its component parts
*
* @param scriptUrl url e.g. /alfresco/service/mytasks?f=1
* @return url parts [0] = context (e.g. alfresco), [1] = servlet (e.g. service), [2] = script (e.g. mytasks), [3] = args (e.g. f=1)
*/
public static String[] getScriptUrlParts(String scriptUrl)
{
String[] urlParts = new String[4];
String path;
String queryString;
int argsIndex = scriptUrl.indexOf("?");
if (argsIndex != -1)
{
path = scriptUrl.substring(0, argsIndex);
queryString = scriptUrl.substring(argsIndex + 1);
}
else
{
path = scriptUrl;
queryString = null;
}
String[] pathSegments = path.split("/");
String pathInfo = "";
for (int i = 3; i < pathSegments.length; i++)
{
pathInfo += "/" + pathSegments[i];
}
urlParts[0] = "/" + pathSegments[1]; // context path
urlParts[1] = "/" + pathSegments[2]; // servlet path
urlParts[2] = pathInfo; // path info
urlParts[3] = queryString; // query string
return urlParts;
}
/**
* Construct
@@ -102,37 +48,22 @@ public class WebScriptPortletRequest implements WebScriptRequest
* @param scriptUrl
* @param serviceMatch
*/
WebScriptPortletRequest(PortletRequest req, String scriptUrl, WebScriptMatch serviceMatch)
public WebScriptPortletRequest(PortletRequest req, String scriptUrl, WebScriptMatch serviceMatch)
{
this(req, getScriptUrlParts(scriptUrl), serviceMatch);
this(req, splitURL(scriptUrl), serviceMatch);
}
/**
* Construct
*
* @param req
* 'param scriptUrlParts
* @param scriptUrlParts
* @param serviceMatch
*/
WebScriptPortletRequest(PortletRequest req, String[] scriptUrlParts, WebScriptMatch serviceMatch)
public WebScriptPortletRequest(PortletRequest req, String[] scriptUrlParts, WebScriptMatch serviceMatch)
{
super(scriptUrlParts, serviceMatch);
this.req = req;
this.contextPath = scriptUrlParts[0];
this.servletPath = scriptUrlParts[1];
this.pathInfo = scriptUrlParts[2];
this.queryString = scriptUrlParts[3];
this.queryArgs = new HashMap<String, String>();
if (this.queryString != null)
{
String[] args = this.queryString.split("&");
for (String arg : args)
{
String[] parts = arg.split("=");
// TODO: Handle multi-value parameters
this.queryArgs.put(parts[0], parts.length == 2 ? parts[1] : "");
}
}
this.serviceMatch = serviceMatch;
}
/**
@@ -145,14 +76,6 @@ public class WebScriptPortletRequest implements WebScriptRequest
return req;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getServiceMatch()
*/
public WebScriptMatch getServiceMatch()
{
return serviceMatch;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getServerPath()
*/
@@ -161,98 +84,6 @@ public class WebScriptPortletRequest implements WebScriptRequest
return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getContextPath()
*/
public String getContextPath()
{
return contextPath;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getServiceContextPath()
*/
public String getServiceContextPath()
{
return getContextPath() + servletPath;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getServicePath()
*/
public String getServicePath()
{
return getServiceContextPath() + pathInfo;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getURL()
*/
public String getURL()
{
return getServicePath() + (queryString != null ? "?" + queryString : "");
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getQueryString()
*/
public String getQueryString()
{
return queryString;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getParameterNames()
*/
public String[] getParameterNames()
{
Set<String> keys = queryArgs.keySet();
String[] names = new String[keys.size()];
keys.toArray(names);
return names;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getParameter(java.lang.String)
*/
public String getParameter(String name)
{
return queryArgs.get(name);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getExtensionPath()
*/
public String getExtensionPath()
{
String servicePath = serviceMatch.getPath();
String extensionPath = pathInfo;
int extIdx = extensionPath.indexOf(servicePath);
if (extIdx != -1)
{
int extLength = (servicePath.endsWith("/") ? servicePath.length() : servicePath.length() + 1);
extensionPath = extensionPath.substring(extIdx + extLength);
}
return extensionPath;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#isGuest()
*/
public boolean isGuest()
{
return Boolean.valueOf(queryArgs.get("guest"));
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getFormat()
*/
public String getFormat()
{
String format = queryArgs.get("format");
return (format == null || format.length() == 0) ? "" : format;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRequest#getAgent()
*/