com.gentics.cr.portlet.imagestore
Class GenticsImageStoreServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.gentics.cr.portlet.imagestore.GenticsImageStoreServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class GenticsImageStoreServlet
extends javax.servlet.http.HttpServlet

Servlet for resizing images for Content.Node

See Also:
Serialized Form
 

Field Summary
static int BUFFER_SIZE
          buffer size for writing the image to the response
protected  com.gentics.lib.log.NodeLogger logger
          logger
private  String portalBasePath
          Portal basepath
private  String portalBasePathRegEx
          Regex that will be used to determine the portal basepath
private  com.gentics.api.imagestore.RequestDecorator requestDecoratorClass
          Will be instantiated with a class given by an optional servlet parameter which enables the user to modify header information and data in requests to the GenticsImageStore May be null.
private  String secret
          Configured secret for resize validation
private static long serialVersionUID
          serial version uid
private  com.gentics.api.imagestore.ImageUriMapper uriMapper
          Will be instantiated with a class given by an optional servlet parameter which enables the user to customize exactly how requests to images are mapped to the actual location where the image will be fetched from.
private  URI urlPrefix
          The GenticsImageStore by default fetches the subject image from the host of the request (usually identical to the host the GenticsImageStore runs on).
 
Constructor Summary
GenticsImageStoreServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doResizing(String mode, String width, String height, boolean cropandresize, String topleftx, String toplefty, String cropwidth, String cropheight, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String imagePath)
          Do the resizing of an image and return the image
 void init()
           
private  URI toImageUri(javax.servlet.http.HttpServletRequest request, String imagePath)
          Gets the absolute URI for a relative image path.
protected  void writeImageToResponse(com.gentics.api.lib.upload.FileInformation image, javax.servlet.http.HttpServletResponse response)
          Write the image into the servlet response
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, 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
 

Field Detail

serialVersionUID

private static final long serialVersionUID
serial version uid

See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
buffer size for writing the image to the response

See Also:
Constant Field Values

portalBasePath

private String portalBasePath
Portal basepath


portalBasePathRegEx

private String portalBasePathRegEx
Regex that will be used to determine the portal basepath


logger

protected com.gentics.lib.log.NodeLogger logger
logger


urlPrefix

private volatile URI urlPrefix
The GenticsImageStore by default fetches the subject image from the host of the request (usually identical to the host the GenticsImageStore runs on). However, in some network constellations the host name used to make the request to the GenticsImageStore is actually the host name of some front end web server for example. In such constellations, the host the request is made to may not be reachable from the host the GenticsImageStore runs on, and in such cases it is useful to be able to specify a custom urlPrefix which should include the scheme, host and optionally the port of the host where images should be fetched from. For example http://localhost:8080 May be null.


uriMapper

private volatile com.gentics.api.imagestore.ImageUriMapper uriMapper
Will be instantiated with a class given by an optional servlet parameter which enables the user to customize exactly how requests to images are mapped to the actual location where the image will be fetched from. May be null.


requestDecoratorClass

private volatile com.gentics.api.imagestore.RequestDecorator requestDecoratorClass
Will be instantiated with a class given by an optional servlet parameter which enables the user to modify header information and data in requests to the GenticsImageStore May be null.


secret

private volatile String secret
Configured secret for resize validation

Constructor Detail

GenticsImageStoreServlet

public GenticsImageStoreServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doGet

protected 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

toImageUri

private URI toImageUri(javax.servlet.http.HttpServletRequest request,
                       String imagePath)
                throws javax.servlet.ServletException
Gets the absolute URI for a relative image path. If the urlPrefix servlet parameter is provided, it will be used to make the given imagePath absolute. If urlPrefix is not provided, the scheme, host and port of the given request will be used to make the given imagePath absolute. Additionally, if the urlMapper servlet parameter is provided, it will be given the now absolute imagePath and whatever it returns replaces the absoulte imagePath.

Parameters:
request - The request to this servlet which fetches the image from the path specified with imagePath.
imagePath - The relative path to an image.
Returns:
The absolute URI for this image.
Throws:
javax.servlet.ServletException - If the given imagePath can not be made absolute because it is of an incorrect format.

doResizing

protected void doResizing(String mode,
                          String width,
                          String height,
                          boolean cropandresize,
                          String topleftx,
                          String toplefty,
                          String cropwidth,
                          String cropheight,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          String imagePath)
                   throws javax.servlet.ServletException,
                          IOException
Do the resizing of an image and return the image

Parameters:
mode - resizing mode
width - new width
height - new height
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
IOException

writeImageToResponse

protected void writeImageToResponse(com.gentics.api.lib.upload.FileInformation image,
                                    javax.servlet.http.HttpServletResponse response)
                             throws IOException
Write the image into the servlet response

Parameters:
image - image data
response - servlet response
Throws:
IOException


Copyright © 2014 Gentics Software GmbH. All Rights Reserved.