Top Description Fields Constructors Methods
uk.ac.ed.ph.snuggletex.internal

public final Class WebPageBuilder

extends Object
Class Inheritance
Imports
uk.ac.ed.ph.snuggletex.SerializationMethod, .SnuggleRuntimeException, .SnuggleSession.EndOutputAction, .WebPageOutputOptions, uk.ac.ed.ph.snuggletex.definitions.W3CConstants, uk.ac.ed.ph.snuggletex.internal.util.ObjectUtilities, .XMLUtilities, uk.ac.ed.ph.snuggletex.tokens.FlowToken, uk.ac.ed.ph.snuggletex.utilities.CSSUtilities, .StylesheetManager, java.io.IOException, .OutputStream, .OutputStreamWriter, .StringWriter, java.lang.reflect.Method, java.util.List, .Properties, javax.xml.XMLConstants, javax.xml.transform.OutputKeys, .Transformer, .TransformerException, javax.xml.transform.dom.DOMResult, .DOMSource, javax.xml.transform.stream.StreamResult, org.w3c.dom.Document, .Element

Builds a web page from a List of fixed FlowTokens, using the supplied WebPageOutputOptions to determine the exact form of the results.
Author
David McKain
Version
$Revision$

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_MATHJAX_URL

Default URL and config to use when MathJax configuration option has been enabled.

private final WebPageOutputOptions
private final SessionContext

Constructor Summary

AccessConstructor and Description
public
WebPageBuilder(final SessionContext sessionContext, final WebPageOutputOptions options)

Method Summary

Modifier and TypeMethod and Description
public final Document
buildWebPage(final List<FlowToken> fixedTokens)

public final String
buildWebPageString(final List<FlowToken> fixedTokens)

private String
computeContentTypeHeader()

Computes the appropriate "Content-Type" string to be specified as an HTTP Header.

private String
computeMetaContentType()

Computes the appropriate "Content-Type" string to be specified as an the XHTML meta element.

private final Transformer
private Element
createXHTMLElement(Document document, String elementLocalName)

Helper to create XHTML elements, setting the correct namespace prefix if required by the underlyingWebPageOutputOptions.

private Element
createXHTMLElement(Document document, String elementLocalName, String content)

Helper to create XHTML text elements, setting the correct namespace prefix if required by the underlyingWebPageOutputOptions.

public final void
setWebPageContentType(Object
Object that will have its contentType property set if provided.
contentTypeSettable
)

Calls the setContentType method for the given Object (by reflection) to something appropriate for serving the types of web pages generated by this builder over HTTP.

public final void
writeWebPage(final List<FlowToken>
fixed Tokens from earlier stages of parsing
fixedTokens
,
Object
optional bean Object that will have its contentType property set if provided. (This is generally useful as a proxy for the HttpResponse Object in the servlet API, which I want to avoid a compile-time dependency on.)
contentTypeSettable
,
final OutputStream
Stream to send the resulting page to, which will be closed afterwards.
outputStream
,
final SnuggleSession.EndOutputAction
specifies what to do with the outputStream once we've finished writing to it.
endOutputOptions
)

Creates a web page representing the given (fixed) Tokens, and writes the results to the given OutputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MATHJAX_URLback to summary
public static final String DEFAULT_MATHJAX_URL

Default URL and config to use when MathJax configuration option has been enabled.

optionsback to summary
private final WebPageOutputOptions options
sessionContextback to summary
private final SessionContext sessionContext

Constructor Detail

WebPageBuilderback to summary
public WebPageBuilder(final SessionContext sessionContext, final WebPageOutputOptions options)

Method Detail

buildWebPageback to summary
public final Document buildWebPage(final List<FlowToken> fixedTokens) throws SnuggleParseException
buildWebPageStringback to summary
public final String buildWebPageString(final List<FlowToken> fixedTokens) throws SnuggleParseException
computeContentTypeHeaderback to summary
private String computeContentTypeHeader()

Computes the appropriate "Content-Type" string to be specified as an HTTP Header. (Note that MathPlayer only sniffs a limited number of Content Types.)

computeMetaContentTypeback to summary
private String computeMetaContentType()

Computes the appropriate "Content-Type" string to be specified as an the XHTML meta element.

See Also
computeContentTypeHeader()
createSerializerback to summary
private final Transformer createSerializer()
Exceptions
SnuggleRuntimeException:
if a serializer cannot be created.
createXHTMLElementback to summary
private Element createXHTMLElement(Document document, String elementLocalName)

Helper to create XHTML elements, setting the correct namespace prefix if required by the underlyingWebPageOutputOptions.

createXHTMLElementback to summary
private Element createXHTMLElement(Document document, String elementLocalName, String content)

Helper to create XHTML text elements, setting the correct namespace prefix if required by the underlyingWebPageOutputOptions.

setWebPageContentTypeback to summary
public final void setWebPageContentType(Object contentTypeSettable)

Calls the setContentType method for the given Object (by reflection) to something appropriate for serving the types of web pages generated by this builder over HTTP.

(The main example for this would be passing a javax.servlet.http.HttpResponse Object, which I want to avoid a compile-time dependency on.)

Parameters
contentTypeSettable:Object

Object that will have its contentType property set if provided.

writeWebPageback to summary
public final void writeWebPage(final List<FlowToken> fixedTokens, Object contentTypeSettable, final OutputStream outputStream, final SnuggleSession.EndOutputAction endOutputOptions) throws SnuggleParseException, IOException

Creates a web page representing the given (fixed) Tokens, and writes the results to the given OutputStream.

Parameters
fixedTokens:List<FlowToken>

fixed Tokens from earlier stages of parsing

contentTypeSettable:Object

optional bean Object that will have its contentType property set if provided. (This is generally useful as a proxy for the HttpResponse Object in the servlet API, which I want to avoid a compile-time dependency on.)

outputStream:OutputStream

Stream to send the resulting page to, which will be closed afterwards.

endOutputOptions:SnuggleSession.EndOutputAction

specifies what to do with the outputStream once we've finished writing to it.

Exceptions
SnuggleRuntimeException:
if calling setContentType() on the contentTypeSettable Object failed, with the underlying Exception wrapped up.