public class BinariesServlet
extends javax.servlet.http.HttpServlet
<init-param> <param-name>contentDispositionContentTypes</param-name> <param-value> application/pdf, application/rtf, application/excel </param-value> </init-param>In the above init param configuration, you can also set glob style configurations such as '*/*' or 'application/*'. Also, you can configure the JCR property to get the file name from. The file name is used to send along in the HTTP response for content dispositioning. To configure this, set the "contentDispositionFilenameProperty" init param in the web.xml in which this servlet is defined. Example:
<init-param> <param-name>contentDispositionFilenameProperty</param-name> <param-value>demosite:filename</param-value> </init-param>The contentDispositionFilenameProperty is being encoded. By default, we try to do this user-agent-agnostic. This is preferrable when using caching reverse proxies in front of your application. In user-agent-agnostic mode, we try to convert filenames consisting non ascii chars to their base form, in other words, replace diacritics. However for for example a language like Chinese this won't work. Then, you might want to opt for the user-agent-specific mode. You then have to take care of your reverse proxies taking care of the user-agent. They thus should take the user-agent into account. Also see
ContentDispositionUtils.encodeFileName(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String)
.
Changing the default user-agent-agnostic mode to user-agent-specific mode can be done by adding the init-param:
<init-param> <param-name>contentDispositionFilenameEncoding</param-name> <param-value>user-agent-specific</param-value> </init-param>
You can also configure multiple JCR property names in the above init parameter by comma-separated value.
Sometimes you do not want to set the content disposition headers for all files of a certain mime-type. You can do this by adding a request parameter to the url to the resource. In the template you should add the request param to the link.
<hst:link var="link" hippobean="${item}"> <hst:param name="forceDownload" value="true"/> </hst:link>
If you want to have a different name for the parameter you can explicitly set the name as an init parameter of the BinariesServlet.
<init-param> <param-name>forceContentDispositionRequestParamName</param-name> <param-value>forceDownload</param-value> </init-param>
Modifier and Type | Class and Description |
---|---|
protected class |
BinariesServlet.DefaultBinaryPageFactory |
Modifier and Type | Field and Description |
---|---|
static String |
BASE_BINARIES_CONTENT_PATH_INIT_PARAM |
static String |
BINARY_DATA_PROP_NAME_INIT_PARAM |
static String |
BINARY_LAST_MODIFIED_PROP_NAME_INIT_PARAM |
static String |
BINARY_MIME_TYPE_PROP_NAME_INIT_PARAM |
static String |
BINARY_RESOURCE_NODE_TYPE_INIT_PARAM |
static String |
CONTENT_DISPOSITION_CONTENT_TYPES_INIT_PARAM |
static String |
CONTENT_DISPOSITION_FILENAME_ENCODING_INIT_PARAM
The init param indicating whether the fileName for the content disposition can be encoded 'user-agent-specific' or
'user-agent-agnostic', also see
ContentDispositionUtils.encodeFileName(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String) |
static String |
CONTENT_DISPOSITION_FILENAME_PROPERTY_INIT_PARAM |
static String |
DEFAULT_FORCE_CONTENT_DISPOSITION_PARAM_NAME |
static String |
FORCE_CONTENT_DISPOSITION_INIT_PARAM |
static String |
SET_CONTENT_LENGTH_HEADER_INIT_PARAM |
Constructor and Description |
---|
BinariesServlet() |
Modifier and Type | Method and Description |
---|---|
protected BinaryPageFactory |
createBinaryPageFactory() |
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
doInit() |
protected BinaryPage |
getBinaryPage(javax.servlet.http.HttpServletRequest request,
String resourcePath) |
protected boolean |
getBooleanInitParameter(String paramName,
boolean defaultValue) |
protected String |
getInitParameter(String paramName,
String defaultValue) |
protected long |
getLastModifiedFromResource(javax.servlet.http.HttpServletRequest request,
String resourcePath) |
protected long |
getLongInitParameter(String paramName,
long defaultValue) |
protected BinaryPage |
getPageFromCacheOrLoadPage(javax.servlet.http.HttpServletRequest request) |
protected InputStream |
getRepositoryResourceStream(javax.jcr.Session session,
BinaryPage page) |
protected javax.jcr.Node |
getResourceNode(javax.jcr.Session session,
String resourcePath)
Retrieve the JCR node representing a resource
|
protected String |
getSessionUserID(javax.servlet.http.HttpServletRequest request) |
protected BinaryPage |
getValidatedPageFromCache(javax.servlet.http.HttpServletRequest request,
BinaryPage page) |
void |
init(javax.servlet.ServletConfig config) |
protected void |
initBinaryPageValues(javax.jcr.Session session,
BinaryPage page) |
protected boolean |
isPageStale(javax.servlet.http.HttpServletRequest request,
BinaryPage page)
Hook for subclasses to check whether a previously cached page should be recreated.
|
protected void |
storeResourceOnBinaryPage(BinaryPage page,
javax.jcr.Node resourceNode)
Stores the binary content of
resourceNode on the page unless the page
is marked to be uncacheable. |
protected void |
writeResponse(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
BinaryPage page) |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
public static final String SET_CONTENT_LENGTH_HEADER_INIT_PARAM
public static final String BASE_BINARIES_CONTENT_PATH_INIT_PARAM
public static final String CONTENT_DISPOSITION_CONTENT_TYPES_INIT_PARAM
public static final String CONTENT_DISPOSITION_FILENAME_PROPERTY_INIT_PARAM
public static final String CONTENT_DISPOSITION_FILENAME_ENCODING_INIT_PARAM
ContentDispositionUtils.encodeFileName(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String)
public static final String FORCE_CONTENT_DISPOSITION_INIT_PARAM
public static final String DEFAULT_FORCE_CONTENT_DISPOSITION_PARAM_NAME
public static final String BINARY_RESOURCE_NODE_TYPE_INIT_PARAM
public static final String BINARY_DATA_PROP_NAME_INIT_PARAM
public static final String BINARY_MIME_TYPE_PROP_NAME_INIT_PARAM
public static final String BINARY_LAST_MODIFIED_PROP_NAME_INIT_PARAM
protected BinaryPageFactory createBinaryPageFactory()
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
protected void writeResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, BinaryPage page) throws IOException
IOException
protected InputStream getRepositoryResourceStream(javax.jcr.Session session, BinaryPage page) throws javax.jcr.RepositoryException
session
- page
- BinaryPage.getResourcePath()
, or null
if
no binary could be found.javax.jcr.RepositoryException
protected BinaryPage getPageFromCacheOrLoadPage(javax.servlet.http.HttpServletRequest request)
protected BinaryPage getValidatedPageFromCache(javax.servlet.http.HttpServletRequest request, BinaryPage page)
protected boolean isPageStale(javax.servlet.http.HttpServletRequest request, BinaryPage page)
BinariesServlet
returns falserequest
- current HTTP requestpage
- current cached binary pageprotected long getLastModifiedFromResource(javax.servlet.http.HttpServletRequest request, String resourcePath)
protected final String getSessionUserID(javax.servlet.http.HttpServletRequest request)
protected javax.jcr.Node getResourceNode(javax.jcr.Session session, String resourcePath)
session
- the jcr session to fetch the resource withresourcePath
- path of resourcenull
if cannot be found or a
RepositoryException
happened.protected BinaryPage getBinaryPage(javax.servlet.http.HttpServletRequest request, String resourcePath)
protected void initBinaryPageValues(javax.jcr.Session session, BinaryPage page) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
protected void storeResourceOnBinaryPage(BinaryPage page, javax.jcr.Node resourceNode)
resourceNode
on the page
unless the page
is marked to be uncacheable.protected void doInit()
protected boolean getBooleanInitParameter(String paramName, boolean defaultValue)
protected long getLongInitParameter(String paramName, long defaultValue)
Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.