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

public final Class StylesheetManager

extends Object
Class Inheritance
Imports
uk.ac.ed.ph.snuggletex.SerializationMethod, .SerializationSpecifier, .SnuggleRuntimeException, uk.ac.ed.ph.snuggletex.definitions.Globals, uk.ac.ed.ph.snuggletex.internal.util.ConstraintUtilities, .StringUtilities, .XMLUtilities, java.io.StringReader, java.util.ArrayList, .List, javax.xml.transform.OutputKeys, .Source, .Templates, .Transformer, .TransformerConfigurationException, .TransformerException, .TransformerFactory, javax.xml.transform.stream.StreamSource

Trivial helper class to manage the loading of SnuggleTeX's internal stylesheets, using a StylesheetCache to cache stylesheets for performance.

This has been made "public" as it is used by certain standalone tools, like the MathMLDownConverter, but its use outside SnuggleTeX is perhaps somewhat limited.

This class is thread-safe.

Author
David McKain
Version
$Revision$

Field Summary

Modifier and TypeField and Description
private StylesheetCache
private TransformerFactoryChooser

Constructor Summary

AccessConstructor and Description
public
public
StylesheetManager(StylesheetCache
StylesheetCache to use, which may be null if you don't want to do any caching.
cache
)

Creates a new StylesheetManager using the DefaultTransformerFactoryChooser and the given StylesheetCache.

public
StylesheetManager(TransformerFactoryChooser
TransformerFactoryChooser to use, which must not be null.
transformerFactoryChooser
,
StylesheetCache cache)

Creates a new StylesheetManager using the given TransformerFactoryChooser and StylesheetCache.

Method Summary

Modifier and TypeMethod and Description
private Templates
compileStylesheet(final String classPathUri, final boolean requireXSLT20)

private Templates
compileStylesheetDriver(final List<String> importUris, boolean requireXSLT20)

Compiles a "driver" XSLT stylesheet that imports the stylesheets at the given URIs.

private void
public Templates

Returns:

compiled XSLT stylesheet.
getCompiledStylesheet
(final String
location of the XSLT stylesheet in the ClassPath, following the URI scheme in ClassPathURIResolver.
classPathUri
)

Obtains the XSLT stylesheet at the given ClassPathURI, using the StylesheetCache (if set) to cache stylesheets for efficiency.

public Templates

Returns:

compiled XSLT stylesheet.
getCompiledStylesheet
(final String
location of the XSLT stylesheet in the ClassPath, following the URI scheme in ClassPathURIResolver.
classPathUri
,
final boolean
if false uses the JAXP default TransformerFactory, otherwise specifies that we require an XSLT 2.0-compliant transformer, of which the only currently supported implementation is SAXON 9.x.
requireXSLT20
)

Obtains the XSLT stylesheet at the given ClassPathURI, using the StylesheetCache (if set) to cache stylesheets for efficiency.

public Templates

Returns:

compiled XSLT stylesheet.
getCompiledStylesheetDriver
(final List<String>
List of locations of the XSLT stylesheets to be compiled, following the URI scheme in ClassPathURIResolver.
importClassPathUris
,
final boolean
if false uses the JAXP default TransformerFactory, otherwise specifies that we require an XSLT 2.0-compliant transformer, of which the only currently supported implementation is SAXON 9.x.
requireXSLT20
)

Obtains a "driver" XSLT stylesheet that imports the stylesheets having the given ClassPath URIs, using the StylesheetCache (if set) to cache the resulting driver for efficiency.

public Transformer
getSerializer(final String
URI for the required serializing stylesheet, null for the default serializer.
serializerUri
,
final SerializationSpecifier
desired SerializationSpecifier, null for default options
serializationOptions
)

Obtains a serializer stylesheet based on the stylesheet at the given URI, configured as per the given SerializationSpecifier.

public StylesheetCache
getStylesheetCache()

Returns the current StylesheetCache for this manager, which may be null.

public TransformerFactory
getTransformerFactory(final boolean requireXSLT20)

Uses the current TransformerFactoryChooser to obtain a TransformerFactory suitable for either XSLT 1.0 or XSLT 2.0 (as specified), and configured to use a ClassPathURIResolver to make it easy to find internal stylesheets.

public TransformerFactoryChooser
getTransformerFactoryChooser()

Returns the current TransformerFactoryChooser for this StylesheetManager, which is used to initialise TransformerFactory instances.

public void
setStylesheetCache(StylesheetCache stylesheetCache)

Sets the StylesheetCache for this manager, which may be null to indicate that no caching should take place.

public void
setTransformerFactoryChooser(TransformerFactoryChooser
new TransformerFactoryChooser, which must not be null.
transformerFactoryChooser
)

Sets the TransformerFactoryChooser for this StylesheetManager, which is used to initialise TransformerFactory instances.

public boolean
supportsXSLT20()

Returns whether or not XSLT 2.0 is supported, by asking the underlying TransformerFactoryChooser.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stylesheetCacheback to summary
private StylesheetCache stylesheetCache
transformerFactoryChooserback to summary
private TransformerFactoryChooser transformerFactoryChooser

Constructor Detail

StylesheetManagerback to summary
public StylesheetManager()

Creates a new StylesheetManager using the DefaultTransformerFactoryChooser and no StylesheetCache.

StylesheetManagerback to summary
public StylesheetManager(StylesheetCache cache)

Creates a new StylesheetManager using the DefaultTransformerFactoryChooser and the given StylesheetCache.

Parameters
cache:StylesheetCache

StylesheetCache to use, which may be null if you don't want to do any caching.

StylesheetManagerback to summary
public StylesheetManager(TransformerFactoryChooser transformerFactoryChooser, StylesheetCache cache)

Creates a new StylesheetManager using the given TransformerFactoryChooser and StylesheetCache.

Parameters
transformerFactoryChooser:TransformerFactoryChooser

TransformerFactoryChooser to use, which must not be null.

Method Detail

compileStylesheetback to summary
private Templates compileStylesheet(final String classPathUri, final boolean requireXSLT20)
compileStylesheetDriverback to summary
private Templates compileStylesheetDriver(final List<String> importUris, boolean requireXSLT20)

Compiles a "driver" XSLT stylesheet that imports the stylesheets at the given URIs.

ensureChooserSpecifiedback to summary
private void ensureChooserSpecified()
getCompiledStylesheetback to summary
public Templates getCompiledStylesheet(final String classPathUri)

Obtains the XSLT stylesheet at the given ClassPathURI, using the StylesheetCache (if set) to cache stylesheets for efficiency.

Parameters
classPathUri:String

location of the XSLT stylesheet in the ClassPath, following the URI scheme in ClassPathURIResolver.

Returns:Templates

compiled XSLT stylesheet.

getCompiledStylesheetback to summary
public Templates getCompiledStylesheet(final String classPathUri, final boolean requireXSLT20)

Obtains the XSLT stylesheet at the given ClassPathURI, using the StylesheetCache (if set) to cache stylesheets for efficiency.

Parameters
classPathUri:String

location of the XSLT stylesheet in the ClassPath, following the URI scheme in ClassPathURIResolver.

requireXSLT20:boolean

if false uses the JAXP default TransformerFactory, otherwise specifies that we require an XSLT 2.0-compliant transformer, of which the only currently supported implementation is SAXON 9.x.

Returns:Templates

compiled XSLT stylesheet.

getCompiledStylesheetDriverback to summary
public Templates getCompiledStylesheetDriver(final List<String> importClassPathUris, final boolean requireXSLT20)

Obtains a "driver" XSLT stylesheet that imports the stylesheets having the given ClassPath URIs, using the StylesheetCache (if set) to cache the resulting driver for efficiency.

Parameters
importClassPathUris:List<String>

List of locations of the XSLT stylesheets to be compiled, following the URI scheme in ClassPathURIResolver.

requireXSLT20:boolean

if false uses the JAXP default TransformerFactory, otherwise specifies that we require an XSLT 2.0-compliant transformer, of which the only currently supported implementation is SAXON 9.x.

Returns:Templates

compiled XSLT stylesheet.

getSerializerback to summary
public Transformer getSerializer(final String serializerUri, final SerializationSpecifier serializationOptions)

Obtains a serializer stylesheet based on the stylesheet at the given URI, configured as per the given SerializationSpecifier. (Some options may require XSLT 2.0 support.)

Parameters
serializerUri:String

URI for the required serializing stylesheet, null for the default serializer.

serializationOptions:SerializationSpecifier

desired SerializationSpecifier, null for default options

Exceptions
SnuggleRuntimeException:
if the serializer could not be created, or if an XSLT 2.0 processor was required but could not be obtained.
getStylesheetCacheback to summary
public StylesheetCache getStylesheetCache()

Returns the current StylesheetCache for this manager, which may be null.

getTransformerFactoryback to summary
public TransformerFactory getTransformerFactory(final boolean requireXSLT20)

Uses the current TransformerFactoryChooser to obtain a TransformerFactory suitable for either XSLT 1.0 or XSLT 2.0 (as specified), and configured to use a ClassPathURIResolver to make it easy to find internal stylesheets.

getTransformerFactoryChooserback to summary
public TransformerFactoryChooser getTransformerFactoryChooser()

Returns the current TransformerFactoryChooser for this StylesheetManager, which is used to initialise TransformerFactory instances. This is never null.

setStylesheetCacheback to summary
public void setStylesheetCache(StylesheetCache stylesheetCache)

Sets the StylesheetCache for this manager, which may be null to indicate that no caching should take place.

setTransformerFactoryChooserback to summary
public void setTransformerFactoryChooser(TransformerFactoryChooser transformerFactoryChooser)

Sets the TransformerFactoryChooser for this StylesheetManager, which is used to initialise TransformerFactory instances.

Parameters
transformerFactoryChooser:TransformerFactoryChooser

new TransformerFactoryChooser, which must not be null.

supportsXSLT20back to summary
public boolean supportsXSLT20()

Returns whether or not XSLT 2.0 is supported, by asking the underlying TransformerFactoryChooser.