org.hippoecm.hst.servlet
Class BinariesServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.hippoecm.hst.servlet.BinariesServlet
- All Implemented Interfaces:
- Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
public class BinariesServlet
- extends javax.servlet.http.HttpServlet
Serves binary files from the repository. Binary files are represented by nodes.
This servlet has the ability to set the "Content-Disposition" header in the HTTP response to tell browsers to
download a binary file instead of trying to display the file directly. This needs some configuration, which is
described below.
Content disposition configuration
To configure which mime types to enable content dispositioning for, set the "contentDispositionContentTypes" init
param in the web.xml in which this servlet is defined. Example:
<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 #encodeContentDispositionFileName(HttpServletRequest, HttpServletResponse, 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.
- See Also:
- Serialized Form
Method Summary |
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)
Return the input stream for a looked up binary for BinaryPage.getResourcePath() and return null if
there is not found a binary |
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 void |
storeBinaryPageToCache(BinaryPage page,
javax.jcr.Node resourceNode)
|
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SET_CONTENT_LENGTH_HEADER_INIT_PARAM
public static final String SET_CONTENT_LENGTH_HEADER_INIT_PARAM
- See Also:
- Constant Field Values
BASE_BINARIES_CONTENT_PATH_INIT_PARAM
public static final String BASE_BINARIES_CONTENT_PATH_INIT_PARAM
- See Also:
- Constant Field Values
CONTENT_DISPOSITION_CONTENT_TYPES_INIT_PARAM
public static final String CONTENT_DISPOSITION_CONTENT_TYPES_INIT_PARAM
- See Also:
- Constant Field Values
CONTENT_DISPOSITION_FILENAME_PROPERTY_INIT_PARAM
public static final String CONTENT_DISPOSITION_FILENAME_PROPERTY_INIT_PARAM
- See Also:
- Constant Field Values
CONTENT_DISPOSITION_FILENAME_ENCODING_INIT_PARAM
public static final 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
#encodeContentDispositionFileName(HttpServletRequest, HttpServletResponse, String)
- See Also:
- Constant Field Values
BINARY_RESOURCE_NODE_TYPE_INIT_PARAM
public static final String BINARY_RESOURCE_NODE_TYPE_INIT_PARAM
- See Also:
- Constant Field Values
BINARY_DATA_PROP_NAME_INIT_PARAM
public static final String BINARY_DATA_PROP_NAME_INIT_PARAM
- See Also:
- Constant Field Values
BINARY_MIME_TYPE_PROP_NAME_INIT_PARAM
public static final String BINARY_MIME_TYPE_PROP_NAME_INIT_PARAM
- See Also:
- Constant Field Values
BINARY_LAST_MODIFIED_PROP_NAME_INIT_PARAM
public static final String BINARY_LAST_MODIFIED_PROP_NAME_INIT_PARAM
- See Also:
- Constant Field Values
BinariesServlet
public BinariesServlet()
init
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
-
- Specified by:
init
in interface javax.servlet.Servlet
- Overrides:
init
in class javax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
doGet
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
- Overrides:
doGet
in class javax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
getRepositoryResourceStream
protected InputStream getRepositoryResourceStream(javax.jcr.Session session,
BinaryPage page)
throws javax.jcr.RepositoryException
- Return the input stream for a looked up binary for
BinaryPage.getResourcePath()
and return null
if
there is not found a binary
- Parameters:
session
- page
-
- Returns:
-
- Throws:
javax.jcr.RepositoryException
getPageFromCacheOrLoadPage
protected BinaryPage getPageFromCacheOrLoadPage(javax.servlet.http.HttpServletRequest request)
getValidatedPageFromCache
protected BinaryPage getValidatedPageFromCache(javax.servlet.http.HttpServletRequest request,
BinaryPage page)
getLastModifiedFromResource
protected long getLastModifiedFromResource(javax.servlet.http.HttpServletRequest request,
String resourcePath)
getBinaryPage
protected BinaryPage getBinaryPage(javax.servlet.http.HttpServletRequest request,
String resourcePath)
initBinaryPageValues
protected void initBinaryPageValues(javax.jcr.Session session,
BinaryPage page)
throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
storeBinaryPageToCache
protected void storeBinaryPageToCache(BinaryPage page,
javax.jcr.Node resourceNode)
doInit
protected void doInit()
getInitParameter
protected String getInitParameter(String paramName,
String defaultValue)
getBooleanInitParameter
protected boolean getBooleanInitParameter(String paramName,
boolean defaultValue)
getLongInitParameter
protected long getLongInitParameter(String paramName,
long defaultValue)
Copyright © 2008-2012 Hippo. All Rights Reserved.