Web Scripts as JSR-168 portlets

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5627 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-05-04 15:11:19 +00:00
parent 1618ac1a83
commit fa8309b777
31 changed files with 1981 additions and 885 deletions

View File

@@ -0,0 +1,158 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.scripts.portlet;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.web.app.servlet.AuthenticationHelper;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.scripts.WebScriptContext;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Portlet authenticator which synchronizes with the Alfresco Web Client authentication
*
* @author davidc
*/
public class WebClientPortletAuthenticator implements WebScriptPortletAuthenticator
{
// Logger
private static final Log logger = LogFactory.getLog(WebClientPortletAuthenticator.class);
// dependencies
private AuthenticationService authenticationService;
private WebScriptContext scriptContext;
/**
* @param authenticationService
*/
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
/**
* @param scriptContext
*/
public void setScriptContext(WebScriptContext scriptContext)
{
this.scriptContext = scriptContext;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.portlet.WebScriptPortletAuthenticator#authenticate(org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication, boolean, javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
public void authenticate(RequiredAuthentication required, boolean isGuest, RenderRequest req, RenderResponse res)
{
PortletSession session = req.getPortletSession();
String portalUser = req.getRemoteUser();
if (logger.isDebugEnabled())
{
logger.debug("JSR-168 Remote user: " + portalUser);
}
if (isGuest || portalUser == null)
{
if (logger.isDebugEnabled())
logger.debug("Authenticating as Guest");
// authenticate as guest
AuthenticationUtil.setCurrentUser(AuthenticationUtil.getGuestUserName());
if (logger.isDebugEnabled())
logger.debug("Setting Web Client authentication context for guest");
createWebClientUser(session);
removeSessionInvalidated(session);
}
else
{
if (logger.isDebugEnabled())
logger.debug("Authenticating as user " + portalUser);
AuthenticationUtil.setCurrentUser(portalUser);
// determine if Web Client context needs to be updated
User user = getWebClientUser(session);
if (user == null || !portalUser.equals(user.getUserName()))
{
if (logger.isDebugEnabled())
logger.debug("Setting Web Client authentication context for user " + portalUser);
createWebClientUser(session);
removeSessionInvalidated(session);
}
}
}
/**
* Helper. Remove Web Client session invalidated flag
*
* @param session
*/
private void removeSessionInvalidated(PortletSession session)
{
session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED, PortletSession.APPLICATION_SCOPE);
}
/**
* Helper. Create Web Client session user
*
* @param session
*/
private void createWebClientUser(PortletSession session)
{
NodeRef personRef = scriptContext.getPerson();
User user = new User(authenticationService.getCurrentUserName(), authenticationService.getCurrentTicket(), personRef);
NodeRef homeRef = scriptContext.getUserHome(personRef);
if (homeRef != null)
{
user.setHomeSpaceId(homeRef.getId());
}
session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user, PortletSession.APPLICATION_SCOPE);
}
/**
* Helper. Get Web Client session user
*
* @param session
* @return
*/
private User getWebClientUser(PortletSession session)
{
return (User)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER, PortletSession.APPLICATION_SCOPE);
}
}

View File

@@ -0,0 +1,287 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.scripts.portlet;
import java.io.IOException;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletSecurityException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.WindowState;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.scripts.DeclarativeWebScriptRegistry;
import org.alfresco.web.scripts.WebScript;
import org.alfresco.web.scripts.WebScriptDescription;
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.WebScriptDescription.RequiredAuthentication;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
/**
* Generic JSR-168 Portlet for hosting an Alfresco Web Script as a Portlet.
*
* Accepts the following init-config:
*
* scriptUrl => the url of the web script to host e.g. /alfresco/service/mytasks
*
* @author davidc
*/
public class WebScriptPortlet implements Portlet
{
private static Log logger = LogFactory.getLog(WebScriptPortlet.class);
// Portlet initialisation
protected String initScriptUrl = null;
// Component Dependencies
protected DeclarativeWebScriptRegistry registry;
protected TransactionService transactionService;
protected WebScriptPortletAuthenticator authenticator;
/* (non-Javadoc)
* @see javax.portlet.Portlet#init(javax.portlet.PortletConfig)
*/
public void init(PortletConfig config) throws PortletException
{
initScriptUrl = config.getInitParameter("scriptUrl");
PortletContext portletCtx = config.getPortletContext();
WebApplicationContext ctx = (WebApplicationContext)portletCtx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
registry = (DeclarativeWebScriptRegistry)ctx.getBean("webscripts.registry");
transactionService = (TransactionService)ctx.getBean("transactionComponent");
authenticator = (WebScriptPortletAuthenticator)ctx.getBean("webscripts.authenticator.jsr168");
}
/* (non-Javadoc)
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
*/
public void processAction(ActionRequest req, ActionResponse res) throws PortletException, PortletSecurityException, IOException
{
Map<String, String[]> params = req.getParameterMap();
for (Map.Entry<String, String[]> param : params.entrySet())
{
String name = param.getKey();
if (name.equals("scriptUrl") || name.startsWith("arg."))
{
res.setRenderParameter(name, param.getValue());
}
}
}
/* (non-Javadoc)
* @see javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
public void render(RenderRequest req, RenderResponse res) throws PortletException, PortletSecurityException, IOException
{
PortletMode portletMode = req.getPortletMode();
if (PortletMode.VIEW.equals(portletMode))
{
doView(req, res);
}
// else if (PortletMode.HELP.equals(portletMode))
// {
// doHelp(request, response);
// }
// else if (PortletMode.EDIT.equals(portletMode))
// {
// doEdit(request, response);
// }
}
/* (non-Javadoc)
* @see javax.portlet.Portlet#destroy()
*/
public void destroy()
{
}
/**
* Render Web Script view
*
* @param req
* @param res
* @throws PortletException
* @throws PortletSecurityException
* @throws IOException
*/
protected void doView(RenderRequest req, RenderResponse res) throws PortletException, PortletSecurityException, IOException
{
//
// Establish Web Script URL
//
String scriptUrl = req.getParameter("scriptUrl");
if (scriptUrl != null)
{
// build web script url from render request
String scriptUrlArgs = "";
Map<String, String[]> params = req.getParameterMap();
for (Map.Entry<String, String[]> param : params.entrySet())
{
String name = param.getKey();
if (name.startsWith("arg."))
{
String argName = name.substring("arg.".length());
for (String argValue : param.getValue())
{
scriptUrlArgs += (scriptUrlArgs.length() == 0) ? "" : "&";
scriptUrlArgs += argName + "=" + argValue;
}
}
}
scriptUrl += "?" + scriptUrlArgs;
}
else
{
// retrieve initial scriptUrl as configured by Portlet
scriptUrl = initScriptUrl;
if (scriptUrl == null)
{
throw new PortletException("Initial Web script URL has not been specified.");
}
}
//
// Execute Web Script
//
if (logger.isDebugEnabled())
logger.debug("Processing portal render request " + req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + "/" + req.getContextPath() + " (scriptUrl=" + scriptUrl + ")");
WebScriptRuntime runtime = new WebScriptPortalRuntime(req, res, scriptUrl);
runtime.executeScript();
}
/**
* JSR-168 Web Script Runtime
*
* @author davidc
*/
private class WebScriptPortalRuntime extends WebScriptRuntime
{
private RenderRequest req;
private RenderResponse res;
private String[] requestUrlParts;
/**
* Construct
* @param req
* @param res
* @param requestUrl
*/
public WebScriptPortalRuntime(RenderRequest req, RenderResponse res, String requestUrl)
{
super(registry, transactionService);
this.req = req;
this.res = res;
this.requestUrlParts = WebScriptPortletRequest.getScriptUrlParts(requestUrl);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#getScriptMethod()
*/
@Override
protected String getScriptMethod()
{
return "get";
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#getScriptUrl()
*/
@Override
protected String getScriptUrl()
{
return requestUrlParts[2];
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#createRequest(org.alfresco.web.scripts.WebScriptMatch)
*/
@Override
protected WebScriptRequest createRequest(WebScriptMatch match)
{
return new WebScriptPortletRequest(req, requestUrlParts, match);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#createResponse()
*/
@Override
protected WebScriptResponse createResponse()
{
return new WebScriptPortletResponse(res);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#authenticate(org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication, boolean)
*/
@Override
protected void authenticate(RequiredAuthentication required, boolean isGuest)
{
authenticator.authenticate(required, isGuest, req, res);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#preExecute(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected boolean preExecute(WebScriptRequest scriptReq, WebScriptResponse scriptRes)
{
// Set Portlet title based on Web Script
WebScript script = scriptReq.getServiceMatch().getWebScript();
WebScriptDescription desc = script.getDescription();
res.setTitle(desc.getShortName());
// Note: Do not render script if portlet window is minimized
return !WindowState.MINIMIZED.equals(req.getWindowState());
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptRuntime#postExecute(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected void postExecute(WebScriptRequest scriptReq, WebScriptResponse scriptRes)
{
}
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.scripts.portlet;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
/**
* Web Script Authenticator for the JSR-168 environment
*
* @author davidc
*/
public interface WebScriptPortletAuthenticator
{
/**
* Authenticate Web Script execution
*
* @param required required level of authentication
* @param isGuest is Guest accessing the web script
* @param req portlet render request
* @param res portlet render response
*/
public void authenticate(RequiredAuthentication required, boolean isGuest, RenderRequest req, RenderResponse res);
}

View File

@@ -0,0 +1,265 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
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;
/**
* JSR-168 Web Script Request
*
* @author davidc
*/
public class WebScriptPortletRequest implements WebScriptRequest
{
/** 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
*
* @param req
* @param scriptUrl
* @param serviceMatch
*/
WebScriptPortletRequest(PortletRequest req, String scriptUrl, WebScriptMatch serviceMatch)
{
this(req, getScriptUrlParts(scriptUrl), serviceMatch);
}
/**
* Construct
*
* @param req
* 'param scriptUrlParts
* @param serviceMatch
*/
WebScriptPortletRequest(PortletRequest req, String[] scriptUrlParts, WebScriptMatch 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;
}
/**
* Gets the Portlet Request
*
* @return Portlet Request
*/
public PortletRequest getPortletRequest()
{
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()
*/
public String getServerPath()
{
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()
*/
public String getAgent()
{
// NOTE: rely on default agent mappings
return null;
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.scripts.portlet;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import javax.portlet.PortletURL;
import javax.portlet.RenderResponse;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
/**
* JSR-168 Web Script Response
*
* @author davidc
*/
public class WebScriptPortletResponse implements WebScriptResponse
{
/** Portlet response */
private RenderResponse res;
/**
* Construct
*
* @param res
*/
WebScriptPortletResponse(RenderResponse res)
{
this.res = res;
}
/**
* Gets the Portlet Render Response
*
* @return render response
*/
public RenderResponse getRenderResponse()
{
return res;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptResponse#setContentType(java.lang.String)
*/
public void setContentType(String contentType)
{
res.setContentType(contentType);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptResponse#getWriter()
*/
public Writer getWriter() throws IOException
{
return res.getWriter();
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptResponse#getOutputStream()
*/
public OutputStream getOutputStream() throws IOException
{
return res.getPortletOutputStream();
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptResponse#encodeScriptUrl(java.lang.String)
*/
public String encodeScriptUrl(String url)
{
WebScriptRequest req = new WebScriptPortletRequest(null, url, null);
PortletURL portletUrl = res.createActionURL();
portletUrl.setParameter("scriptUrl", req.getServicePath());
String[] parameterNames = req.getParameterNames();
for (String parameterName : parameterNames)
{
portletUrl.setParameter("arg." + parameterName, req.getParameter(parameterName));
}
return portletUrl.toString();
}
}