public final class XMLTools extends Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
XMLTools.XMLListener
ErrorListener implementation that logs errors and warnings using SLF4J.
|
Modifier and Type | Field and Description |
---|---|
private static SchemaFactory |
FACTORY |
(package private) static org.slf4j.Logger |
LOGGER |
private static ThreadLocal<HashMap<URI,Schema>> |
schemas |
private static TransformerFactory |
transformFactory |
private static String |
XML_SCHEMA_PATH |
private static String |
XSI_NS |
Modifier | Constructor and Description |
---|---|
private |
XMLTools() |
Modifier and Type | Method and Description |
---|---|
static String |
avoidUndeclaredNamespaces(String xml)
Replaces NS:tag with NS_tag for undeclared namespaces
|
private static void |
checkUTF8(InputStream is)
Checks the given stream for a UTF-8 BOM header, skipping it if present.
|
static DocumentBuilder |
createBuilder()
|
static Document |
createDocument()
Calls
DocumentBuilder.newDocument() on a
new builder . |
private static TransformerFactory |
createTransformFactory() |
static String |
dumpXML(String schemaLocation,
Document doc,
Element r)
Dumps the given OME-XML DOM tree to a string.
|
static String |
dumpXML(String schemaLocation,
Document doc,
Element r,
boolean includeXMLDeclaration)
Dumps the given OME-XML DOM tree to a string.
|
static String |
escapeXML(String s)
Escape special characters.
|
static Templates |
getStylesheet(String resourcePath,
Class<?> sourceClass)
Gets an XSLT template from the given resource location.
|
static String |
getXML(Document doc)
Converts the given DOM back to a string.
|
static String |
indentXML(String xml)
Indents XML to be more readable.
|
static String |
indentXML(String xml,
boolean preserveCData)
Indents XML to be more readable, avoiding any whitespace
injection into CDATA if the preserveCData flag is set.
|
static String |
indentXML(String xml,
int spacing)
Indents XML by the given spacing to be more readable.
|
static String |
indentXML(String xml,
int spacing,
boolean preserveCData)
Indents XML by the given spacing to be more readable, avoiding any
whitespace injection into CDATA if the preserveCData flag is set.
|
static Document |
parseDOM(File file)
Parses a DOM from the given XML file on disk.
|
static Document |
parseDOM(InputStream is)
Parses a DOM from the given XML input stream.
|
static Document |
parseDOM(String xml)
Parses a DOM from the given XML string.
|
static void |
parseXML(byte[] xml,
DefaultHandler handler)
Parses the XML contained in the given byte array into
using the specified XML handler.
|
static void |
parseXML(InputStream xml,
DefaultHandler handler)
Parses the XML contained in the given InputStream using the
specified XML handler.
|
static void |
parseXML(RandomAccessInputStream stream,
DefaultHandler handler)
Parses the XML contained in the given input stream into
using the specified XML handler.
|
static Hashtable<String,String> |
parseXML(String xml)
Parses the given XML string into a list of key/value pairs.
|
static void |
parseXML(String xml,
DefaultHandler handler)
Parses the given XML string using the specified XML handler.
|
static String |
sanitizeXML(String s)
Remove invalid characters from an XML string.
|
static String |
transformXML(Source xmlSource,
Templates xslt)
Transforms the given XML data using the specified XSLT stylesheet.
|
static String |
transformXML(String xml,
Templates xslt)
Transforms the given XML string using the specified XSLT stylesheet.
|
static boolean |
validateXML(String xml)
Attempts to validate the given XML string using
Java's XML validation facility.
|
static boolean |
validateXML(String xml,
String label)
Attempts to validate the given XML string using
Java's XML validation facility.
|
static void |
writeXML(OutputStream os,
Document doc)
Writes the specified DOM to the given output stream.
|
static void |
writeXML(OutputStream os,
Document doc,
boolean includeXMLDeclaration)
Writes the specified DOM to the given output stream.
|
static void |
writeXML(Result output,
Document doc,
boolean includeXMLDeclaration)
Writes the specified DOM to the given stream.
|
static final org.slf4j.Logger LOGGER
private static final String XSI_NS
private static final String XML_SCHEMA_PATH
private static final SchemaFactory FACTORY
private static final TransformerFactory transformFactory
private static ThreadLocal<HashMap<URI,Schema>> schemas
private static TransformerFactory createTransformFactory()
public static DocumentBuilder createBuilder()
public static Document createDocument()
DocumentBuilder.newDocument()
on a
new builder
.public static Document parseDOM(File file) throws ParserConfigurationException, SAXException, IOException
public static Document parseDOM(String xml) throws ParserConfigurationException, SAXException, IOException
public static Document parseDOM(InputStream is) throws ParserConfigurationException, SAXException, IOException
public static String getXML(Document doc) throws TransformerConfigurationException, TransformerException
public static String dumpXML(String schemaLocation, Document doc, Element r)
schemaLocation
- if null, no xmlns attribute will be added.public static String dumpXML(String schemaLocation, Document doc, Element r, boolean includeXMLDeclaration)
schemaLocation
- if null, no xmlns attribute will be added.public static String sanitizeXML(String s)
public static String indentXML(String xml, int spacing)
public static String indentXML(String xml, boolean preserveCData)
public static String indentXML(String xml, int spacing, boolean preserveCData)
public static Hashtable<String,String> parseXML(String xml) throws IOException
IOException
public static void parseXML(String xml, DefaultHandler handler) throws IOException
IOException
public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException
IOException
public static void parseXML(byte[] xml, DefaultHandler handler) throws IOException
IOException
public static void parseXML(InputStream xml, DefaultHandler handler) throws IOException
IOException
public static void writeXML(OutputStream os, Document doc) throws TransformerException
TransformerException
public static void writeXML(OutputStream os, Document doc, boolean includeXMLDeclaration) throws TransformerException
TransformerException
public static void writeXML(Result output, Document doc, boolean includeXMLDeclaration) throws TransformerException
TransformerException
public static Templates getStylesheet(String resourcePath, Class<?> sourceClass)
public static String avoidUndeclaredNamespaces(String xml)
public static String transformXML(String xml, Templates xslt) throws IOException
IOException
public static String transformXML(Source xmlSource, Templates xslt) throws IOException
IOException
public static boolean validateXML(String xml)
xml
- The XML string to validate.public static boolean validateXML(String xml, String label)
xml
- The XML string to validate.label
- String describing the type of XML being validated.private static void checkUTF8(InputStream is) throws IOException
We must discard this character because Java does not handle it correctly.
IOException
Copyright © 2016 Open Microscopy Environment