Novell exteNd
Director 5.2 API

com.novell.afw.util
Class EboXmlUtil

java.lang.Object
 |
 +--com.novell.afw.util.EboXmlUtil

public final class EboXmlUtil
extends Object

Utilities for dealing with XML

Since:
v.5.0

Constructor Summary
EboXmlUtil()
           
 
Method Summary
static Node addDirectiveToXSL(Document xslDom, String directiveName, String attributeName, String attributeValue)
          Add an xsl:import or xsl:include etc.
static Node addDirectiveToXSLBeforeSibling(Node sibling, String directiveName, String attributeName, String attributeValue)
          Add an xsl:import or xsl:include node to an existing xsl style sheet (represented as DOM) before the passed sibling node
static Node addNodeAfterSibling(Node siblingNode, String nodeName, Node content)
          create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node; both Nodes need to be part of the same document
static Node addNodeAfterSibling(Node siblingNode, String nodeName, Node content, boolean contentIsLocal)
          create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node
static Node addNodeBeforeSibling(Node siblingNode, String nodeName, Node content)
          create a new Element with nodeName and insert it before the siblingNode (same level)
static Node addNodeBeforeSibling(Node siblingNode, String nodeName, Node content, boolean contentIsLocal)
          create a new Element with nodeName and insert it before the siblingNode (same level); if the node name is null, insert the content node before the sibling node
static Node appendChildNode(Node parentNode, Node contentNode)
          import a node into the current document directly under the passed parent Node
static Node appendChildNode(Node parentNode, Node contentNode, boolean contentIsLocal)
          import a node into the current document directly under the passed parent Node
static Attr createAttribute(Document doc, String attributeName, String attributeValue)
          create an attribute standalone (not added to any node)
static Attr createAttribute(Element el, String attributeName, String attributeValue)
          create an attribute and add it to the Node provided
static Node createCDATANode(Node parentNode, String nodeName, String content)
          create a CDATA section as a child to the provided parentNode In case the content is null, a child node without content will be created, using createChildNode()
static Node createChildNode(Node parentNode, String nodeName)
          Create a child node and append it to the provided parent node
static Node createChildNode(Node parentNode, String nodeName, Node contentNode)
          create a child node (to parentNode) and populate it with the delivered content (if != null)
static Node createChildNode(Node parentNode, String nodeName, Node contentNode, boolean contentIsLocal)
          create a child node (to parentNode) and populate it with the delivered content (if != null)
static Document createDocument()
          create a new org.w3c.dom.Document with validation turned off and name space awareness turned on
static Document createDocument(byte[] bytes)
          create a Document from a byte[]
static Document createDocument(InputSource inputSrc, boolean isValidating, boolean isNamespaceAware, ErrorHandler errorHandler, EntityResolver entityResolver)
          Creates a new Document from an InputSource allowing the validation, namespace, error handler and entity resolver to be set.
static Document createDocument(InputStream stream)
          create a Document from a String representation (with name space awareness on and validation off)
static Document createDocument(InputStream stream, String encoding, boolean validation, boolean namespace)
          create a Document from a stream representation of the XML content use the requested char-set encoding, validation and name space awareness
static Document createDocument(Reader reader, boolean validation, boolean namespace)
          create a Document from a reader representation of the XML content use the requested validation and name space awareness
static Document createDocument(String strDoc)
          Creates a Document from a String representing a valid XML document (no validation, but name space aware)
static Document createDocument(URL documentURL)
          create a Document from a URL (get the content from the URL); name space aware, but no validation
static Node createDocumentRootNode(Document parentDocument, String nodeName, Node contentNode)
          create a child node (to parentDocument) and populate it with the delivered content (if != null)
static Node createDocumentRootNode(Document parentDocument, String nodeName, Node contentNode, boolean contentIsLocal)
          create a child node (to parentDocument) and populate it with the delivered content (if != null)
static Node createNode(Document document, String nodeName, Node contentNode)
          create a Node standalone (not added to any parent)
static Node createNode(Document document, String nodeName, Node contentNode, boolean contentIsLocal)
          create a Node standalone (not added to any parent)
static Node createTextNode(Document doc, Node parentNode, String nodeName, String content)
          create a text node
static Node createTextNode(Node parentNode, String nodeName, String content)
          create a text node
static Attr getAttribute(String attributeName, Node node)
          get an attribute of a node (if present)
static String getAttributeValue(String attributeName, Node node)
          get the value of an attribute of a node (if present)
static DocumentBuilder getBuilder()
          get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory validation turned off and name space awareness turned on if you need a DocumentBuilder with different features, use the getBuilder(boolean validation, boolean nameSpaceAware) method (this method will cache the DocumentBuilder after the fist hit
static DocumentBuilder getBuilder(boolean validation, boolean nameSpaceAware)
          get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory
static String getElementBodyText(Node parentNode)
          get the text from an elements body example get 'hello world' from hello world
static Templates getTemplates(Source source)
          compile the provided style sheet into templates
static Transformer getTransformer()
          get a new Transformer from the TransformerFactory with indent turned on
static Transformer getTransformer(Document doc)
          get a new Transformer for the passed Document (the xsl) from the TransformerFactory with indent turned on
static Transformer getTransformer(Properties transProps)
          get a new Transformer from the TransformerFactory with the passed output properties
static Transformer getTransformer(Source strSource)
          get a new Transformer for the passed Source (the xsl) from the TransformerFactory with indent turned on
static Transformer getTransformer(Templates templates)
          get a new Transformer for the passed compiled xsl template (with indent turned on)
static String serialize(Node doc)
          serialize a Document to String (using a Transformer) This call uses a javax.xml.transform.Transformer, and it's output encoding to convert the content to a String (default is UTF-8) If you want to use a different encoding, get a transformer via #getTransformer(Properties) and set the output property "encoding" to the desired one, then use #serialize(Node, Transformer)
static void serialize(Node doc, OutputStream output)
          serialize a Document to the provided OutputStream (using a Transformer)
static void serialize(Node doc, OutputStream output, Transformer transformer)
          serialize a Document to the provided OutputStream (using the passed Transformer)
static String serialize(Node doc, Transformer transformer)
          serialize a Document to String (using the passed Transformer) This call uses the transformer's output encoding to convert the content to a String
static void serialize(Node doc, Writer writer)
          serialize a Document to the provided Writer (using a Transformer)
static void serialize(Node doc, Writer writer, Transformer transformer)
          serialize a Document to the provided Writer (using a Transformer) This call uses the transformer's output encoding to convert the content to a String (default is UTF-8)
static void xslTransform(Document contentDom, Document styleDom, Writer out)
          Transforms an xml with the provided xsl document and writes it to the writer.
static String xslTransform(Document contentDom, Transformer transformer, OutputStream out)
          Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
static void xslTransform(Document contentDom, Transformer transformer, Writer writer)
          Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EboXmlUtil

public EboXmlUtil()
Method Detail

getBuilder

public static DocumentBuilder getBuilder()
                                  throws ParserConfigurationException
get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory validation turned off and name space awareness turned on if you need a DocumentBuilder with different features, use the getBuilder(boolean validation, boolean nameSpaceAware) method (this method will cache the DocumentBuilder after the fist hit
Returns:
javax.xml.parsers.DocumentBuilder
Throws:
ParserConfigurationException -  
Since:
v.5.0

getBuilder

public static DocumentBuilder getBuilder(boolean validation,
                                         boolean nameSpaceAware)
                                  throws ParserConfigurationException
get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory
Parameters:
validation - true if validation should be turned on, otherwise use false
nameSpaceAware - true if name space awareness should be turned on, otherwise use false
Returns:
a DocumentBuilder to create Documents
Throws:
ParserConfigurationException - if the underlying parser does
Since:
v.5.0

createDocument

public static Document createDocument()
                               throws ParserConfigurationException
create a new org.w3c.dom.Document with validation turned off and name space awareness turned on
Returns:
the created org.w3c.dom.Document
Throws:
ParserConfigurationException - if the underlying parser does
Since:
v.5.0

createDocument

public static Document createDocument(String strDoc)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
Creates a Document from a String representing a valid XML document (no validation, but name space aware)
Parameters:
strDoc - the string representing the xml
Returns:
the created Document
Throws:
DOMException - if the provided string does not represent a valid xml document
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the passed string is null
Since:
v.5.0

createDocument

public static Document createDocument(InputStream stream)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
create a Document from a String representation (with name space awareness on and validation off)
Parameters:
stream - the InputStream that represents the XML Content
Returns:
a Document representing the same content
Throws:
DOMException - if the InputSource does not represent a valid XML document
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the provided InputSource is null
Since:
v.5.0

createDocument

public static Document createDocument(byte[] bytes)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
create a Document from a byte[]
Parameters:
byte[] - that represents the XML Content
Returns:
a Document representing the same content
Throws:
DOMException - if the InputSource does not represent a valid XML document
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the provided InputSource is null
Since:
v.5.2

createDocument

public static Document createDocument(InputStream stream,
                                      String encoding,
                                      boolean validation,
                                      boolean namespace)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
create a Document from a stream representation of the XML content use the requested char-set encoding, validation and name space awareness
Parameters:
stream - the stream (InputStream,...) to represent the XML
encoding - the Char encoding that should be used to read from the stream
namespace - use namespace awareness (true) , or not (false)
validation - use validation (true), or not (false)
Returns:
a Document representing the same XML content in form of a DOM
Throws:
DOMException -  
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the provided InputSource or encoding is null
Since:
v.5.0

createDocument

public static Document createDocument(Reader reader,
                                      boolean validation,
                                      boolean namespace)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
create a Document from a reader representation of the XML content use the requested validation and name space awareness
Parameters:
reader - the reader pointing to the 'raw' xml
namespace - use namespace awareness (true) , or not (false)
validation - use validation (true), or not (false)
Returns:
a Document representing the same XML content in form of a DOM
Throws:
DOMException -  
IOException - if the reader doesn't allow successfull access
SAXException -  
ParserConfigurationException - if the underlying parser does
Since:
v.5.0

createDocument

public static Document createDocument(URL documentURL)
                               throws IOException,
                                      SAXException,
                                      ParserConfigurationException
create a Document from a URL (get the content from the URL); name space aware, but no validation
Parameters:
documentURL - the URL pointing to the Document
Returns:
a Document representing the document content
Throws:
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the provided URL is null
Since:
v.5.0

createDocument

public static Document createDocument(InputSource inputSrc,
                                      boolean isValidating,
                                      boolean isNamespaceAware,
                                      ErrorHandler errorHandler,
                                      EntityResolver entityResolver)
                               throws DOMException,
                                      IOException,
                                      SAXException,
                                      ParserConfigurationException
Creates a new Document from an InputSource allowing the validation, namespace, error handler and entity resolver to be set.
Parameters:
inputSrc - the InputSource representing the xml
isValidating - the boolean determining if validating is used against the xml
isNamespaceAware - the boolean determining if the NameSpaceAware feature is set
errorHandler - the ErrorHandler to be used if supplied
entityResolver - the entityResolver to be used if supplied
Returns:
a Document
Throws:
DOMException -  
IOException -  
SAXException -  
ParserConfigurationException - if the underlying parser does
IllegalArgumentException - if the provided InputSource is null
Since:
v.5.0

createDocumentRootNode

public static Node createDocumentRootNode(Document parentDocument,
                                          String nodeName,
                                          Node contentNode)
create a child node (to parentDocument) and populate it with the delivered content (if != null)
Parameters:
parentDocument - the Document that will receive the new Element and the content
nodeName - the name of the Element to create
contentNode - the Node that will be appended as a child to the created Element
Returns:
the created Node
Throws:
IllegalArgumentException - if the document or the node name is null
Since:
v.5.0

createDocumentRootNode

public static Node createDocumentRootNode(Document parentDocument,
                                          String nodeName,
                                          Node contentNode,
                                          boolean contentIsLocal)
create a child node (to parentDocument) and populate it with the delivered content (if != null)
Parameters:
parentDocument - the Document that will receive the new Element and the content
nodeName - the name of the Element to create
contentNode - the Node that will be imported (if external) or appended (if local) as a child to the created Element (incl. subtree)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the created Element
Throws:
IllegalArgumentException - if the document or the node name is null
Since:
v.5.0

createNode

public static Node createNode(Document document,
                              String nodeName,
                              Node contentNode)
create a Node standalone (not added to any parent)
Parameters:
document - Document used to create the Element (not null!)
nodeName - name of the node to be created (not null!)
contentNode - content in form of a Node to be appended as child (if not null) ; including the subtree
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the document or the node name is null
Since:
v.5.0

createNode

public static Node createNode(Document document,
                              String nodeName,
                              Node contentNode,
                              boolean contentIsLocal)
create a Node standalone (not added to any parent)
Parameters:
document - Document used to create the Element (not null!)
nodeName - name of the node to be created (not null!)
contentNode - content in form of a Node to be imported or appended as child (if not null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the document or the node name is null
Since:
v.5.0

createChildNode

public static Node createChildNode(Node parentNode,
                                   String nodeName,
                                   Node contentNode)
create a child node (to parentNode) and populate it with the delivered content (if != null)
Parameters:
parentNode - the parent Node (not null!)
nodeName - the name for the new Element (not null!)
contentNode - org.w3c.dom.Node that contains the content to be appended (incl. subtree) to the parent Document (or null)
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the parent node or the node name is null
Since:
v.5.0

createChildNode

public static Node createChildNode(Node parentNode,
                                   String nodeName,
                                   Node contentNode,
                                   boolean contentIsLocal)
create a child node (to parentNode) and populate it with the delivered content (if != null)
Parameters:
parentNode - the parent Node (not null!)
nodeName - the name for the new Element (not null!)
contentNode - org.w3c.dom.Node that contains the content to be imported (incl. subtree) or appended (if local) to the parent Document (or null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the parent node or the node name is null
Since:
v.5.0

createChildNode

public static Node createChildNode(Node parentNode,
                                   String nodeName)
Create a child node and append it to the provided parent node
Parameters:
nodeName - the name for the new node
parentNode - the parent org.w3c.dom.Node that will receive the child
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the parent node or the node name is null
Since:
v.5.0

createTextNode

public static Node createTextNode(Document doc,
                                  Node parentNode,
                                  String nodeName,
                                  String content)
create a text node
Parameters:
doc - the Document to contain the new text node (not null!)
parentNode - the Node under which the new text node should be placed (or null)
nodeName - the name of the new text node (not null!)
content - the text itself
Returns:
the newly created Node
Throws:
IllegalArgumentException - if either the document, or the node name and the parent node are null
Since:
v.5.0

createTextNode

public static Node createTextNode(Node parentNode,
                                  String nodeName,
                                  String content)
create a text node
Parameters:
parentNode - the Node under which the new text node should be placed (not null!)
nodeName - the name of the new text node (not null!)
content - the text itself
Returns:
the newly created Node
Throws:
IllegalArgumentException - if the parent node is null
Since:
v.5.0

createAttribute

public static Attr createAttribute(Element el,
                                   String attributeName,
                                   String attributeValue)
create an attribute and add it to the Node provided
Parameters:
el - the element that will receive the attribute (not null!)
attributeName - name of the attribute to be created (not null!)
attributeValue - value of the attribute to be created
Returns:
the created attribute as Attr
Throws:
IllegalArgumentException - if the element or the attribute name is null
Since:
v.5.0

createAttribute

public static Attr createAttribute(Document doc,
                                   String attributeName,
                                   String attributeValue)
create an attribute standalone (not added to any node)
Parameters:
doc - the Document used to create the attribute
attributeName - name of the attribute to be created
attributeValue - value of the attribute to be created
Returns:
the Attribute as org.w3c.dom.Attr
Throws:
IllegalArgumentException - if the document or the attribute name is null
Since:
v.5.0

getAttributeValue

public static String getAttributeValue(String attributeName,
                                       Node node)
get the value of an attribute of a node (if present)
Parameters:
attributeName - the name of the attribute you want to get
node - the Node where the attribute lives
Returns:
the value of the attribute, or null if not present
Throws:
IllegalArgumentException - if the attribute name or the node is null
Since:
v.5.0

getAttribute

public static Attr getAttribute(String attributeName,
                                Node node)
get an attribute of a node (if present)
Parameters:
attributeName - the name of the attribute you want to get
node - the Node where the attribute lives
Returns:
the attribute, or null if not present on the node
Throws:
IllegalArgumentException - if the attribute name or the node is null
Since:
v.5.0

getElementBodyText

public static String getElementBodyText(Node parentNode)
get the text from an elements body example get 'hello world' from hello world
Parameters:
parentNode - the node that contains text
Returns:
the text inside the element and end element tags if the node is a text node, otherwise an empty string
Throws:
DOMException - if the undelying DOM api does
Since:
v.5.2

createCDATANode

public static Node createCDATANode(Node parentNode,
                                   String nodeName,
                                   String content)
create a CDATA section as a child to the provided parentNode In case the content is null, a child node without content will be created, using createChildNode()
Parameters:
parentNode - Node (parent) of the element to be created (not null!)
nodeName - the name you want to give your Node (or null if the textnode should be appended to the parent node directly)
content - the content of the node (the text that will be wrapped in a CDATA section)
Returns:
the org.w3c.dom.Node that was created
Throws:
IllegalArgumentException - if the parent node is null
Since:
v.5.0
See Also:
EboXmlUtil.createChildNode(Node,String)

addNodeBeforeSibling

public static Node addNodeBeforeSibling(Node siblingNode,
                                        String nodeName,
                                        Node content)
create a new Element with nodeName and insert it before the siblingNode (same level)
Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted before this node
nodeName - the name of the element to create
content - any subtree that will be appended as child of the new element (if != null)
Returns:
the newly created element as a Node
Throws:
IllegalArgumentException - if the sibling node or the node name is null
Since:
v.5.0

addNodeBeforeSibling

public static Node addNodeBeforeSibling(Node siblingNode,
                                        String nodeName,
                                        Node content,
                                        boolean contentIsLocal)
create a new Element with nodeName and insert it before the siblingNode (same level); if the node name is null, insert the content node before the sibling node
Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted before this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created element as a Node
Throws:
IllegalArgumentException - if the sibling node is null or the node name and the content is null
Since:
v.5.0

addNodeAfterSibling

public static Node addNodeAfterSibling(Node siblingNode,
                                       String nodeName,
                                       Node content)
create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node; both Nodes need to be part of the same document
Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted after this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
Returns:
the newly created element as a Node
Throws:
IllegalArgumentException - if the sibling node is null or the node name and the content is null
Since:
v.5.0

addNodeAfterSibling

public static Node addNodeAfterSibling(Node siblingNode,
                                       String nodeName,
                                       Node content,
                                       boolean contentIsLocal)
create a new Element with nodeName and insert it after the siblingNode (same level); if the node name is null, insert the content node after the sibling node
Parameters:
siblingNode - the node that will be used as reference; the new element will be inserted after this node
nodeName - the name of the element to create (or null; if null, content needs to be not null!)
content - any subtree that will be imported or appended (if local) as child of the new element (if != null)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the newly created element as a Node
Throws:
IllegalArgumentException - if the sibling node is null or the node name and the content is null
Since:
v.5.0

appendChildNode

public static Node appendChildNode(Node parentNode,
                                   Node contentNode)
import a node into the current document directly under the passed parent Node
Parameters:
parentNode - the Node under which the content should be placed (not null!)
contentNode - the Node (not null!) that will be imported as a child to the created Node (incl. subtree)
Returns:
the Node representing the imported content in the current dom
Throws:
IllegalArgumentException - if the parent node or the content node is null
Since:
v.5.0

appendChildNode

public static Node appendChildNode(Node parentNode,
                                   Node contentNode,
                                   boolean contentIsLocal)
import a node into the current document directly under the passed parent Node
Parameters:
parentNode - the Node under which the content should be placed (not null!)
contentNode - the Node (not null!) that will be imported as a child to the created Node (incl. subtree)
contentIsLocal - a boolean indicating wether the contentNode is external to the document and has to be imported (false), or if it can be appended (true)
Returns:
the Node representing the imported content in the current dom (or the passed in contentNode if it's local)
Throws:
IllegalArgumentException - if the parent node or the content node is null
Since:
v.5.0

serialize

public static void serialize(Node doc,
                             OutputStream output)
                      throws IOException,
                             TransformerConfigurationException,
                             TransformerException
serialize a Document to the provided OutputStream (using a Transformer)
Parameters:
doc - Document (-fragment) to be serialized
output - the OutputStream to write to
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the output stream or the document is null
Since:
v.5.0

serialize

public static void serialize(Node doc,
                             OutputStream output,
                             Transformer transformer)
                      throws IOException,
                             TransformerConfigurationException,
                             TransformerException
serialize a Document to the provided OutputStream (using the passed Transformer)
Parameters:
doc - Document (-fragment) to be serialized
output - the OutputStream to write to
transformer - the transformer to use
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the output stream or the document or the transformer is null
Since:
v.5.0

serialize

public static void serialize(Node doc,
                             Writer writer)
                      throws IOException,
                             TransformerConfigurationException,
                             TransformerException
serialize a Document to the provided Writer (using a Transformer)
Parameters:
doc - Document (-fragment) to be serialized
writer - the writer to write to
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the document or the writer is null
Since:
v.5.0

serialize

public static void serialize(Node doc,
                             Writer writer,
                             Transformer transformer)
                      throws IOException,
                             TransformerConfigurationException,
                             TransformerException
serialize a Document to the provided Writer (using a Transformer) This call uses the transformer's output encoding to convert the content to a String (default is UTF-8)
Parameters:
doc - Document (-fragment) to be serialized
writer - the writer to write to
transformer - the transformer to use
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the document or the writer or the transformer is null
Since:
v.5.0

serialize

public static String serialize(Node doc)
                        throws IOException,
                               TransformerConfigurationException,
                               TransformerException
serialize a Document to String (using a Transformer) This call uses a javax.xml.transform.Transformer, and it's output encoding to convert the content to a String (default is UTF-8) If you want to use a different encoding, get a transformer via #getTransformer(Properties) and set the output property "encoding" to the desired one, then use #serialize(Node, Transformer)
Parameters:
doc - Document (-fragment) to be serialized
Returns:
the String representation of the Document
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the document is null
Since:
v.5.0

serialize

public static String serialize(Node doc,
                               Transformer transformer)
                        throws IOException,
                               TransformerConfigurationException,
                               TransformerException
serialize a Document to String (using the passed Transformer) This call uses the transformer's output encoding to convert the content to a String
Parameters:
doc - Document (-fragment) to be serialized
transformer - the transformer to use
Returns:
the String representation of the Document
Throws:
IOException -  
TransformerConfigurationException -  
TransformerException -  
IllegalArgumentException - if the document or the transformer is null
Since:
v.5.0

addDirectiveToXSL

public static Node addDirectiveToXSL(Document xslDom,
                                     String directiveName,
                                     String attributeName,
                                     String attributeValue)
                              throws TransformerException
Add an xsl:import or xsl:include etc. node to an existing xsl style sheet (represented as DOM)
Parameters:
xslDom - the DOM representation of the XSL style sheet
directiveName - the tag name (@see #DIRECTIVE_INCLUDE and #DIRECTIVE_IMPORT)
attributeName - the name of an attribute to create, or null
attributeValue - the value for the attribute, or null
Returns:
the newly created node
Throws:
TransformerException -  
IllegalArgumentException - if the document or the directive name is null, or if the document is not an xsl style sheet
Since:
v.5.0

addDirectiveToXSLBeforeSibling

public static Node addDirectiveToXSLBeforeSibling(Node sibling,
                                                  String directiveName,
                                                  String attributeName,
                                                  String attributeValue)
Add an xsl:import or xsl:include node to an existing xsl style sheet (represented as DOM) before the passed sibling node
Parameters:
sibling - the node before which the new node will be added as a sibling (same level)
directiveName - (@see #DIRECTIVE_INCLUDE and #DIRECTIVE_IMPORT)
attributeName - the name of an attribute to create, or null
attributeValue - the value for the attribute, or null
Returns:
the newly created node
Throws:
IllegalArgumentException - if the sibling node or the directive name is null (no check if this is a style sheet!)
Since:
v.5.2

xslTransform

public static void xslTransform(Document contentDom,
                                Document styleDom,
                                Writer out)
                         throws TransformerException,
                                TransformerConfigurationException,
                                FileNotFoundException,
                                IOException
Transforms an xml with the provided xsl document and writes it to the writer.
Parameters:
contentDom - the document to be transformed
styleDom - the style to apply to the content
out - the writer to write the result to
Throws:
TransformerException -  
TransformerConfigurationException -  
FileNotFoundException -  
IOException -  
IllegalArgumentException - if any of the arguments is null
Since:
v.5.0

xslTransform

public static String xslTransform(Document contentDom,
                                  Transformer transformer,
                                  OutputStream out)
                           throws TransformerException,
                                  TransformerConfigurationException,
                                  FileNotFoundException,
                                  IOException
Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
Parameters:
contentDom - the document to be transformed
transformer - the compiled xsl style sheet that will be applied to the content document
out - the OutputStream to write the result to
Returns:
the encoding in which to read from the stream (taken from the transformers encoding property)

Note: you can set that encoding via #Transformer.getOutputProperties().setProperty("encoding", String); or in you xsl style sheet via xsl:output encoding="your encoding here" .....; the default encoding is UTF-8

Throws:
TransformerException -  
TransformerConfigurationException -  
FileNotFoundException -  
IOException -  
IllegalArgumentException - if any of the arguments is null
Since:
v.5.0

xslTransform

public static void xslTransform(Document contentDom,
                                Transformer transformer,
                                Writer writer)
                         throws TransformerException,
                                TransformerConfigurationException,
                                FileNotFoundException,
                                IOException
Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer
Parameters:
contentDom - the document to be transformed
transformer - the compiled xsl style sheet that will be applied to the content document
writer - the writer to write the result to
Throws:
TransformerException -  
TransformerConfigurationException -  
FileNotFoundException -  
IOException -  
IllegalArgumentException - if any of the arguments is null
Since:
v.5.2

getTransformer

public static Transformer getTransformer()
                                  throws TransformerConfigurationException
get a new Transformer from the TransformerFactory with indent turned on
Returns:
the new Transformer
Throws:
TransformerConfigurationException - if the underlying parser does
Since:
v.5.0

getTransformer

public static Transformer getTransformer(Properties transProps)
                                  throws TransformerConfigurationException
get a new Transformer from the TransformerFactory with the passed output properties
Parameters:
transProps - a Porperties file containing the desired Output properties
Returns:
the new Transformer
Throws:
TransformerConfigurationException - if the underlying parser does
Since:
v.5.0

getTransformer

public static Transformer getTransformer(Source strSource)
                                  throws TransformerConfigurationException
get a new Transformer for the passed Source (the xsl) from the TransformerFactory with indent turned on
Parameters:
strSource - a Source (StreamSource, DOMSource, SAXSource) representing the style we need the Transformer for
Returns:
the new Transformer
Throws:
TransformerConfigurationException - if the underlying parser does
Since:
v.5.0

getTransformer

public static Transformer getTransformer(Templates templates)
                                  throws TransformerConfigurationException
get a new Transformer for the passed compiled xsl template (with indent turned on)
Parameters:
templates - the pre compile xsl style sheet
Returns:
the new Transformer
Throws:
TransformerConfigurationException - if the underlying parser does
Since:
v.5.0

getTransformer

public static Transformer getTransformer(Document doc)
                                  throws TransformerException,
                                         IOException
get a new Transformer for the passed Document (the xsl) from the TransformerFactory with indent turned on
Parameters:
doc - a document representing the style we need the Transformer for
Returns:
the new Transformer (compiled xsl style sheet)
Throws:
TransformerException - if the underlying parser does
IOException - if converting the document to a stream source fails
Since:
v.5.0

getTemplates

public static Templates getTemplates(Source source)
                              throws TransformerConfigurationException
compile the provided style sheet into templates
Parameters:
source - a StreamSource, DOMSource, ... that contains the xsl style sheet to compile
Returns:
the compiled style sheet (where you can get the Transformer from)
Throws:
TransformerConfigurationException - if the underlying parser does
Since:
v.5.0

Novell exteNd
Director 5.2 API