org.mmbase.servlet
Class HandleServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byorg.mmbase.servlet.MMBaseServlet
              extended byorg.mmbase.servlet.BridgeServlet
                  extended byorg.mmbase.servlet.HandleServlet
All Implemented Interfaces:
MMBaseStarter, Serializable, Servlet, ServletConfig
Direct Known Subclasses:
AttachmentServlet, ImageServlet

public class HandleServlet
extends BridgeServlet

Base servlet for nodes with a 'handle' field. It serves as a basic implementation for more specialized servlets. The mime-type is always application/x-binary, forcing the browser to download.

Since:
MMBase-1.6
Version:
$Id: HandleServlet.java,v 1.28 2006/06/27 13:11:51 johannes Exp $
Author:
Michiel Meeuwissen
See Also:
ImageServlet, AttachmentServlet, Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.mmbase.servlet.BridgeServlet
BridgeServlet.QueryParts
 
Field Summary
protected static Pattern legalizeFileName
           
 
Fields inherited from class org.mmbase.servlet.BridgeServlet
FILE_PATTERN, MESSAGE_ATTRIBUTE
 
Fields inherited from class org.mmbase.servlet.MMBaseServlet
mmbase, retryAfter
 
Constructor Summary
HandleServlet()
           
 
Method Summary
 void doGet(HttpServletRequest req, HttpServletResponse res)
          Serves a node with a byte[] handle field as an attachment.
protected  Map getAssociations()
          On default, servlets are not associated with any function.
protected  Cloud getClassCloud()
          Obtains a cloud using 'class' security.
protected  String getFileName(Node node, Node titleNode, String def)
           
protected  String getMimeType(Node node)
          Forces download in browsers.
 void init()
          Takes care of the 'expire' init-parameter.
static void main(String[] argv)
          Just to test to damn regexp
protected  void sendBytes(HttpServletResponse res, byte[] bytes)
          Deprecated.  
protected  void sendBytes(HttpServletResponse res, InputStream bytes)
           
protected  boolean setCacheControl(HttpServletResponse res, Node node)
          Sets cache-controlling headers.
protected  boolean setContent(BridgeServlet.QueryParts query, Node node, String mimeType)
          Sets the content disposition header.
protected  boolean setExpires(HttpServletResponse res, Node node)
          Sets the exires header.
 
Methods inherited from class org.mmbase.servlet.BridgeServlet
desperatelyGetNode, findCloud, getAnonymousCloud, getCloud, getCloudName, getLastModified, getNode, getServedNode, readQuery, readQuery, readServletPath
 
Methods inherited from class org.mmbase.servlet.MMBaseServlet
associateMapping, checkInited, decRefCount, destroy, getMMBase, getRequestURL, getServletByAssociation, getServletByMapping, getServletInfo, getServletMappings, getServletMappingsByAssociation, incRefCount, service, setInitException, setMMBase
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

legalizeFileName

protected static final Pattern legalizeFileName
Constructor Detail

HandleServlet

public HandleServlet()
Method Detail

getAssociations

protected Map getAssociations()
Description copied from class: MMBaseServlet
On default, servlets are not associated with any function. This function is called in the init method.

Overrides:
getAssociations in class MMBaseServlet
Returns:
A map of Strings (function) -> Integer (priority). Never null.

init

public void init()
          throws ServletException
Takes care of the 'expire' init-parameter. Inits lastmodifiedField. The init of an MMBaseServlet checks if MMBase is running. It not then it is started.

Overrides:
init in class BridgeServlet
Throws:
ServletException

getClassCloud

protected Cloud getClassCloud()
Description copied from class: BridgeServlet
Obtains a cloud using 'class' security. If e.g. you authorize org.mmbase.servlet.ImageServlet by class-security for read all rights, it will be used.

Overrides:
getClassCloud in class BridgeServlet

getMimeType

protected String getMimeType(Node node)
Forces download in browsers. This is overriden in several extensions.


getFileName

protected String getFileName(Node node,
                             Node titleNode,
                             String def)
Since:
MMBase-1.8

setContent

protected boolean setContent(BridgeServlet.QueryParts query,
                             Node node,
                             String mimeType)
                      throws IOException
Sets the content disposition header.

Returns:
true on success
Throws:
IOException

setExpires

protected boolean setExpires(HttpServletResponse res,
                             Node node)
Sets the exires header.

Returns:
true on sucess

setCacheControl

protected boolean setCacheControl(HttpServletResponse res,
                                  Node node)
Sets cache-controlling headers. Only nodes which are to be served to 'anonymous' might be (front proxy) cached. To other nodes there might be read restrictions, so they should not be stored in front-proxy caches.

Returns:
true if cacheing is disabled.
Since:
MMBase-1.7

doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
           throws ServletException,
                  IOException
Serves a node with a byte[] handle field as an attachment.

Overrides:
doGet in class MMBaseServlet
Throws:
ServletException
IOException

sendBytes

protected final void sendBytes(HttpServletResponse res,
                               byte[] bytes)
                        throws IOException
Deprecated.  

Utility function to send bytes at the end of doGet implementation.

Throws:
IOException

sendBytes

protected final void sendBytes(HttpServletResponse res,
                               InputStream bytes)
                        throws IOException
Throws:
IOException

main

public static void main(String[] argv)
Description copied from class: BridgeServlet
Just to test to damn regexp



MMBase build 1.8.1.20060716