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

public final Class XMLUtilities

extends Object
Class Inheritance
Imports
uk.ac.ed.ph.snuggletex.SerializationSpecifier, .SnuggleRuntimeException, uk.ac.ed.ph.snuggletex.definitions.Globals, uk.ac.ed.ph.snuggletex.utilities.StylesheetManager, java.io.StringWriter, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, javax.xml.transform.OutputKeys, .Transformer, .TransformerFactory, .TransformerFactoryConfigurationError, javax.xml.transform.dom.DOMResult, .DOMSource, javax.xml.transform.stream.StreamResult, org.w3c.dom.Document, .Element, .Node, .NodeList

Some trivial little helpers for creating suitably-configured TransformerFactory instances.

(This is based on similar utility methods in ph-commons.)

Author
David McKain
Version
$Revision$

Field Summary

Modifier and TypeField and Description
public static final String
SAXON_TRANSFORMER_FACTORY_CLASS_NAME

Explicit name of the SAXON 9.X TransformerFactoryImpl Class, as used by the up-conversion extensions

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static TransformerFactory
createJAXPTransformerFactory()

Creates an instance of the currently specified JAXP TransformerFactory, ensuring that the result supports the DOMSource#FEATURE and DOMResult#FEATURE features.

public static DocumentBuilder
createNSAwareDocumentBuilder()

Creates a (namespace-aware) DOM DocumentBuilder, throwing a SnuggleRuntimeException if such a thing cannot be created/configured.

public static TransformerFactory
createSaxonTransformerFactory()

Explicitly creates a Saxon 9 TransformerFactory, as used by the up-conversion extensions.

private static String
public static String
extractTextElementValue(final Element textElement)

Trivial convenience method to extract the value of a (text) Element, coping with the possibility that text child Nodes may not have been coalesced.

public static boolean
public static boolean
isXMLName(String string)

public static boolean
public static void
requireFeature(final TransformerFactory transformerFactory, final String feature)

public static String
serializeNode(final Node
DOM Node to serialize.
node
,
final SerializationSpecifier
XML serialization options
serializationOptions
)

Serializes the given Node to a well-formed external parsed entity.

public static String
serializeNode(StylesheetManager
used to help compile and cache stylesheets used in this process.
stylesheetManager
,
final Node
DOM Node to serialize.
node
,
final SerializationSpecifier
XML serialization options
serializationOptions
)

Serializes the given Node to a well-formed external parsed entity.

public static String
serializeNodeChildren(StylesheetManager
used to help compile and cache stylesheets used in this process.
stylesheetManager
,
final Node
DOM Node to serialize.
node
,
final SerializationSpecifier
XML serialization options
serializationOptions
)

Serializes the children of given Node to a well-formed external parsed entity.

public static void
setIndentation(Transformer
Transformer to configure
transformer
,
int
required indentation, where 0 or more provides indentation and negative numbers turns indentation off.
indent
)

Helper to turn on indentation for a Transformer that works correctly for both Saxon and Xalan.

public static boolean
supportsXSLT20(final TransformerFactory tranformerFactory)

Tests whether the given TransformerFactory is known to support XSLT 2.0.

public static boolean
supportsXSLT20(final Transformer tranformer)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SAXON_TRANSFORMER_FACTORY_CLASS_NAMEback to summary
public static final String SAXON_TRANSFORMER_FACTORY_CLASS_NAME

Explicit name of the SAXON 9.X TransformerFactoryImpl Class, as used by the up-conversion extensions

Constructor Detail

XMLUtilitiesback to summary
public XMLUtilities()

Method Detail

createJAXPTransformerFactoryback to summary
public static TransformerFactory createJAXPTransformerFactory()

Creates an instance of the currently specified JAXP TransformerFactory, ensuring that the result supports the DOMSource#FEATURE and DOMResult#FEATURE features.

createNSAwareDocumentBuilderback to summary
public static DocumentBuilder createNSAwareDocumentBuilder()

Creates a (namespace-aware) DOM DocumentBuilder, throwing a SnuggleRuntimeException if such a thing cannot be created/configured.

createSaxonTransformerFactoryback to summary
public static TransformerFactory createSaxonTransformerFactory()

Explicitly creates a Saxon 9 TransformerFactory, as used by the up-conversion extensions.

ensureExtractTextNodeValueback to summary
private static String ensureExtractTextNodeValue(final Node node)
extractTextElementValueback to summary
public static String extractTextElementValue(final Element textElement)

Trivial convenience method to extract the value of a (text) Element, coping with the possibility that text child Nodes may not have been coalesced.

isSaxonAvailableback to summary
public static boolean isSaxonAvailable()
isXMLNameback to summary
public static boolean isXMLName(String string)
isXMLNCNameback to summary
public static boolean isXMLNCName(String string)
requireFeatureback to summary
public static void requireFeature(final TransformerFactory transformerFactory, final String feature)
serializeNodeback to summary
public static String serializeNode(final Node node, final SerializationSpecifier serializationOptions)

Serializes the given Node to a well-formed external parsed entity. (If the given Node is an Element or a Document then the result will be a well-formed XML String.)

Parameters
node:Node

DOM Node to serialize.

serializationOptions:SerializationSpecifier

XML serialization options

serializeNodeback to summary
public static String serializeNode(StylesheetManager stylesheetManager, final Node node, final SerializationSpecifier serializationOptions)

Serializes the given Node to a well-formed external parsed entity. (If the given Node is an Element or a Document then the result will be a well-formed XML String.)

(This may use an XSLT 2.0 stylesheet to help with named entities, hence the requirement for a StylesheetManager).

Parameters
stylesheetManager:StylesheetManager

used to help compile and cache stylesheets used in this process.

node:Node

DOM Node to serialize.

serializationOptions:SerializationSpecifier

XML serialization options

serializeNodeChildrenback to summary
public static String serializeNodeChildren(StylesheetManager stylesheetManager, final Node node, final SerializationSpecifier serializationOptions)

Serializes the children of given Node to a well-formed external parsed entity.

(This uses a little XSLT stylesheet to help, hence the requirement for a StylesheetManager).

Parameters
stylesheetManager:StylesheetManager

used to help compile and cache stylesheets used in this process.

node:Node

DOM Node to serialize.

serializationOptions:SerializationSpecifier

XML serialization options

setIndentationback to summary
public static void setIndentation(Transformer transformer, int indent)

Helper to turn on indentation for a Transformer that works correctly for both Saxon and Xalan.

Parameters
transformer:Transformer

Transformer to configure

indent:int

required indentation, where 0 or more provides indentation and negative numbers turns indentation off.

supportsXSLT20back to summary
public static boolean supportsXSLT20(final TransformerFactory tranformerFactory)

Tests whether the given TransformerFactory is known to support XSLT 2.0.

(Currently, this involves checking for a suitable version of Saxon; this will change once more processors become available.)

supportsXSLT20back to summary
public static boolean supportsXSLT20(final Transformer tranformer)