|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.portal.common.util.XML
Utilities for dealing with XML.
Field Summary | |
static java.lang.String |
ATTRIB_CDATA_SECTION_ELEMENTS
|
static java.lang.String |
ATTRIB_HREF
|
static java.lang.String |
ATTRIB_INDENT
|
static java.lang.String |
ATTRIB_METHOD
|
static java.lang.String |
ATTRIB_OMIT_XML_DECLARATION
|
static boolean |
DEFAULT_NAMESPACE_AWARE
|
static boolean |
DEFAULT_VALIDATION
|
static java.lang.String |
DIRECTIVE_IMPORT
|
static java.lang.String |
DIRECTIVE_INCLUDE
|
static java.lang.String |
PARAM_NO
|
static java.lang.String |
PARAM_YES
|
static java.lang.String |
XML_LANG_NAMESPACE_URI
Namespace URI for XML lang. |
Method Summary | |
static org.w3c.dom.Node |
addDirectiveToXSL(org.w3c.dom.Document xslDom,
java.lang.String directiveName,
java.lang.String attributeName,
java.lang.String attributeValue)
Add an xsl:import or xsl:include etc. |
static org.w3c.dom.Node |
addDirectiveToXSLBeforeSibling(org.w3c.dom.Node sibling,
java.lang.String directiveName,
java.lang.String attributeName,
java.lang.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 org.w3c.dom.Node |
addNodeAfterSibling(org.w3c.dom.Node siblingNode,
java.lang.String nodeName,
org.w3c.dom.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 org.w3c.dom.Node |
addNodeAfterSibling(org.w3c.dom.Node siblingNode,
java.lang.String nodeName,
org.w3c.dom.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 org.w3c.dom.Node |
addNodeBeforeSibling(org.w3c.dom.Node siblingNode,
java.lang.String nodeName,
org.w3c.dom.Node content)
create a new Element with nodeName and insert it before the siblingNode (same level) |
static org.w3c.dom.Node |
addNodeBeforeSibling(org.w3c.dom.Node siblingNode,
java.lang.String nodeName,
org.w3c.dom.Node content,
boolean contentIsLocal)
Create a new Element with nodeName and insert it before the siblingNode (same level). |
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Document document,
org.w3c.dom.Element parent,
java.lang.String key)
Create and adds a new element to parent with a tag of key. |
static org.w3c.dom.Node |
appendChildNode(org.w3c.dom.Node parentNode,
org.w3c.dom.Node contentNode)
import a node into the current document directly under the passed parent Node |
static org.w3c.dom.Node |
appendChildNode(org.w3c.dom.Node parentNode,
org.w3c.dom.Node contentNode,
boolean contentIsLocal)
import a node into the current document directly under the passed parent Node |
static java.lang.String |
asString(org.w3c.dom.Element element)
Perform trimming by default |
static java.lang.String |
asString(org.w3c.dom.Element element,
boolean trim)
Get the element's content as a string. |
static void |
copyAttributes(org.w3c.dom.Element src,
org.w3c.dom.Element dest)
Copies all of the attributes from the src Element to the dest Element. |
static org.w3c.dom.Attr |
createAttribute(org.w3c.dom.Document doc,
java.lang.String attributeName,
java.lang.String attributeValue)
create an attribute standalone (not added to any node) |
static org.w3c.dom.Attr |
createAttribute(org.w3c.dom.Element el,
java.lang.String attributeName,
java.lang.String attributeValue)
create an attribute and add it to the Node provided |
static org.w3c.dom.Node |
createCDATANode(org.w3c.dom.Node parentNode,
java.lang.String nodeName,
java.lang.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 org.w3c.dom.Node |
createChildNode(org.w3c.dom.Node parentNode,
java.lang.String nodeName)
Create a child node and append it to the provided parent node |
static org.w3c.dom.Node |
createChildNode(org.w3c.dom.Node parentNode,
java.lang.String nodeName,
org.w3c.dom.Node contentNode)
create a child node (to parentNode) and populate it with the delivered content (if != null) |
static org.w3c.dom.Node |
createChildNode(org.w3c.dom.Node parentNode,
java.lang.String nodeName,
org.w3c.dom.Node contentNode,
boolean contentIsLocal)
create a child node (to parentNode) and populate it with the delivered content (if != null) |
static org.w3c.dom.Document |
createDocument()
create a new org.w3c.dom.Document with validation turned off and name space awareness turned on |
static org.w3c.dom.Document |
createDocument(byte[] bytes)
create a Document from a byte[] |
static org.w3c.dom.Document |
createDocument(org.xml.sax.InputSource inputSrc,
boolean isValidating,
boolean isNamespaceAware,
org.xml.sax.ErrorHandler errorHandler,
org.xml.sax.EntityResolver entityResolver)
Creates a new Document from an InputSource allowing the validation, namespace, error handler and entity resolver to be set. |
static org.w3c.dom.Document |
createDocument(java.io.InputStream stream)
create a Document from a String representation (with name space awareness on and validation off) |
static org.w3c.dom.Document |
createDocument(java.io.InputStream stream,
java.lang.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 org.w3c.dom.Document |
createDocument(java.io.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 org.w3c.dom.Document |
createDocument(java.lang.String strDoc)
Creates a Document from a String representing a valid XML document (no validation, but name space aware) |
static org.w3c.dom.Document |
createDocument(java.net.URL documentURL)
create a Document from a URL (get the content from the URL); name space aware, but no validation |
static org.w3c.dom.Node |
createDocumentRootNode(org.w3c.dom.Document parentDocument,
java.lang.String nodeName,
org.w3c.dom.Node contentNode)
create a child node (to parentDocument) and populate it with the delivered content (if != null) |
static org.w3c.dom.Node |
createDocumentRootNode(org.w3c.dom.Document parentDocument,
java.lang.String nodeName,
org.w3c.dom.Node contentNode,
boolean contentIsLocal)
create a child node (to parentDocument) and populate it with the delivered content (if != null). |
static org.w3c.dom.Node |
createNode(org.w3c.dom.Document document,
java.lang.String nodeName,
org.w3c.dom.Node contentNode)
create a Node standalone (not added to any parent) |
static org.w3c.dom.Node |
createNode(org.w3c.dom.Document document,
java.lang.String nodeName,
org.w3c.dom.Node contentNode,
boolean contentIsLocal)
create a Node standalone (not added to any parent) |
static java.util.Properties |
createOutputProperties(boolean omitXMLDeclaration,
boolean enableIndenting,
java.lang.String[] elements)
create the output properties for an xsl style sheet (like |
static org.w3c.dom.Node |
createTextNode(org.w3c.dom.Document doc,
org.w3c.dom.Node parentNode,
java.lang.String nodeName,
java.lang.String content)
create a text node To create a stand-alone node, pass null for parentNode. |
static org.w3c.dom.Node |
createTextNode(org.w3c.dom.Node parentNode,
java.lang.String nodeName,
java.lang.String content)
Create a text node as a child of another node. |
static org.w3c.dom.Attr |
getAttribute(java.lang.String attributeName,
org.w3c.dom.Node node)
get an attribute of a node (if present) |
static java.lang.String |
getAttributeValue(java.lang.String attributeName,
org.w3c.dom.Node node)
get the value of an attribute of a node (if present) |
static javax.xml.parsers.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 |
static javax.xml.parsers.DocumentBuilder |
getBuilder(boolean validation,
boolean nameSpaceAware)
get a javax.xml.parsers.DocumentBuilder from the javax.xml.parsers.DocumentBuilderFactory Using this method will cache the DocumentBuilder in thread local storage after the fist hit |
static java.util.List |
getChildren(org.w3c.dom.Element element,
java.lang.String name)
Return all the children of the given element having the specified name. |
static javax.xml.parsers.DocumentBuilderFactory |
getDocumentBuilderFactory()
Return the builder factory. |
static java.lang.String |
getElementBodyText(org.w3c.dom.Node parentNode)
get the text from an elements body example get 'hello world' from |
static java.lang.String |
getElementValue(org.w3c.dom.Node node)
entities are often considered serperate text nodes. |
static java.lang.String |
getFirstElementValue(org.w3c.dom.Node node,
java.lang.String element)
Returns the value of the first occurence of the child element specified for the node specified |
static javax.xml.parsers.SAXParserFactory |
getSAXParserFactory(boolean validation,
boolean nameSpaceAware)
get a SAXParserFactory (from cache) for the validation and name space aware properties |
static org.w3c.dom.Node |
getSelectedNode(org.apache.xpath.CachedXPathAPI xpath,
org.w3c.dom.Node contextNode,
java.lang.String str)
Use an XPath string to select a single node. |
static org.w3c.dom.Node |
getSelectedNode(org.w3c.dom.Node contextNode,
java.lang.String str)
Use an XPath string to select a single node. |
static org.w3c.dom.NodeList |
getSelectedNodes(org.w3c.dom.Node contextNode,
java.lang.String str)
Use an XPath string to select a nodelist. |
static javax.xml.transform.Templates |
getTemplates(javax.xml.transform.Source source)
compile the provided style sheet into templates |
static javax.xml.transform.Transformer |
getTransformer()
get a new Transformer from the TransformerFactory with indent turned on |
static javax.xml.transform.Transformer |
getTransformer(org.w3c.dom.Document doc)
get a new Transformer for the passed Document (the xsl) from the TransformerFactory with indent turned on |
static javax.xml.transform.Transformer |
getTransformer(java.util.Properties transProps)
get a new Transformer from the TransformerFactory with the passed output properties |
static javax.xml.transform.Transformer |
getTransformer(javax.xml.transform.Source strSource)
get a new Transformer for the passed Source (the xsl) from the TransformerFactory with indent turned on |
static javax.xml.transform.Transformer |
getTransformer(javax.xml.transform.Templates templates)
get a new Transformer for the passed compiled xsl template (with indent turned on) |
static org.w3c.dom.Element |
getUniqueChild(org.w3c.dom.Element element,
boolean strict)
Return the optional unique child of an element. |
static org.w3c.dom.Element |
getUniqueChild(org.w3c.dom.Element element,
java.lang.String name,
boolean strict)
Return an optional child of an element with the specified name. |
static void |
importChildNodes(org.w3c.dom.Node src,
org.w3c.dom.Node dest)
Deep copies the src Node's children to the dest Node. |
static void |
moveChildNodes(org.w3c.dom.Node src,
org.w3c.dom.Node dest)
Move all child nodes or src to the dest node. |
static void |
saxParse(org.xml.sax.InputSource source,
org.xml.sax.helpers.DefaultHandler handler,
boolean validation,
boolean nameSpaceAware)
parse the document from an InputStream with the provided handler |
static void |
saxParse(java.io.InputStream in,
org.xml.sax.helpers.DefaultHandler handler,
boolean validation,
boolean nameSpaceAware)
parse the document from an InputStream with the provided handler |
static java.lang.String |
serialize(org.w3c.dom.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). |
static void |
serialize(org.w3c.dom.Node doc,
java.io.OutputStream output)
serialize a Document to the provided OutputStream (using a Transformer) |
static void |
serialize(org.w3c.dom.Node doc,
java.io.OutputStream output,
javax.xml.transform.Transformer transformer)
serialize a Document to the provided OutputStream (using the passed Transformer) |
static java.lang.String |
serialize(org.w3c.dom.Node doc,
javax.xml.transform.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(org.w3c.dom.Node doc,
java.io.Writer writer)
serialize a Document to the provided Writer (using a Transformer) |
static void |
serialize(org.w3c.dom.Node doc,
java.io.Writer writer,
javax.xml.transform.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 org.w3c.dom.Document |
toDocument(java.lang.String text)
Parse a string into a document. |
static org.w3c.dom.Element |
toElement(java.lang.String text)
Parse a string into an element. |
static java.lang.String |
toString(org.w3c.dom.Document doc)
Serialize the document with the default format : - No XML declaration - Indented - Encoding is UTF-8 |
static java.lang.String |
toString(org.w3c.dom.Document doc,
java.util.Properties format)
Converts an document to a String representation. |
static java.lang.String |
toString(org.w3c.dom.Element element)
|
static java.lang.String |
toString(org.w3c.dom.Element element,
java.util.Properties properties)
Converts an element to a String representation. |
static void |
xslTransform(org.w3c.dom.Document contentDom,
org.w3c.dom.Document styleDom,
java.io.Writer out)
Transforms an xml with the provided xsl document and writes it to the writer. |
static java.lang.String |
xslTransform(org.w3c.dom.Document contentDom,
javax.xml.transform.Transformer transformer,
java.io.OutputStream out)
Transforms an xml document with the provided xsl style (compiled version) and write it to the provided writer |
static void |
xslTransform(org.w3c.dom.Document contentDom,
javax.xml.transform.Transformer transformer,
java.io.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 |
Field Detail |
public static final java.lang.String XML_LANG_NAMESPACE_URI
public static final java.lang.String PARAM_YES
public static final java.lang.String PARAM_NO
public static final java.lang.String ATTRIB_OMIT_XML_DECLARATION
public static final java.lang.String ATTRIB_CDATA_SECTION_ELEMENTS
public static final java.lang.String ATTRIB_METHOD
public static final java.lang.String ATTRIB_INDENT
public static final java.lang.String ATTRIB_HREF
public static final java.lang.String DIRECTIVE_IMPORT
public static final java.lang.String DIRECTIVE_INCLUDE
public static final boolean DEFAULT_NAMESPACE_AWARE
public static final boolean DEFAULT_VALIDATION
Method Detail |
public static javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
public static final java.lang.String toString(org.w3c.dom.Element element, java.util.Properties properties) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException
javax.xml.parsers.ParserConfigurationException
javax.xml.transform.TransformerException
public static final java.lang.String toString(org.w3c.dom.Element element) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException
javax.xml.parsers.ParserConfigurationException
javax.xml.transform.TransformerException
toString(Document)
public static final java.lang.String toString(org.w3c.dom.Document doc) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
toString(Document,Properties)
public static java.lang.String toString(org.w3c.dom.Document doc, java.util.Properties format) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
public static org.w3c.dom.Document toDocument(java.lang.String text) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Element toElement(java.lang.String text) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
public static java.lang.String asString(org.w3c.dom.Element element) throws java.lang.IllegalArgumentException
element
-
java.lang.IllegalArgumentException
asString(org.w3c.dom.Element, boolean)
public static java.lang.String asString(org.w3c.dom.Element element, boolean trim) throws java.lang.IllegalArgumentException
element
- the containertrim
- true if text should be trimmed before returning result
java.lang.IllegalArgumentException
- if the element content is mixed or nullpublic static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element, boolean strict) throws java.lang.IllegalArgumentException, NoSuchElementException, TooManyElementException
element
- the parent elementstrict
- true if the element must be present
java.lang.IllegalArgumentException
- if an argument is null
NoSuchElementException
- if strict is true and the element is not present
TooManyElementException
- if more than one element is foundpublic static org.w3c.dom.Element getUniqueChild(org.w3c.dom.Element element, java.lang.String name, boolean strict) throws java.lang.IllegalArgumentException, NoSuchElementException, TooManyElementException
element
- the parent elementname
- the child namestrict
- if the child must be present
java.lang.IllegalArgumentException
- if an argument is null
NoSuchElementException
- if strict is true and the element is not present
TooManyElementException
- if more than one element is foundpublic static java.util.List getChildren(org.w3c.dom.Element element, java.lang.String name) throws java.lang.IllegalArgumentException
element
- the parent elementname
- the child names
java.lang.IllegalArgumentException
- if the element is null or the name is nullpublic static javax.xml.parsers.DocumentBuilder getBuilder() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- if the parser is not configuredgetBuilder(boolean, boolean)
public static javax.xml.parsers.DocumentBuilder getBuilder(boolean validation, boolean nameSpaceAware) throws javax.xml.parsers.ParserConfigurationException
validation
- true if validation should be turned on, otherwise use falsenameSpaceAware
- true if name space awareness should be turned on, otherwise use false
javax.xml.parsers.ParserConfigurationException
- if the underlying parser doespublic static org.w3c.dom.Document createDocument() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- if the underlying parser doespublic static org.w3c.dom.Document createDocument(java.lang.String strDoc) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
strDoc
- the string representing the xml
org.w3c.dom.DOMException
- if the provided string does not represent a valid xml document
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the passed string is nullpublic static org.w3c.dom.Document createDocument(java.io.InputStream stream) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
stream
- the InputStream that represents the XML Content
org.w3c.dom.DOMException
- if the InputSource does not represent a valid XML document
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the provided InputSource is nullpublic static org.w3c.dom.Document createDocument(byte[] bytes) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
bytes
- the bytes that represents the XML Content
org.w3c.dom.DOMException
- if the InputSource does not represent a valid XML document
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the provided InputSource is nullpublic static org.w3c.dom.Document createDocument(java.io.InputStream stream, java.lang.String encoding, boolean validation, boolean namespace) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
stream
- the stream (InputStream,...) to represent the XMLencoding
- the Char encoding that should be used to read from the streamvalidation
- use validation (true), or not (false)namespace
- use namespace awareness (true) , or not (false)
org.w3c.dom.DOMException
- on Document problems
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the provided InputSource or encoding is nullpublic static org.w3c.dom.Document createDocument(java.io.Reader reader, boolean validation, boolean namespace) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
reader
- the reader pointing to the 'raw' xmlnamespace
- use namespace awareness (true) , or not (false)validation
- use validation (true), or not (false)
org.w3c.dom.DOMException
- on Document problems
java.io.IOException
- if the reader doesn't allow successfull access
org.xml.sax.SAXException
- on parsing problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser doespublic static org.w3c.dom.Document createDocument(java.net.URL documentURL) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
documentURL
- the URL pointing to the Document
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the provided URL is nullpublic static org.w3c.dom.Document createDocument(org.xml.sax.InputSource inputSrc, boolean isValidating, boolean isNamespaceAware, org.xml.sax.ErrorHandler errorHandler, org.xml.sax.EntityResolver entityResolver) throws org.w3c.dom.DOMException, java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
inputSrc
- the InputSource representing the xmlisValidating
- the boolean determining if validating is used against the xmlisNamespaceAware
- the boolean determining if the NameSpaceAware feature is seterrorHandler
- the ErrorHandler to be used if suppliedentityResolver
- the entityResolver to be used if supplied
org.w3c.dom.DOMException
- on Document problems
java.io.IOException
- on read problems
org.xml.sax.SAXException
- on parse problems
javax.xml.parsers.ParserConfigurationException
- if the underlying parser does
java.lang.IllegalArgumentException
- if the provided InputSource is nullpublic static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument, java.lang.String nodeName, org.w3c.dom.Node contentNode)
parentDocument
- the Document that will receive the new Element and the contentnodeName
- the name of the Element to createcontentNode
- the Node that will be appended as a child to the created Element
java.lang.IllegalArgumentException
- if the document or the node name is nullpublic static org.w3c.dom.Node createDocumentRootNode(org.w3c.dom.Document parentDocument, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
parentDocument
- the Document that will receive the new Element and the contentnodeName
- the name of the Element to createcontentNode
- 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)
java.lang.IllegalArgumentException
- if the document or the node name is nullpublic static org.w3c.dom.Node createNode(org.w3c.dom.Document document, java.lang.String nodeName, org.w3c.dom.Node contentNode)
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
java.lang.IllegalArgumentException
- if the document or the node name is nullpublic static org.w3c.dom.Node createNode(org.w3c.dom.Document document, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
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)
java.lang.IllegalArgumentException
- if the document or the node name is nullpublic static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, org.w3c.dom.Node contentNode)
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)
java.lang.IllegalArgumentException
- if the parent node or the node name is nullpublic static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, org.w3c.dom.Node contentNode, boolean contentIsLocal)
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)
java.lang.IllegalArgumentException
- if the parent node or the node name is nullpublic static org.w3c.dom.Node createChildNode(org.w3c.dom.Node parentNode, java.lang.String nodeName)
nodeName
- the name for the new nodeparentNode
- the parent org.w3c.dom.Node that will receive the child
java.lang.IllegalArgumentException
- if the parent node or the node name is nullpublic static org.w3c.dom.Node createTextNode(org.w3c.dom.Document doc, org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
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
java.lang.IllegalArgumentException
- if either the document, or the node name and the parent node are nullpublic static org.w3c.dom.Node createTextNode(org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
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
java.lang.IllegalArgumentException
- if the parent node is nullpublic static org.w3c.dom.Attr createAttribute(org.w3c.dom.Element el, java.lang.String attributeName, java.lang.String attributeValue)
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
java.lang.IllegalArgumentException
- if the element or the attribute name is nullpublic static org.w3c.dom.Attr createAttribute(org.w3c.dom.Document doc, java.lang.String attributeName, java.lang.String attributeValue)
doc
- the Document used to create the attributeattributeName
- name of the attribute to be createdattributeValue
- value of the attribute to be created
java.lang.IllegalArgumentException
- if the document or the attribute name is nullpublic static java.lang.String getAttributeValue(java.lang.String attributeName, org.w3c.dom.Node node)
attributeName
- the name of the attribute you want to getnode
- the Node where the attribute lives
java.lang.IllegalArgumentException
- if the attribute name or the node is nullpublic static org.w3c.dom.Attr getAttribute(java.lang.String attributeName, org.w3c.dom.Node node)
attributeName
- the name of the attribute you want to getnode
- the Node where the attribute lives
java.lang.IllegalArgumentException
- if the attribute name or the node is nullpublic static java.lang.String getElementBodyText(org.w3c.dom.Node parentNode)
parentNode
- the node that contains text
org.w3c.dom.DOMException
- if the undelying DOM api doespublic static org.w3c.dom.Node createCDATANode(org.w3c.dom.Node parentNode, java.lang.String nodeName, java.lang.String content)
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)
java.lang.IllegalArgumentException
- if the parent node is nullcreateChildNode(org.w3c.dom.Node,String)
public static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content)
siblingNode
- the node that will be used as reference; the new element will be inserted before this nodenodeName
- the name of the element to createcontent
- any subtree that will be appended as child of the new element (if != null)
java.lang.IllegalArgumentException
- if the sibling node or the node name is nullpublic static org.w3c.dom.Node addNodeBeforeSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content, boolean contentIsLocal)
siblingNode
- the node that will be used as reference; the new element will be inserted before this nodenodeName
- 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)
java.lang.IllegalArgumentException
- if the sibling node is null or the node name and the content is nullpublic static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content)
siblingNode
- the node that will be used as reference; the new element will be inserted after this nodenodeName
- 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)
java.lang.IllegalArgumentException
- if the sibling node is null or the node name and the content is nullpublic static org.w3c.dom.Node addNodeAfterSibling(org.w3c.dom.Node siblingNode, java.lang.String nodeName, org.w3c.dom.Node content, boolean contentIsLocal)
siblingNode
- the node that will be used as reference; the new element will be inserted after this nodenodeName
- 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)
java.lang.IllegalArgumentException
- if the sibling node is null or the node name and the content is nullpublic static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document document, org.w3c.dom.Element parent, java.lang.String key)
document
- xml document to which element will be addedparent
- Element inside of which element of tag "key" will go.key
- String that becomes the appended element.
public static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode, org.w3c.dom.Node contentNode)
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)
java.lang.IllegalArgumentException
- if the parent node or the content node is nullpublic static org.w3c.dom.Node appendChildNode(org.w3c.dom.Node parentNode, org.w3c.dom.Node contentNode, boolean contentIsLocal)
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)
java.lang.IllegalArgumentException
- if the parent node or the content node is nullpublic static void importChildNodes(org.w3c.dom.Node src, org.w3c.dom.Node dest)
src
- Node in Document A that should have all it's children copied.dest
- Node in Document B that is the destination of the copy from the src node.
java.lang.IllegalArgumentException
- if the provided nodes are nullpublic static void moveChildNodes(org.w3c.dom.Node src, org.w3c.dom.Node dest)
src
- Node that should have all it's children removed.dest
- Node that is the destination of the move from the src node.
java.lang.IllegalArgumentException
- if the provided nodes are nullpublic static java.util.Properties createOutputProperties(boolean omitXMLDeclaration, boolean enableIndenting, java.lang.String[] elements)
omitXMLDeclaration
- omit-xml-declaration 'yes' or 'no'enableIndenting
- indent 'yes' or 'no'elements
- cdata-section-elements will be converted to a space separated list
#setOutputProperties(Properties)
,
OutputKeys
,
Properties
public static void serialize(org.w3c.dom.Node doc, java.io.OutputStream output) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serializedoutput
- the OutputStream to write to
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on parser configuration problems
javax.xml.transform.TransformerException
- on trandformation problems
java.lang.IllegalArgumentException
- if the output stream or the document is nullpublic static void serialize(org.w3c.dom.Node doc, java.io.OutputStream output, javax.xml.transform.Transformer transformer) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serializedoutput
- the OutputStream to write totransformer
- the transformer to use
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
javax.xml.transform.TransformerException
- on trnaformation problems
java.lang.IllegalArgumentException
- if the output stream or the document or the transformer is nullpublic static void serialize(org.w3c.dom.Node doc, java.io.Writer writer) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serializedwriter
- the writer to write to
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
javax.xml.transform.TransformerException
- on trnaformation problems
java.lang.IllegalArgumentException
- if the document or the writer is nullpublic static void serialize(org.w3c.dom.Node doc, java.io.Writer writer, javax.xml.transform.Transformer transformer) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serializedwriter
- the writer to write totransformer
- the transformer to use
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
javax.xml.transform.TransformerException
- on trnaformation problems
java.lang.IllegalArgumentException
- if the document or the writer or the transformer is nullpublic static java.lang.String serialize(org.w3c.dom.Node doc) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serialized
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
javax.xml.transform.TransformerException
- on trnaformation problems
java.lang.IllegalArgumentException
- if the document is nullpublic static java.lang.String serialize(org.w3c.dom.Node doc, javax.xml.transform.Transformer transformer) throws java.io.IOException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
doc
- Document (-fragment) to be serializedtransformer
- the transformer to use
java.io.IOException
- on read problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
javax.xml.transform.TransformerException
- on trnaformation problems
java.lang.IllegalArgumentException
- if the document or the transformer is nullpublic static org.w3c.dom.Node addDirectiveToXSL(org.w3c.dom.Document xslDom, java.lang.String directiveName, java.lang.String attributeName, java.lang.String attributeValue) throws javax.xml.transform.TransformerException
xslDom
- the DOM representation of the XSL style sheetdirectiveName
- the tag name (@see #DIRECTIVE_INCLUDE and #DIRECTIVE_IMPORT)attributeName
- the name of an attribute to create, or nullattributeValue
- the value for the attribute, or null
javax.xml.transform.TransformerException
- when problems adding the xsl directive occur
java.lang.IllegalArgumentException
- if the document or the directive name is null, or if the document is not an xsl
style sheetpublic static org.w3c.dom.Node addDirectiveToXSLBeforeSibling(org.w3c.dom.Node sibling, java.lang.String directiveName, java.lang.String attributeName, java.lang.String attributeValue)
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 nullattributeValue
- the value for the attribute, or null
java.lang.IllegalArgumentException
- if the sibling node or the directive name is null (no check if this is a style
sheet!)public static void xslTransform(org.w3c.dom.Document contentDom, org.w3c.dom.Document styleDom, java.io.Writer out) throws javax.xml.transform.TransformerException, javax.xml.transform.TransformerConfigurationException, java.io.FileNotFoundException, java.io.IOException
contentDom
- the document to be transformedstyleDom
- the style to apply to the contentout
- the writer to write the result to
javax.xml.transform.TransformerException
- on trnaformation problems
javax.xml.transform.TransformerConfigurationException
- on transformer configuration problems
java.io.FileNotFoundException
- if the write operation fails
java.io.IOException
- on read problems
java.lang.IllegalArgumentException
- if any of the arguments is nullpublic static java.lang.String xslTransform(org.w3c.dom.Document contentDom, javax.xml.transform.Transformer transformer, java.io.OutputStream out) throws javax.xml.transform.TransformerException, javax.xml.transform.TransformerConfigurationException
contentDom
- the document to be transformedtransformer
- the compiled xsl style sheet that will be applied to the content documentout
- the OutputStream to write the result to
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
javax.xml.transform.TransformerException
- if the transformation fails
javax.xml.transform.TransformerConfigurationException
- if the transformer is misconfigured
java.lang.IllegalArgumentException
- if any of the arguments is nullpublic static void xslTransform(org.w3c.dom.Document contentDom, javax.xml.transform.Transformer transformer, java.io.Writer writer) throws javax.xml.transform.TransformerException, javax.xml.transform.TransformerConfigurationException
contentDom
- the document to be transformedtransformer
- the compiled xsl style sheet that will be applied to the content documentwriter
- the writer to write the result to
javax.xml.transform.TransformerException
- if the transformation fails
javax.xml.transform.TransformerConfigurationException
- if the transformer is misconfigured
java.lang.IllegalArgumentException
- if any of the arguments is nullpublic static javax.xml.transform.Transformer getTransformer() throws javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerConfigurationException
- if the underlying parser doespublic static javax.xml.transform.Transformer getTransformer(java.util.Properties transProps) throws javax.xml.transform.TransformerConfigurationException
transProps
- a Porperties file containing the desired Output properties
javax.xml.transform.TransformerConfigurationException
- if the underlying parser doespublic static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Source strSource) throws javax.xml.transform.TransformerConfigurationException
strSource
- a Source (StreamSource, DOMSource, SAXSource) representing the style we need the Transformer for
javax.xml.transform.TransformerConfigurationException
- if the underlying parser doespublic static javax.xml.transform.Transformer getTransformer(javax.xml.transform.Templates templates) throws javax.xml.transform.TransformerConfigurationException
templates
- the pre compile xsl style sheet
javax.xml.transform.TransformerConfigurationException
- if the underlying parser doespublic static javax.xml.transform.Transformer getTransformer(org.w3c.dom.Document doc) throws javax.xml.transform.TransformerException, java.io.IOException
doc
- a document representing the style we need the Transformer for
javax.xml.transform.TransformerException
- if the underlying parser does
java.io.IOException
- if converting the document to a stream source failspublic static javax.xml.transform.Templates getTemplates(javax.xml.transform.Source source) throws javax.xml.transform.TransformerConfigurationException
source
- a StreamSource, DOMSource, ... that contains the xsl style sheet to compile
javax.xml.transform.TransformerConfigurationException
- if the underlying parser doespublic static org.w3c.dom.NodeList getSelectedNodes(org.w3c.dom.Node contextNode, java.lang.String str) throws javax.xml.transform.TransformerException
contextNode
- the node from which on to search in the treestr
- the XPATH expression
java.lang.RuntimeException
- (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException
- if the xpath expression is not validpublic static org.w3c.dom.Node getSelectedNode(org.w3c.dom.Node contextNode, java.lang.String str) throws javax.xml.transform.TransformerException
contextNode
- the node from which on to search in the treestr
- the XPATH expression
java.lang.RuntimeException
- (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException
- if the xpath expression is not validpublic static org.w3c.dom.Node getSelectedNode(org.apache.xpath.CachedXPathAPI xpath, org.w3c.dom.Node contextNode, java.lang.String str) throws javax.xml.transform.TransformerException
xpath
- a org.apache.xpath.CachedXPathAPI
instance to use for xpath navigationcontextNode
- the node from which on to search in the treestr
- the XPATH expression
java.lang.RuntimeException
- (possibly wrapping the original checked exception) if any exception happens
javax.xml.transform.TransformerException
- if the xpath expression is not validpublic static javax.xml.parsers.SAXParserFactory getSAXParserFactory(boolean validation, boolean nameSpaceAware)
validation
- if the factory should validate the documentnameSpaceAware
- if the factory should be name space aware
public static void saxParse(java.io.InputStream in, org.xml.sax.helpers.DefaultHandler handler, boolean validation, boolean nameSpaceAware) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
in
- the InputStream pointing to an xml document (from file ...)handler
- the handler to use for parsing (extends DefaultHandler)validation
- if the parser should validate the documentnameSpaceAware
- if the parser should be name space aware
javax.xml.parsers.ParserConfigurationException
- if the parser is misconfigured
org.xml.sax.SAXException
- if the parsing fails
java.io.IOException
- if the read failspublic static void saxParse(org.xml.sax.InputSource source, org.xml.sax.helpers.DefaultHandler handler, boolean validation, boolean nameSpaceAware) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
source
- the InputSource to parsehandler
- the handler to use for parsing (extends DefaultHandler)validation
- if the parser should validate the documentnameSpaceAware
- if the parser should be name space aware
javax.xml.parsers.ParserConfigurationException
- if the parser is misconfigured
org.xml.sax.SAXException
- if the parsing fails
java.io.IOException
- if the read failspublic static java.lang.String getFirstElementValue(org.w3c.dom.Node node, java.lang.String element)
node
- the node from where on to search for a node with the name specified by #elementelement
- the name of the node to look for
java.lang.IllegalArgumentException
- if any of the arguments is nullpublic static java.lang.String getElementValue(org.w3c.dom.Node node)
node
- the node that will be inspected for children
java.lang.IllegalArgumentException
- if the provided node is nullpublic static void copyAttributes(org.w3c.dom.Element src, org.w3c.dom.Element dest)
src
- The Element from which all attributes will be copied.dest
- The Element to recieve the attributes in the src element.
java.lang.IllegalArgumentException
- if the provided elements are null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |