com.day.cq.wcm.commons
Class AbstractImageServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by org.apache.sling.api.servlets.SlingSafeMethodsServlet
          extended by com.day.cq.wcm.commons.AbstractImageServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class AbstractImageServlet
extends org.apache.sling.api.servlets.SlingSafeMethodsServlet

Servers as base for image servlets

See Also:
Serialized Form

Nested Class Summary
static class AbstractImageServlet.ImageContext
          Convenience class that holds usefull stuff needed for image generation
 
Constructor Summary
AbstractImageServlet()
           
 
Method Summary
protected  boolean checkModifiedSince(org.apache.sling.api.SlingHttpServletRequest req, org.apache.sling.api.SlingHttpServletResponse resp)
          Checks if the request contains a if-last-modified-since header and if the node has a jcr:lastModified property.
protected abstract  com.day.image.Layer createLayer(AbstractImageServlet.ImageContext c)
          Creates the image layer.
protected  void doGet(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
          Handles a GET request and created the desired image.
protected  double getImageQuality()
          Returns the image quality.
protected  String getImageType()
          Returns the image type.
protected  String getImageType(String ext)
          Returns the image type for the given extension.
protected  void writeLayer(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, AbstractImageServlet.ImageContext context, com.day.image.Layer layer)
          Writes the layer to the response.
 
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getAllowedRequestMethods, getServletInfo, handleMethodNotImplemented, mayService, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, 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

AbstractImageServlet

public AbstractImageServlet()
Method Detail

doGet

protected void doGet(org.apache.sling.api.SlingHttpServletRequest request,
                     org.apache.sling.api.SlingHttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
Handles a GET request and created the desired image. calls the following methods: If the requested extension does not map to a known image type via getImageType(String), a 404 is responded.

Overrides:
doGet in class org.apache.sling.api.servlets.SlingSafeMethodsServlet
Throws:
javax.servlet.ServletException
IOException

writeLayer

protected void writeLayer(org.apache.sling.api.SlingHttpServletRequest request,
                          org.apache.sling.api.SlingHttpServletResponse response,
                          AbstractImageServlet.ImageContext context,
                          com.day.image.Layer layer)
                   throws IOException,
                          RepositoryException
Writes the layer to the response.

Parameters:
request - servlet request
response - servlet response
context - the context
layer - layer
Throws:
IOException - if an I/O error occurs.
RepositoryException - if an repositor error occurs.

getImageType

protected String getImageType()
Returns the image type. default "image/png"

Returns:
the image type.

getImageType

protected String getImageType(String ext)
Returns the image type for the given extension. currently there are only "png", "gif" and "jpg" supported, but an subclass can provide other mappings.

Parameters:
ext - the extension
Returns:
the image type or null.

getImageQuality

protected double getImageQuality()
Returns the image quality. default 1.0

Returns:
the image quality.

checkModifiedSince

protected boolean checkModifiedSince(org.apache.sling.api.SlingHttpServletRequest req,
                                     org.apache.sling.api.SlingHttpServletResponse resp)
Checks if the request contains a if-last-modified-since header and if the node has a jcr:lastModified property. if the properties were modified before the header a 304 is sent otherwise the response last modified header is set. If the give doesn't have the property, the parent node is searched.

Parameters:
req - the request
resp - the response
Returns:
true if the response was sent

createLayer

protected abstract com.day.image.Layer createLayer(AbstractImageServlet.ImageContext c)
                                            throws RepositoryException,
                                                   IOException
Creates the image layer.

Parameters:
c - the convenience context
Returns:
the layer
Throws:
RepositoryException - if an error occurs.
IOException - if an I/O error occurs


Copyright © 2009 Day Management AG. All Rights Reserved.