public final class SnuggleSession extends Object implements SessionContext
SnuggleEngine.createSession(), optionally passing
configuration details for this session.
parseInput(SnuggleInput) on one or more input documents to tokenise and
fix-up the LaTeX contained therein.
getErrors() to get at the errors that have arisen during this session.
createSnapshot() at any time to make a "snapshot" of the current state for
later reuse.
| Modifier and Type | Class and Description |
|---|---|
static class |
SnuggleSession.EndOutputAction
Trivial enumeration which specifies the possible actions to perform once we
finish writing with the various
writeWebPage(WebPageOutputOptions, OutputStream)
methods. |
| Modifier and Type | Method and Description |
|---|---|
NodeList |
buildDOMSubtree()
Convenience method to build a DOM
NodeList representing the converted Tokens. |
NodeList |
buildDOMSubtree(DOMOutputOptions options)
Convenience method to build a DOM
NodeList representing the converted Tokens. |
boolean |
buildDOMSubtree(Element targetRoot)
Builds a DOM sub-tree based on the currently parsed tokens, appending the results as
children of the given target root Element.
|
boolean |
buildDOMSubtree(Element targetRoot,
DOMOutputOptions options)
Builds a DOM sub-tree based on the currently parsed tokens, appending the results as
children of the given target root Element.
|
Document |
buildWebPage(WebPageOutputOptions options)
Builds a complete web page based on the currently parsed tokens, returning a DOM
Document Object. |
String |
buildWebPageString(WebPageOutputOptions options)
Builds a complete web page based on the currently parsed tokens, returning a String
containing the resulting content.
|
String |
buildXMLString()
Creates a well-formed external general parsed entity out of the currently parsed tokens.
|
String |
buildXMLString(boolean indent)
Deprecated.
Use
buildXMLString(XMLStringOutputOptions) instead |
String |
buildXMLString(DOMOutputOptions options)
Deprecated.
Use
buildXMLString(XMLStringOutputOptions) instead. |
String |
buildXMLString(DOMOutputOptions options,
boolean indent)
Deprecated.
Use
buildXMLString(XMLStringOutputOptions) instead. |
String |
buildXMLString(XMLStringOutputOptions options)
Creates a well-formed external general parsed entity out of the currently parsed tokens.
|
SnuggleSnapshot |
createSnapshot()
Creates a
SnuggleSnapshot Object holding the current state of this session that can
be later used to recreate a session having exactly the same state. |
Document |
createWebPage(WebPageOutputOptions options)
Deprecated.
|
BuiltinCommand |
getBuiltinCommandByTeXName(String texName)
Returns the
BuiltinCommand corresponding to LaTeX command called
\texName, or null if this command is not defined. |
BuiltinEnvironment |
getBuiltinEnvironmentByTeXName(String texName)
Returns the
BuiltinEnvironment corresponding to LaTeX environment
called texName, or null if this environment is not defined. |
SessionConfiguration |
getConfiguration() |
List<InputError> |
getErrors() |
MathCharacter |
getMathCharacter(int codePoint) |
List<FlowToken> |
getParsedTokens() |
StylesheetManager |
getStylesheetManager()
Gets the
StylesheetManager being used by the underlying SnuggleEngine |
Map<String,UserDefinedCommand> |
getUserCommandMap()
Gets the
Map of all user-defined commands created in this session. |
Map<String,UserDefinedEnvironment> |
getUserEnvironmentMap()
Gets the
Map of all user-defined environments created in this session. |
boolean |
parseInput(SnuggleInput snuggleInput)
Parses the data contained within the given
SnuggleInput, and performs fixing
on the resulting tokens. |
void |
registerError(InputError inputError)
Records a new error, throwing a
SnuggleParseException if
the current SessionConfiguration deems that we should
fail on the first error. |
void |
reset()
Resets this
SnuggleSession back to an initial blank state |
void |
setWebPageContentType(WebPageOutputOptions options,
Object contentTypeSettable)
Calls the
setContentType of the given Object to something appropriate for the
given WebPageOutputOptions. |
boolean |
writeWebPage(WebPageOutputOptions options,
Object contentTypeSettable,
OutputStream outputStream)
Builds a complete web page based on the currently parsed tokens, sending the results
to the given
OutputStream, which is closed afterwards. |
boolean |
writeWebPage(WebPageOutputOptions options,
Object contentTypeSettable,
OutputStream outputStream,
SnuggleSession.EndOutputAction endOutputAction)
Builds a complete web page based on the currently parsed tokens, sending the results
to the given
OutputStream and performing the given SnuggleSession.EndOutputAction to
it afterwards (i.e. close, flush or do nothing). |
boolean |
writeWebPage(WebPageOutputOptions options,
OutputStream outputStream)
Builds a complete web page based on the currently parsed tokens, sending the results
to the given
OutputStream, which is closed afterwards. |
boolean |
writeWebPage(WebPageOutputOptions options,
OutputStream outputStream,
SnuggleSession.EndOutputAction endOutputAction)
Builds a complete web page based on the currently parsed tokens, sending the results
to the given
OutputStream and performing the given SnuggleSession.EndOutputAction to
it afterwards (i.e. close, flush or do nothing). |
public SessionConfiguration getConfiguration()
getConfiguration in interface SessionContextpublic List<InputError> getErrors()
getErrors in interface SessionContextpublic boolean parseInput(SnuggleInput snuggleInput) throws IOException
SnuggleInput, and performs fixing
on the resulting tokens.snuggleInput - input to parse, which must not be nullIOExceptionpublic SnuggleSnapshot createSnapshot()
SnuggleSnapshot Object holding the current state of this session that can
be later used to recreate a session having exactly the same state.public void reset()
SnuggleSession back to an initial blank statepublic boolean buildDOMSubtree(Element targetRoot, DOMOutputOptions options)
DOMOutputOptions Object
is used to configure the process.
If the DOMOutputOptions specifies that MathML should be down-converted to
XHTML where possible, then this will also happen.
public boolean buildDOMSubtree(Element targetRoot)
DOMOutputOptions
associated with this engine.public NodeList buildDOMSubtree()
NodeList representing the converted Tokens.
These Nodes will belong to a "fake root" element in the
SnuggleConstants.SNUGGLETEX_NAMESPACE namespace called "root".
The default DOMOutputOptions specified in the SnuggleEngine will be
used.
NodeList if the process completed successfully, null if the process was
terminated by an error in the input LaTeX and if the session was configured to fail on
the first error.public NodeList buildDOMSubtree(DOMOutputOptions options)
NodeList representing the converted Tokens.
These Nodes will belong to a "fake root" element in the
SnuggleConstants.SNUGGLETEX_NAMESPACE namespace called "root".
The given DOMOutputOptions Object is used to configure the process, which must
not be null.
options - DOMOutputOptions to use, which must not be nullNodeList if the process completed successfully, null if the process was
terminated by an error in the input LaTeX and if the session was configured to fail on
the first error.public String buildXMLString()
The default XMLStringOutputOptions specified in the SnuggleEngine will be
used.
public String buildXMLString(XMLStringOutputOptions options)
The given XMLStringOutputOptions Object is used to configure the process.
options - XMLStringOutputOptions to use, which must not be null.@Deprecated public String buildXMLString(boolean indent)
buildXMLString(XMLStringOutputOptions) instead
The default DOMOutputOptions specified in the SnuggleEngine will be
used.
indent - whether to indent the resulting XML or not@Deprecated public String buildXMLString(DOMOutputOptions options)
buildXMLString(XMLStringOutputOptions) instead.
The given DOMOutputOptions Object is used to configure the process.
@Deprecated public String buildXMLString(DOMOutputOptions options, boolean indent)
buildXMLString(XMLStringOutputOptions) instead.
The given DOMOutputOptions Object is used to configure the process.
indent - whether to indent the resulting XML or notpublic Document buildWebPage(WebPageOutputOptions options)
Document Object.
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
Any XSLT stylesheet specified by WebPageOutputOptions.getStylesheets()
will have been applied to the result before it is returned. On the other hand, serialisation
options in the WebPageOutputOptions (such as Content Type and encoding)
will not have been applied when this method returns.
@Deprecated public Document createWebPage(WebPageOutputOptions options)
buildWebPage(WebPageOutputOptions) instead.public String buildWebPageString(WebPageOutputOptions options)
writeWebPage(WebPageOutputOptions, OutputStream) might be more efficient.
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
Any XSLT stylesheet specified by WebPageOutputOptions.getStylesheets()
will have been applied to the result before it is returned. On the other hand, serialisation
options in the WebPageOutputOptions (such as Content Type and encoding)
will not have been applied when this method returns.
public boolean writeWebPage(WebPageOutputOptions options, OutputStream outputStream) throws IOException
OutputStream, which is closed afterwards.
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
IOExceptionpublic boolean writeWebPage(WebPageOutputOptions options, OutputStream outputStream, SnuggleSession.EndOutputAction endOutputAction) throws IOException
OutputStream and performing the given SnuggleSession.EndOutputAction to
it afterwards (i.e. close, flush or do nothing).
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
IOExceptionpublic boolean writeWebPage(WebPageOutputOptions options, Object contentTypeSettable, OutputStream outputStream) throws IOException
OutputStream, which is closed afterwards.
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
If the contentTypeSettable Object has a
property called contentType, then it is set in advance to the appropriate HTTP
Content-Type header for the resulting page before the web page data is written.
IOException - if an I/O problem arose whilst writing out the web page data.SnuggleRuntimeException - if calling setContentType() on the contentTypeSettable
Object failed, with the underlying Exception wrapped up.public boolean writeWebPage(WebPageOutputOptions options, Object contentTypeSettable, OutputStream outputStream, SnuggleSession.EndOutputAction endOutputAction) throws IOException
OutputStream and performing the given SnuggleSession.EndOutputAction to
it afterwards (i.e. close, flush or do nothing).
The provided WebPageOutputOptions Object is
used to determine which type of web page to generate and how it should be configured.
If the contentTypeSettable Object has a
property called contentType, then it is set in advance to the appropriate HTTP
Content-Type header for the resulting page before the web page data is written.
IOException - if an I/O problem arose whilst writing out the web page data.SnuggleRuntimeException - if calling setContentType() on the contentTypeSettable
Object failed, with the underlying Exception wrapped up.public void setWebPageContentType(WebPageOutputOptions options, Object contentTypeSettable)
setContentType of the given Object to something appropriate for the
given WebPageOutputOptions. This may be useful in some cases.
The main example for this would be passing a javax.servlet.http.HttpResponse
Object, which I want to avoid a compile-time dependency on.
public MathCharacter getMathCharacter(int codePoint)
getMathCharacter in interface SessionContextpublic BuiltinCommand getBuiltinCommandByTeXName(String texName)
BuiltinCommand corresponding to LaTeX command called
\texName, or null if this command is not defined.getBuiltinCommandByTeXName in interface SessionContextpublic BuiltinEnvironment getBuiltinEnvironmentByTeXName(String texName)
BuiltinEnvironment corresponding to LaTeX environment
called texName, or null if this environment is not defined.getBuiltinEnvironmentByTeXName in interface SessionContextpublic Map<String,UserDefinedCommand> getUserCommandMap()
Map of all user-defined commands created in this session.getUserCommandMap in interface SessionContextpublic Map<String,UserDefinedEnvironment> getUserEnvironmentMap()
Map of all user-defined environments created in this session.getUserEnvironmentMap in interface SessionContextpublic StylesheetManager getStylesheetManager()
StylesheetManager being used by the underlying SnuggleEnginegetStylesheetManager in interface SessionContextpublic void registerError(InputError inputError) throws SnuggleParseException
SnuggleParseException if
the current SessionConfiguration deems that we should
fail on the first error.registerError in interface SessionContextinputError - InputError to register, which must not be null.SnuggleParseException - if this session is configured to fail fastCopyright © 2008–2026 The University of Edinburgh. All rights reserved.