Top Description Inners Fields Constructors Methods
uk.ac.ed.ph.snuggletex.webapp

public final Class DocumentationServlet

extends BaseServlet
Class Inheritance
Imports
uk.ac.ed.ph.snuggletex.InputError, .SerializationMethod, .SnuggleEngine, .SnuggleInput, .SnuggleLogicException, .SnuggleSession, .WebPageOutputOptions, .WebPageOutputOptionsTemplates, .DOMOutputOptions.ErrorOutputOptions, .WebPageOutputOptions.WebPageType, uk.ac.ed.ph.snuggletex.definitions.W3CConstants, uk.ac.ed.ph.snuggletex.internal.util.IOUtilities, uk.ac.ed.ph.snuggletex.jeuclid.JEuclidUtilities, .SimpleMathMLImageSavingCallback, uk.ac.ed.ph.snuggletex.utilities.MessageFormatter, java.io.File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.util.HashMap, .List, .Map, javax.servlet.ServletException, javax.servlet.http.HttpServletRequest, .HttpServletResponse, javax.xml.transform.Transformer, org.slf4j.Logger, .LoggerFactory

Rather trivial (and badly factored) servlet that serves up the documentation pages for SnuggleTeX. Main points:
Author
David McKain
Version
$Revision$

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
DocumentationServlet.ImageSavingCallback

Implementation of SimpleMathMLImageSavingCallback that stores images in the given output directory with the given base URL, using a very simple naming scheme.

Field Summary

Modifier and TypeField and Description
private File
baseDirectory

Directory in which Files created and cached by this servlet will be stored.

private boolean
caching

Whether to cache result or not

private static final String
CACHING_PARAM

init-param controlling whether we are caching or not

private final Map<String, String>
extensionToContentTypeMap

Maps supported extensions to Content Types, for all extensions we support here

private final Map<String, WebPageOutputOptions.WebPageType>
extensionToWebPageTypeMap

Maps extension to WebPageType, for those generated that way

private static final String
FORMAT_OUTPUT_XSLT_URI

Location of XSLT for formatting the resulting web pages

pack-priv static final Logger
private static final String
MACROS_RESOURCE_LOCATION

Location of macros TeX file (relative to webapp)

private static final long
private static final String
TEX_SOURCE_BASE_RESOURCE

Base Location for .tex source files (relative to webapp)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
doGet(HttpServletRequest request, HttpServletResponse response)

Overrides javax.servlet.http.HttpServlet.doGet.

Called by the server (via the service method) to allow a servlet to handle a GET request.

private File

Returns:

resulting File, or null if the source TeX file for this resource couldn't be located or if the file extension couldn't be understood.
generateResource
(final HttpServletRequest request, final String resourcePath, final String resourceBaseName, final String extension)

Generates the documentation resource at the given path.

private File
generateSnuggledFile(final HttpServletRequest request, final InputStream texSourceStream, final String texSourceResourcePath, final WebPageOutputOptions.WebPageType webPageType, final String outputResourcePath, final String imageOutputDirectoryResourcePath, final String imageOutputBaseURL)
References Deprecated WebPageOutputOptions.WebPageType is deprecated or references (maybe indirectly) at least one deprecated element.

public void
init()

Overrides javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

private File
mapResourcePath(final String resourcePath)

Maps a requested "resource path" to a file under our baseDirectory "cache".

Inherited from uk.ac.ed.ph.snuggletex.webapp.BaseServlet:
chooseBestBaseWebPageOutputOptionschooseBestWebPageTypecreateMathMLSourceSerializationOptionscreateSnuggleEngineensureGetContextInitParamensureReadResourceextractMathMLElementgetStylesheetgetStylesheetCachegetStylesheetManagerisInternetExplorerisMathMLCapable

Field Detail

baseDirectoryback to summary
private File baseDirectory

Directory in which Files created and cached by this servlet will be stored.

cachingback to summary
private boolean caching

Whether to cache result or not

CACHING_PARAMback to summary
private static final String CACHING_PARAM

init-param controlling whether we are caching or not

extensionToContentTypeMapback to summary
private final Map<String, String> extensionToContentTypeMap

Maps supported extensions to Content Types, for all extensions we support here

extensionToWebPageTypeMapback to summary
private final Map<String, WebPageOutputOptions.WebPageType> extensionToWebPageTypeMap

Maps extension to WebPageType, for those generated that way

FORMAT_OUTPUT_XSLT_URIback to summary
private static final String FORMAT_OUTPUT_XSLT_URI

Location of XSLT for formatting the resulting web pages

loggerback to summary
pack-priv static final Logger logger
MACROS_RESOURCE_LOCATIONback to summary
private static final String MACROS_RESOURCE_LOCATION

Location of macros TeX file (relative to webapp)

serialVersionUIDback to summary
private static final long serialVersionUID

Hides uk.ac.ed.ph.snuggletex.webapp.BaseServlet.serialVersionUID.

TEX_SOURCE_BASE_RESOURCEback to summary
private static final String TEX_SOURCE_BASE_RESOURCE

Base Location for .tex source files (relative to webapp)

Constructor Detail

DocumentationServletback to summary
public DocumentationServlet()

Method Detail

doGetback to summary
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.doGet.

Doc from javax.servlet.http.HttpServlet.doGet.

Called by the server (via the service method) to allow a servlet to handle a GET request.

Overriding this method to support a GET request also automatically supports an HTTP HEAD request. A HEAD request is a GET request that returns no body in the response, only the request header fields.

When overriding this method, read the request data, write the response headers, get the response's writer or output stream object, and finally, write the response data. It's best to include content type and encoding. When using a PrintWriter object to return the response, set the content type before accessing the PrintWriter object.

The servlet container must write the headers before committing the response, because in HTTP the headers must be sent before the response body.

Where possible, set the Content-Length header (with the javax.servlet.ServletResponse#setContentLength method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.

When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.

The GET method should be safe, that is, without any side effects for which users are held responsible. For example, most form queries have no side effects. If a client request is intended to change stored data, the request should use some other HTTP method.

The GET method should also be idempotent, meaning that it can be safely repeated. Sometimes making a method safe also makes it idempotent. For example, repeating queries is both safe and idempotent, but buying a product online or modifying data is neither safe nor idempotent.

If the request is incorrectly formatted, doGet returns an HTTP "Bad Request" message.

Annotations
@Override
Exceptions
ServletException:
if the request for the GET could not be handled
IOException:
if an input or output error is detected when the servlet handles the GET request
generateResourceback to summary
private File generateResource(final HttpServletRequest request, final String resourcePath, final String resourceBaseName, final String extension) throws ServletException, IOException

Generates the documentation resource at the given path.

Returns:File

resulting File, or null if the source TeX file for this resource couldn't be located or if the file extension couldn't be understood.

generateSnuggledFileback to summary
private File generateSnuggledFile(final HttpServletRequest request, final InputStream texSourceStream, final String texSourceResourcePath, final WebPageOutputOptions.WebPageType webPageType, final String outputResourcePath, final String imageOutputDirectoryResourcePath, final String imageOutputBaseURL) throws ServletException, IOException

References Deprecated

WebPageOutputOptions.WebPageType is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

initback to summary
public void init() throws ServletException

Overrides javax.servlet.GenericServlet.init.

Doc from javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig.

Annotations
@Override
Exceptions
ServletException:
if an exception occurs that interrupts the servlet's normal operation
mapResourcePathback to summary
private File mapResourcePath(final String resourcePath)

Maps a requested "resource path" to a file under our baseDirectory "cache".

uk.ac.ed.ph.snuggletex.webapp back to summary

private Class DocumentationServlet.ImageSavingCallback

extends SimpleMathMLImageSavingCallback
Class Inheritance

Implementation of SimpleMathMLImageSavingCallback that stores images in the given output directory with the given base URL, using a very simple naming scheme.

Field Summary

Modifier and TypeField and Description
private final String
private final File
Inherited from uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback:
DEFAULT_ANTI_ALIASINGDEFAULT_CONTENT_TYPEDEFAULT_FONT_SIZE

Constructor Summary

AccessConstructor and Description
public
ImageSavingCallback(final File imageOutputDirectory, final String imageOutputBaseURL)

Method Summary

Modifier and TypeMethod and Description
private String
getImageName(int mathmlCounter)

public File
getImageOutputFile(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageOutputFile.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputFile.

Implement if you want the resulting image to be written to a File of your choice.

public OutputStream
getImageOutputStream(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageOutputStream.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputStream.

Implement this if you want the resulting image to be written to an OutputStream of your choice.

public String
getImageURL(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageURL.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageURL.

Implement to return the URL String that will be put into the img src attribute to refer to the image.

public void
imageSavingFailed(Object imageOutputObject, int mathmlCounter, String contentType, Throwable exception)

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.imageSavingFailed.

Called back if MathML image could not be saved for some reason.

Inherited from uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback:
getFontSizegetImageContentTypegetImageContentTypegetLayoutContextimageSavingSucceededisAntiAliasingsetAntiAliasingsetFontSizesetImageContentType

Field Detail

imageOutputBaseURLback to summary
private final String imageOutputBaseURL
imageOutputDirectoryback to summary
private final File imageOutputDirectory

Constructor Detail

ImageSavingCallbackback to summary
public ImageSavingCallback(final File imageOutputDirectory, final String imageOutputBaseURL)

Method Detail

getImageNameback to summary
private String getImageName(int mathmlCounter)
getImageOutputFileback to summary
public File getImageOutputFile(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageOutputFile.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputFile.

Doc from uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputFile.

Implement if you want the resulting image to be written to a File of your choice. Return null if you want the image to be written to the result of getImageOutputStream(int) instead.

Annotations
@Override
getImageOutputStreamback to summary
public OutputStream getImageOutputStream(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageOutputStream.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputStream.

Doc from uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageOutputStream.

Implement this if you want the resulting image to be written to an OutputStream of your choice. The method getImageOutputFile(int) is checked first, so must return null in this case.

Annotations
@Override
getImageURLback to summary
public String getImageURL(int mathmlCounter)

Implements abstract uk.ac.ed.ph.snuggletex.jeuclid.SimpleMathMLImageSavingCallback.getImageURL.

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageURL.

Doc from uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.getImageURL.

Implement to return the URL String that will be put into the img src attribute to refer to the image.

Annotations
@Override
imageSavingFailedback to summary
public void imageSavingFailed(Object imageOutputObject, int mathmlCounter, String contentType, Throwable exception)

Implements uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.imageSavingFailed.

Doc from uk.ac.ed.ph.snuggletex.jeuclid.MathMLImageSavingCallback.imageSavingFailed.

Called back if MathML image could not be saved for some reason.