mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -24,27 +24,16 @@
|
||||
*/
|
||||
package org.alfresco.web.scripts.jsf;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.web.scripts.WebScriptMatch;
|
||||
import org.alfresco.web.scripts.WebScriptRequest;
|
||||
import org.alfresco.web.scripts.portlet.WebScriptPortletRequest;
|
||||
import org.alfresco.web.scripts.WebScriptURLRequest;
|
||||
|
||||
/**
|
||||
* Implementation of a WebScript Request for the JSF environment.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class WebScriptJSFRequest implements WebScriptRequest
|
||||
public class WebScriptJSFRequest extends WebScriptURLRequest
|
||||
{
|
||||
private WebScriptMatch match;
|
||||
private FacesContext fc;
|
||||
private String[] scriptUrlParts;
|
||||
private Map<String, String> args = new HashMap<String, String>(4, 1.0f);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -52,47 +41,19 @@ public class WebScriptJSFRequest implements WebScriptRequest
|
||||
* @param fc FacesContext
|
||||
* @param match WebScriptMatch that matched this webscript
|
||||
* @param scriptUrl The script URL this request is for
|
||||
*/
|
||||
WebScriptJSFRequest(FacesContext fc, WebScriptMatch match, String scriptUrl)
|
||||
*/
|
||||
public WebScriptJSFRequest(String scriptUrl, WebScriptMatch match)
|
||||
{
|
||||
this.fc = fc;
|
||||
this.match = match;
|
||||
this.scriptUrlParts = WebScriptPortletRequest.getScriptUrlParts(scriptUrl);
|
||||
if (this.scriptUrlParts[3] != null)
|
||||
{
|
||||
String[] parts = this.scriptUrlParts[3].split("&");
|
||||
for (String argument : parts)
|
||||
{
|
||||
int sepIndex = argument.indexOf('=');
|
||||
if (sepIndex != -1)
|
||||
{
|
||||
String value = "";
|
||||
if (argument.length() > sepIndex + 1)
|
||||
{
|
||||
value = argument.substring(sepIndex + 1);
|
||||
}
|
||||
this.args.put(argument.substring(0, sepIndex), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
this(splitURL(scriptUrl), match);
|
||||
}
|
||||
|
||||
public WebScriptJSFRequest(String[] scriptUrlParts, WebScriptMatch match)
|
||||
{
|
||||
super(scriptUrlParts, match);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the matching API Service for this request
|
||||
*
|
||||
* @return the service match
|
||||
*/
|
||||
public WebScriptMatch getServiceMatch()
|
||||
{
|
||||
return this.match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server portion of the request
|
||||
*
|
||||
* e.g. scheme://host:port
|
||||
*
|
||||
* @return server path
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getServerPath()
|
||||
*/
|
||||
public String getServerPath()
|
||||
{
|
||||
@@ -100,126 +61,13 @@ public class WebScriptJSFRequest implements WebScriptRequest
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getContextPath()
|
||||
*/
|
||||
public String getContextPath()
|
||||
{
|
||||
return fc.getExternalContext().getRequestContextPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Alfresco Web Script Context Path
|
||||
*
|
||||
* @return service url e.g. /alfresco/service
|
||||
*/
|
||||
public String getServiceContextPath()
|
||||
{
|
||||
return fc.getExternalContext().getRequestContextPath() + scriptUrlParts[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Alfresco Service Path
|
||||
*
|
||||
* @return service url e.g. /alfresco/service/search/keyword
|
||||
*/
|
||||
public String getServicePath()
|
||||
{
|
||||
return getServiceContextPath() + scriptUrlParts[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full request URL
|
||||
*
|
||||
* @return request url e.g. /alfresco/service/search/keyword?q=term
|
||||
*/
|
||||
public String getURL()
|
||||
{
|
||||
return getServicePath() + (scriptUrlParts[3] != null ? "?" + scriptUrlParts[3] : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getQueryString()
|
||||
*/
|
||||
public String getQueryString()
|
||||
{
|
||||
return scriptUrlParts[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getParameterNames()
|
||||
*/
|
||||
public String[] getParameterNames()
|
||||
{
|
||||
Set<String> keys = this.args.keySet();
|
||||
String[] names = new String[keys.size()];
|
||||
keys.toArray(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getParameter(java.lang.String)
|
||||
*/
|
||||
public String getParameter(String name)
|
||||
{
|
||||
return this.args.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path extension beyond the path registered for this service
|
||||
*
|
||||
* e.g.
|
||||
* a) service registered path = /search/engine
|
||||
* b) request path = /search/engine/external
|
||||
*
|
||||
* => /external
|
||||
*
|
||||
* @return extension path
|
||||
*/
|
||||
public String getExtensionPath()
|
||||
{
|
||||
String servicePath = this.scriptUrlParts[2];
|
||||
if (servicePath.indexOf('/') != -1)
|
||||
{
|
||||
return servicePath.substring(servicePath.indexOf('/'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if Guest User?
|
||||
*
|
||||
* @return true => guest user
|
||||
*/
|
||||
public boolean isGuest()
|
||||
{
|
||||
return Boolean.valueOf(getParameter("guest"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Requested Format
|
||||
*
|
||||
* @return content type requested
|
||||
*/
|
||||
public String getFormat()
|
||||
{
|
||||
String format = getParameter("format");
|
||||
return (format == null || format.length() == 0) ? "" : format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User Agent
|
||||
*
|
||||
* TODO: Expand on known agents
|
||||
*
|
||||
* @return MSIE / Firefox
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#getAgent()
|
||||
*/
|
||||
public String getAgent()
|
||||
{
|
||||
// NOTE: unknown in the JSF environment
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user