org.alfresco.web.app.servlet
Class DownloadContentServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.alfresco.web.app.servlet.BaseServlet
              extended by org.alfresco.web.app.servlet.BaseDownloadContentServlet
                  extended by org.alfresco.web.app.servlet.DownloadContentServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class DownloadContentServlet
extends BaseDownloadContentServlet

Servlet responsible for streaming node content from the repo directly to the response stream. The appropriate mimetype is calculated based on filename extension.

The URL to the servlet should be generated thus:

/alfresco/download/attach/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf
or
/alfresco/download/direct/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf
or
/alfresco/download/[direct|attach]?path=/Company%20Home/MyFolder/myfile.pdf
The protocol, followed by either the store and Id (NodeRef) or instead specify a name based encoded Path to the content, note that the filename element is used for mimetype lookup and as the returning filename for the response stream.

The 'attach' or 'direct' element is used to indicate whether to display the stream directly in the browser or download it as a file attachment.

By default, the download assumes that the content is on the content property.
To retrieve the content of a specific model property, use a 'property' arg, providing the workspace, node ID AND the qualified name of the property.

Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication: ?ticket=1234567890

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".

If the user attempting the request is not authorised to access the requested node the login page will be redirected to.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.alfresco.web.app.servlet.BaseServlet
BaseServlet.PathRefInfo
 
Field Summary
 
Fields inherited from class org.alfresco.web.app.servlet.BaseDownloadContentServlet
ARG_PATH, ARG_PROPERTY, MIMETYPE_OCTET_STREAM, MSG_ERROR_CONTENT_MISSING, MSG_ERROR_NOT_FOUND, URL_ATTACH, URL_ATTACH_LONG, URL_DIRECT, URL_DIRECT_LONG
 
Fields inherited from class org.alfresco.web.app.servlet.BaseServlet
FACES_SERVLET, KEY_ROOT_PATH, KEY_STORE
 
Constructor Summary
DownloadContentServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
protected  void doHead(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
static java.lang.String generateBrowserURL(org.alfresco.service.cmr.repository.NodeRef ref, java.lang.String name)
          Helper to generate a URL to a content node for downloading content from the server.
static java.lang.String generateDownloadURL(org.alfresco.service.cmr.repository.NodeRef ref, java.lang.String name)
          Helper to generate a URL to a content node for downloading content from the server.
protected  org.apache.commons.logging.Log getLogger()
          Gets the logger to use for this request.
 
Methods inherited from class org.alfresco.web.app.servlet.BaseDownloadContentServlet
generateUrl, processDownloadRequest
 
Methods inherited from class org.alfresco.web.app.servlet.BaseServlet
checkAccess, getServiceRegistry, redirectToLoginPage, resolveNamePath, resolveWebDAVPath, resolveWebDAVPath, resolveWebDAVPath, resolveWebDAVPath, servletAuthenticate, servletAuthenticate, setNoCacheHeaders, validRedirectJSP
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadContentServlet

public DownloadContentServlet()
Method Detail

getLogger

protected org.apache.commons.logging.Log getLogger()
Description copied from class: BaseDownloadContentServlet
Gets the logger to use for this request.

This will show all debug entries from this class as though they came from the subclass.

Specified by:
getLogger in class BaseDownloadContentServlet
Returns:
The logger

doHead

protected void doHead(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
               throws javax.servlet.ServletException,
                      java.io.IOException
Overrides:
doHead in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

doGet

protected void doGet(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse res)
              throws javax.servlet.ServletException,
                     java.io.IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException
See Also:
HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

generateDownloadURL

public static final java.lang.String generateDownloadURL(org.alfresco.service.cmr.repository.NodeRef ref,
                                                         java.lang.String name)
Helper to generate a URL to a content node for downloading content from the server. The content is supplied as an HTTP1.1 attachment to the response. This generally means a browser should prompt the user to save the content to specified location.

Parameters:
ref - NodeRef of the content node to generate URL for (cannot be null)
name - File name to return in the URL (cannot be null)
Returns:
URL to download the content from the specified node

generateBrowserURL

public static final java.lang.String generateBrowserURL(org.alfresco.service.cmr.repository.NodeRef ref,
                                                        java.lang.String name)
Helper to generate a URL to a content node for downloading content from the server. The content is supplied directly in the reponse. This generally means a browser will attempt to open the content directly if possible, else it will prompt to save the file.

Parameters:
ref - NodeRef of the content node to generate URL for (cannot be null)
name - File name to return in the URL (cannot be null)
Returns:
URL to download the content from the specified node


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.