mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Humongous merge. It is incomplete, however; faces-config-navigation.xml and ClientConfigElement
were both beyond me, and are just the raw conflict merge data. If Kev can't figure out how they should go together by tomorrow AM (for me) I'll dig back in. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
/**
|
||||
* Base class for the template content servlets. Provides common
|
||||
* processing for the request.
|
||||
*
|
||||
* @see org.alfresco.web.app.servlet.TemplateContentServlet
|
||||
* @see org.alfresco.web.app.servlet.GuestTemplateContentServlet
|
||||
*
|
||||
* @author Kevin Roast
|
||||
* @author gavinc
|
||||
*/
|
||||
public abstract class BaseTemplateContentServlet extends BaseServlet
|
||||
{
|
||||
private static final String MIMETYPE_HTML = "text/html";
|
||||
|
||||
private static final long serialVersionUID = -4123407921997235977L;
|
||||
|
||||
private static final String ARG_MIMETYPE = "mimetype";
|
||||
private static final String ARG_TEMPLATE_PATH = "templatePath";
|
||||
private static final String ARG_CONTEXT_PATH = "contextPath";
|
||||
|
||||
/**
|
||||
* Gets the logger to use for this request.
|
||||
* <p>
|
||||
* This will show all debug entries from this class as though they
|
||||
* came from the subclass.
|
||||
*
|
||||
* @return The logger
|
||||
*/
|
||||
protected abstract Log getLogger();
|
||||
|
||||
/**
|
||||
* Builds the FreeMarker model
|
||||
*
|
||||
* @param services Service Registry instance
|
||||
* @param req Http request
|
||||
* @param templateRef The node ref of the template to process
|
||||
* @return The FreeMarker model
|
||||
*/
|
||||
protected abstract Map<String, Object> buildModel(ServiceRegistry services,
|
||||
HttpServletRequest req, NodeRef templateRef);
|
||||
|
||||
/**
|
||||
* Processes the template request using the current context i.e. no
|
||||
* authentication checks are made, it is presumed they have already
|
||||
* been done.
|
||||
*
|
||||
* @param req The HTTP request
|
||||
* @param res The HTTP response
|
||||
* @param redirectToLogin Flag to determine whether to redirect to the login
|
||||
* page if the user does not have the correct permissions
|
||||
*/
|
||||
protected void processTemplateRequest(HttpServletRequest req, HttpServletResponse res,
|
||||
boolean redirectToLogin) throws ServletException, IOException
|
||||
{
|
||||
Log logger = getLogger();
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Processing URL: " + uri +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
uri = uri.substring(req.getContextPath().length());
|
||||
StringTokenizer t = new StringTokenizer(uri, "/");
|
||||
int tokenCount = t.countTokens();
|
||||
|
||||
t.nextToken(); // skip servlet name
|
||||
|
||||
NodeRef nodeRef = null;
|
||||
NodeRef templateRef = null;
|
||||
|
||||
String contentPath = req.getParameter(ARG_CONTEXT_PATH);
|
||||
if (contentPath != null && contentPath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), contentPath);
|
||||
|
||||
nodeRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount > 3)
|
||||
{
|
||||
// get NodeRef to the content from the URL elements
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
nodeRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// get NodeRef to the template if supplied
|
||||
String templatePath = req.getParameter(ARG_TEMPLATE_PATH);
|
||||
if (templatePath != null && templatePath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), templatePath);
|
||||
|
||||
templateRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount >= 7)
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
templateRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// if no context is specified, use the template itself
|
||||
// TODO: should this default to something else?
|
||||
if (nodeRef == null && templateRef != null)
|
||||
{
|
||||
nodeRef = templateRef;
|
||||
}
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
throw new TemplateException("Not enough elements supplied in URL or no 'path' argument specified.");
|
||||
}
|
||||
|
||||
// get the services we need to retrieve the content
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
TemplateService templateService = serviceRegistry.getTemplateService();
|
||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||
|
||||
// check that the user has at least READ access on any nodes - else redirect to the login page
|
||||
if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED ||
|
||||
(templateRef != null && permissionService.hasPermission(templateRef, PermissionService.READ) == AccessStatus.DENIED))
|
||||
{
|
||||
if (redirectToLogin)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Redirecting to login page...");
|
||||
|
||||
redirectToLoginPage(req, res, getServletContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Returning 403 Forbidden error...");
|
||||
|
||||
res.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String mimetype = MIMETYPE_HTML;
|
||||
if (req.getParameter(ARG_MIMETYPE) != null)
|
||||
{
|
||||
mimetype = req.getParameter(ARG_MIMETYPE);
|
||||
}
|
||||
res.setContentType(mimetype);
|
||||
|
||||
try
|
||||
{
|
||||
UserTransaction txn = null;
|
||||
try
|
||||
{
|
||||
txn = serviceRegistry.getTransactionService().getUserTransaction(true);
|
||||
txn.begin();
|
||||
|
||||
// if template not supplied, then use the default against the node
|
||||
if (templateRef == null)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPLATABLE))
|
||||
{
|
||||
templateRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_TEMPLATE);
|
||||
}
|
||||
if (templateRef == null)
|
||||
{
|
||||
throw new TemplateException("Template reference not set against node or not supplied in URL.");
|
||||
}
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req, templateRef, 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
|
||||
// to be streamed directly to the browser response stream.
|
||||
try
|
||||
{
|
||||
templateService.processTemplate(
|
||||
null,
|
||||
templateRef.toString(),
|
||||
model,
|
||||
res.getWriter());
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.getMessage().contains("ClientAbortException"))
|
||||
{
|
||||
// the client cut the connection - our mission was accomplished apart from a little error message
|
||||
logger.error("Client aborted stream read:\n node: " + nodeRef + "\n template: " + templateRef);
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable txnErr)
|
||||
{
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
throw txnErr;
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Error during template servlet processing: " + err.getMessage(), err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the model that to process the template against.
|
||||
* <p>
|
||||
* The model includes the usual template root objects such as 'companyhome', 'userhome',
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param templateRef NodeRef of the template itself
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map<String, Object> root = buildModel(services, req, templateRef);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/** Template Image resolver helper */
|
||||
private TemplateImageResolver imageResolver = new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(getServletContext(), filename, small);
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.web.bean.repository.User;
|
||||
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
/**
|
||||
* Servlet responsible for streaming content from a template processed against a node directly
|
||||
* to the response stream.
|
||||
* <p>
|
||||
* The URL to the servlet should be generated thus:
|
||||
* <pre>/alfresco/template/workspace/SpacesStore/0000-0000-0000-0000</pre>
|
||||
* or
|
||||
* <pre>/alfresco/template/workspace/SpacesStore/0000-0000-0000-0000/workspace/SpacesStore/0000-0000-0000-0000</pre>
|
||||
* or
|
||||
* <pre>/alfresco/template?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/doc_info.ftl&contextPath=/Company%20Home/mydoc.txt</pre>
|
||||
* <p>
|
||||
* The store protocol, followed by the store ID, followed by the content Node Id used to
|
||||
* identify the node to execute the default template for. The second set of elements encode
|
||||
* the store and node Id of the template to used if a default is not set or not requested. Instead
|
||||
* of using NodeRef references to the template and context, path arguments can be used. The URL args
|
||||
* of 'templatePath' and 'contextPath' can be used instead to specify name based encoded Paths to the
|
||||
* template and its context.
|
||||
* <p>
|
||||
* The URL may be followed by a 'mimetype' argument specifying the mimetype to return the result as
|
||||
* on the stream. Otherwise it is assumed that HTML is the default response mimetype.
|
||||
* <p>
|
||||
* Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication:
|
||||
* ?ticket=1234567890
|
||||
* <p>
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL. If the
|
||||
* guest=true parameter is used the current session will be logged out and the guest user logged in.
|
||||
* Therefore upon completion of this request the current user will be "guest".
|
||||
* <p>
|
||||
* This servlet only accesses content available to the guest user. If the guest user does not
|
||||
* have access to the requested a 401 Forbidden response is returned to the caller.
|
||||
* <p>
|
||||
* This servlet does not effect the current session, therefore if guest access is required to a
|
||||
* resource this servlet can be used without logging out the current user.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class GuestTemplateContentServlet extends BaseTemplateContentServlet
|
||||
{
|
||||
private static final long serialVersionUID = -2510767849932627519L;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GuestTemplateContentServlet.class);
|
||||
|
||||
private static final String DEFAULT_URL = "/guestTemplate/{0}/{1}/{2}";
|
||||
private static final String TEMPLATE_URL = "/guestTemplate/{0}/{1}/{2}/{3}/{4}/{5}";
|
||||
|
||||
@Override
|
||||
protected Log getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req,
|
||||
NodeRef templateRef)
|
||||
{
|
||||
// setup the guest user to pass to the build model helper method
|
||||
AuthenticationService auth = (AuthenticationService)services.getAuthenticationService();
|
||||
PersonService personService = (PersonService)services.getPersonService();
|
||||
NodeService nodeService = (NodeService)services.getNodeService();
|
||||
|
||||
NodeRef guestRef = personService.getPerson(PermissionService.GUEST_AUTHORITY);
|
||||
User guestUser = new User(PermissionService.GUEST_AUTHORITY, auth.getCurrentTicket(), guestRef);
|
||||
NodeRef guestHomeRef = (NodeRef)nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
|
||||
if (nodeService.exists(guestHomeRef) == false)
|
||||
{
|
||||
throw new InvalidNodeRefException(guestHomeRef);
|
||||
}
|
||||
guestUser.setHomeSpaceId(guestHomeRef.getId());
|
||||
|
||||
// build the default model
|
||||
return DefaultModelHelper.buildDefaultModel(services, guestUser, templateRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Setting up guest access to URL: " + req.getRequestURI() +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
TemplateContentWork tcw = new TemplateContentWork(req, res);
|
||||
AuthenticationUtil.runAs(tcw, PermissionService.GUEST_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to generate a URL to process a template against a node.
|
||||
* <p>
|
||||
* The result of the template is supplied returned as the response.
|
||||
*
|
||||
* @param nodeRef NodeRef of the content node to generate URL for (cannot be null)
|
||||
* @param templateRef NodeRef of the template to process against, or null to use default
|
||||
*
|
||||
* @return URL to process the template
|
||||
*/
|
||||
public final static String generateURL(NodeRef nodeRef, NodeRef templateRef)
|
||||
{
|
||||
if (templateRef == null)
|
||||
{
|
||||
return MessageFormat.format(DEFAULT_URL, new Object[] {
|
||||
nodeRef.getStoreRef().getProtocol(),
|
||||
nodeRef.getStoreRef().getIdentifier(),
|
||||
nodeRef.getId() } );
|
||||
}
|
||||
else
|
||||
{
|
||||
return MessageFormat.format(TEMPLATE_URL, new Object[] {
|
||||
nodeRef.getStoreRef().getProtocol(),
|
||||
nodeRef.getStoreRef().getIdentifier(),
|
||||
nodeRef.getId(),
|
||||
templateRef.getStoreRef().getProtocol(),
|
||||
templateRef.getStoreRef().getIdentifier(),
|
||||
templateRef.getId()} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to wrap the call to processTemplateRequest.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TemplateContentWork implements RunAsWork<Object>
|
||||
{
|
||||
private HttpServletRequest req = null;
|
||||
private HttpServletResponse res = null;
|
||||
|
||||
public TemplateContentWork(HttpServletRequest req, HttpServletResponse res)
|
||||
{
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
processTemplateRequest(this.req, this.res, false);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// TODO: DC: Tidy up
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
public class JBPMProcessImageServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
ProcessDefinition processDefinition = jbpmContext.getGraphSession().loadProcessDefinition(processDefinitionId);
|
||||
byte[] bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
|
||||
OutputStream out = response.getOutputStream();
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
|
||||
// leave this in. it is in case we want to set the mime type later.
|
||||
// get the mime type
|
||||
// String contentType = URLConnection.getFileNameMap().getContentTypeFor( fileName );
|
||||
// set the content type (=mime type)
|
||||
// response.setContentType( contentType );
|
||||
}
|
||||
}
|
@@ -17,32 +17,16 @@
|
||||
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;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -71,24 +55,37 @@ import org.apache.commons.logging.LogFactory;
|
||||
* Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication:
|
||||
* ?ticket=1234567890
|
||||
* <p>
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL.
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL. If the
|
||||
* guest=true parameter is used the current session will be logged out and the guest user logged in.
|
||||
* Therefore upon completion of this request the current user will be "guest".
|
||||
* <p>
|
||||
* If the user attempting the request is not authorised to access the requested node the login page
|
||||
* will be redirected to.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class TemplateContentServlet extends BaseServlet
|
||||
{
|
||||
private static final String MIMETYPE_HTML = "text/html";
|
||||
public class TemplateContentServlet extends BaseTemplateContentServlet
|
||||
{
|
||||
private static final long serialVersionUID = -2510767849932627519L;
|
||||
|
||||
private static final long serialVersionUID = -4123407921997235977L;
|
||||
|
||||
private static Log logger = LogFactory.getLog(TemplateContentServlet.class);
|
||||
private static final Log logger = LogFactory.getLog(TemplateContentServlet.class);
|
||||
|
||||
private static final String DEFAULT_URL = "/template/{0}/{1}/{2}";
|
||||
private static final String TEMPLATE_URL = "/template/{0}/{1}/{2}/{3}/{4}/{5}";
|
||||
|
||||
private static final String ARG_MIMETYPE = "mimetype";
|
||||
private static final String ARG_TEMPLATE_PATH = "templatePath";
|
||||
private static final String ARG_CONTEXT_PATH = "contextPath";
|
||||
@Override
|
||||
protected Log getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req,
|
||||
NodeRef templateRef)
|
||||
{
|
||||
return DefaultModelHelper.buildDefaultModel(services,
|
||||
Application.getCurrentUser(req.getSession()), templateRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
@@ -96,12 +93,10 @@ public class TemplateContentServlet extends BaseServlet
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Processing URL: " + uri +
|
||||
logger.debug("Authenticating request to URL: " + req.getRequestURI() +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
@@ -111,189 +106,9 @@ public class TemplateContentServlet extends BaseServlet
|
||||
return;
|
||||
}
|
||||
|
||||
uri = uri.substring(req.getContextPath().length());
|
||||
StringTokenizer t = new StringTokenizer(uri, "/");
|
||||
int tokenCount = t.countTokens();
|
||||
|
||||
t.nextToken(); // skip servlet name
|
||||
|
||||
NodeRef nodeRef = null;
|
||||
NodeRef templateRef = null;
|
||||
|
||||
String contentPath = req.getParameter(ARG_CONTEXT_PATH);
|
||||
if (contentPath != null && contentPath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), contentPath);
|
||||
|
||||
nodeRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount > 3)
|
||||
{
|
||||
// get NodeRef to the content from the URL elements
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
nodeRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// get NodeRef to the template if supplied
|
||||
String templatePath = req.getParameter(ARG_TEMPLATE_PATH);
|
||||
if (templatePath != null && templatePath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), templatePath);
|
||||
|
||||
templateRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount >= 7)
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
templateRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// if no context is specified, use the template itself
|
||||
// TODO: should this default to something else?
|
||||
if (nodeRef == null && templateRef != null)
|
||||
{
|
||||
nodeRef = templateRef;
|
||||
}
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
throw new TemplateException("Not enough elements supplied in URL or no 'path' argument specified.");
|
||||
}
|
||||
|
||||
// get the services we need to retrieve the content
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
TemplateService templateService = serviceRegistry.getTemplateService();
|
||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||
|
||||
// check that the user has at least READ access on any nodes - else redirect to the login page
|
||||
if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED ||
|
||||
(templateRef != null && permissionService.hasPermission(templateRef, PermissionService.READ) == AccessStatus.DENIED))
|
||||
{
|
||||
redirectToLoginPage(req, res, getServletContext());
|
||||
return;
|
||||
}
|
||||
|
||||
String mimetype = MIMETYPE_HTML;
|
||||
if (req.getParameter(ARG_MIMETYPE) != null)
|
||||
{
|
||||
mimetype = req.getParameter(ARG_MIMETYPE);
|
||||
}
|
||||
res.setContentType(mimetype);
|
||||
|
||||
try
|
||||
{
|
||||
UserTransaction txn = null;
|
||||
try
|
||||
{
|
||||
txn = serviceRegistry.getTransactionService().getUserTransaction(true);
|
||||
txn.begin();
|
||||
|
||||
// if template not supplied, then use the default against the node
|
||||
if (templateRef == null)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPLATABLE))
|
||||
{
|
||||
templateRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_TEMPLATE);
|
||||
}
|
||||
if (templateRef == null)
|
||||
{
|
||||
throw new TemplateException("Template reference not set against node or not supplied in URL.");
|
||||
}
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req, templateRef, 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
|
||||
// to be streamed directly to the browser response stream.
|
||||
try
|
||||
{
|
||||
templateService.processTemplate(
|
||||
null,
|
||||
templateRef.toString(),
|
||||
model,
|
||||
res.getWriter());
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.getMessage().contains("ClientAbortException"))
|
||||
{
|
||||
// the client cut the connection - our mission was accomplished apart from a little error message
|
||||
logger.error("Client aborted stream read:\n node: " + nodeRef + "\n template: " + templateRef);
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable txnErr)
|
||||
{
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
throw txnErr;
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Error during template servlet processing: " + err.getMessage(), err);
|
||||
}
|
||||
processTemplateRequest(req, res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the model that to process the template against.
|
||||
* <p>
|
||||
* The model includes the usual template root objects such as 'companyhome', 'userhome',
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param templateRef NodeRef of the template itself
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map root = DefaultModelHelper.buildDefaultModel(
|
||||
services, Application.getCurrentUser(req.getSession()), templateRef);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/** Template Image resolver helper */
|
||||
private TemplateImageResolver imageResolver = new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(getServletContext(), filename, small);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to generate a URL to process a template against a node.
|
||||
* <p>
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.bean.WorkflowUtil;
|
||||
import org.alfresco.web.bean.workflow.WorkflowUtil;
|
||||
|
||||
/**
|
||||
* Approve Workflow command implementation
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.bean.WorkflowUtil;
|
||||
import org.alfresco.web.bean.workflow.WorkflowUtil;
|
||||
|
||||
/**
|
||||
* Reject Workflow command implementation
|
||||
|
Reference in New Issue
Block a user