org.mapfish.print.servlet
Class MapPrinterServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mapfish.print.servlet.BaseMapServlet
              extended by org.mapfish.print.servlet.MapPrinterServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class MapPrinterServlet
extends BaseMapServlet

Main print servlet.

See Also:
Serialized Form

Nested Class Summary
protected static class MapPrinterServlet.TempFile
           
 
Field Summary
protected static java.lang.String TEMP_FILE_PREFIX
           
protected static java.lang.String TEMP_FILE_SUFFIX
           
 
Fields inherited from class org.mapfish.print.servlet.BaseMapServlet
LOGGER
 
Constructor Summary
MapPrinterServlet()
           
 
Method Summary
protected  void addTempFile(MapPrinterServlet.TempFile tempFile, java.lang.String id)
           
protected  void createAndGetPDF(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
          All in one method: create and returns the PDF to the client.
protected  void createPDF(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, java.lang.String basePath)
          Create the PDF and returns to the client (in JSON) the URL to get the PDF.
protected  void deleteFile(java.io.File file)
          If the file is defined, delete it.
 void destroy()
           
protected  MapPrinterServlet.TempFile doCreatePDFFile(java.lang.String spec, javax.servlet.http.HttpServletRequest httpServletRequest)
          Do the actual work of creating the PDF temporary file.
protected  void doGet(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
           
protected  void doPost(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
           
protected  void error(javax.servlet.http.HttpServletResponse httpServletResponse, java.lang.String message, int code)
          Send an error XXX to the client with a message
protected  void error(javax.servlet.http.HttpServletResponse httpServletResponse, java.lang.Throwable e)
          Send an error XXX to the client with an exception
protected  java.lang.String generateId(java.io.File tempFile)
          Get the ID to use in function of the filename (filename without the prefix and the extension).
protected  java.lang.String getBaseUrl(javax.servlet.http.HttpServletRequest httpServletRequest)
           
protected  void getInfo(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.lang.String basePath)
          To get (in JSON) the information about the available formats and CO.
protected  void getPDF(javax.servlet.http.HttpServletResponse httpServletResponse, java.lang.String id)
          To get the PDF created previously.
protected  java.lang.String getSpecFromPostBody(javax.servlet.http.HttpServletRequest httpServletRequest)
           
protected  java.io.File getTempDir()
          Get and cache the temporary directory to use for saving the generated PDF files.
 void init()
           
protected  void purgeOldTemporaryFiles()
          Will purge all the known temporary files older than TEMP_FILE_PURGE_SECONDS.
protected  void sendPdfFile(javax.servlet.http.HttpServletResponse httpServletResponse, java.io.File tempFile)
          copy the PDF into the output stream
 
Methods inherited from class org.mapfish.print.servlet.BaseMapServlet
getMapPrinter
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
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

TEMP_FILE_PREFIX

protected static final java.lang.String TEMP_FILE_PREFIX
See Also:
Constant Field Values

TEMP_FILE_SUFFIX

protected static final java.lang.String TEMP_FILE_SUFFIX
See Also:
Constant Field Values
Constructor Detail

MapPrinterServlet

public MapPrinterServlet()
Method Detail

doGet

protected void doGet(javax.servlet.http.HttpServletRequest httpServletRequest,
                     javax.servlet.http.HttpServletResponse httpServletResponse)
              throws javax.servlet.ServletException,
                     java.io.IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest httpServletRequest,
                      javax.servlet.http.HttpServletResponse httpServletResponse)
               throws javax.servlet.ServletException,
                      java.io.IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

init

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

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class BaseMapServlet

createAndGetPDF

protected void createAndGetPDF(javax.servlet.http.HttpServletRequest httpServletRequest,
                               javax.servlet.http.HttpServletResponse httpServletResponse)
All in one method: create and returns the PDF to the client. Avoid to use it, the accents in the spec are not all supported.


createPDF

protected void createPDF(javax.servlet.http.HttpServletRequest httpServletRequest,
                         javax.servlet.http.HttpServletResponse httpServletResponse,
                         java.lang.String basePath)
                  throws javax.servlet.ServletException
Create the PDF and returns to the client (in JSON) the URL to get the PDF.

Throws:
javax.servlet.ServletException

addTempFile

protected void addTempFile(MapPrinterServlet.TempFile tempFile,
                           java.lang.String id)

getSpecFromPostBody

protected java.lang.String getSpecFromPostBody(javax.servlet.http.HttpServletRequest httpServletRequest)
                                        throws java.io.IOException
Throws:
java.io.IOException

getPDF

protected void getPDF(javax.servlet.http.HttpServletResponse httpServletResponse,
                      java.lang.String id)
               throws java.io.IOException
To get the PDF created previously.

Throws:
java.io.IOException

getInfo

protected void getInfo(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp,
                       java.lang.String basePath)
                throws javax.servlet.ServletException,
                       java.io.IOException
To get (in JSON) the information about the available formats and CO.

Throws:
javax.servlet.ServletException
java.io.IOException

doCreatePDFFile

protected MapPrinterServlet.TempFile doCreatePDFFile(java.lang.String spec,
                                                     javax.servlet.http.HttpServletRequest httpServletRequest)
                                              throws java.io.IOException,
                                                     com.lowagie.text.DocumentException,
                                                     javax.servlet.ServletException
Do the actual work of creating the PDF temporary file.

Throws:
java.io.IOException
com.lowagie.text.DocumentException
javax.servlet.ServletException

sendPdfFile

protected void sendPdfFile(javax.servlet.http.HttpServletResponse httpServletResponse,
                           java.io.File tempFile)
                    throws java.io.IOException
copy the PDF into the output stream

Throws:
java.io.IOException

error

protected void error(javax.servlet.http.HttpServletResponse httpServletResponse,
                     java.lang.Throwable e)
Send an error XXX to the client with an exception


error

protected void error(javax.servlet.http.HttpServletResponse httpServletResponse,
                     java.lang.String message,
                     int code)
Send an error XXX to the client with a message


getTempDir

protected java.io.File getTempDir()
Get and cache the temporary directory to use for saving the generated PDF files.


deleteFile

protected void deleteFile(java.io.File file)
If the file is defined, delete it.


generateId

protected java.lang.String generateId(java.io.File tempFile)
Get the ID to use in function of the filename (filename without the prefix and the extension).


getBaseUrl

protected java.lang.String getBaseUrl(javax.servlet.http.HttpServletRequest httpServletRequest)

purgeOldTemporaryFiles

protected void purgeOldTemporaryFiles()
Will purge all the known temporary files older than TEMP_FILE_PURGE_SECONDS.



Copyright © 2009 Camptocamp SA. All Rights Reserved.