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

public final Class MathInputToImageServlet

extends BaseServlet
Class Inheritance
Imports
uk.ac.ed.ph.snuggletex.InputError, .SnuggleEngine, .SnuggleInput, .SnuggleSession, .WebPageOutputOptions, .DOMOutputOptions.ErrorOutputOptions, 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, .IOException, .OutputStream, java.util.List, javax.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.commons.io.output.NullOutputStream, org.slf4j.Logger, .LoggerFactory

Simple demo servlet that accepts some (displaymath mode) input and serves up an image rendition of the result.

This is useful for creating legacy outputs for dynamically created pages. (I.e. not the documentation pages.)

Author
David McKain
Version
$Revision$

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MathInputToImageServlet.ImageSavingCallback

Does the job of the saving the (first) image rendered to the given output file, recording any Throwable for later retrieval.

Field Summary

Modifier and TypeField and Description
private static final Logger
private static final long

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 void
Inherited from uk.ac.ed.ph.snuggletex.webapp.BaseServlet:
chooseBestBaseWebPageOutputOptionschooseBestWebPageTypecreateMathMLSourceSerializationOptionscreateSnuggleEngineensureGetContextInitParamensureReadResourceextractMathMLElementgetStylesheetgetStylesheetCachegetStylesheetManagerisInternetExplorerisMathMLCapable

Field Detail

loggerback to summary
private static final Logger logger
serialVersionUIDback to summary
private static final long serialVersionUID

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

Constructor Detail

MathInputToImageServletback to summary
public MathInputToImageServlet()

Method Detail

doGetback to summary
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws 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
IOException:
if an input or output error is detected when the servlet handles the GET request
doRequestback to summary
private void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException
uk.ac.ed.ph.snuggletex.webapp back to summary

private Class MathInputToImageServlet.ImageSavingCallback

extends SimpleMathMLImageSavingCallback
Class Inheritance

Does the job of the saving the (first) image rendered to the given output file, recording any Throwable for later retrieval.

Field Summary

Modifier and TypeField and Description
private Throwable
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 outputFile)

Method Summary

Modifier and TypeMethod and Description
public Throwable
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

failureback to summary
private Throwable failure
outputFileback to summary
private final File outputFile

Constructor Detail

ImageSavingCallbackback to summary
public ImageSavingCallback(final File outputFile)

Method Detail

getFailureback to summary
public Throwable getFailure()
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.