From 3fada6cef21c9b16467177d866df778203b51b4d Mon Sep 17 00:00:00 2001
From: Thomas
- * The parsing methods in this class make use of some features internal to the Xerces DOM parser,
- * mainly for performance reasons. As soon as JAXP (currently at version 1.2) is better at schema
- * handling, it should be used as the parser interface.
- *
+ * The parsing methods in this class make use of some features internal to the
+ * Xerces DOM parser, mainly for performance reasons. As soon as JAXP (currently
+ * at version 1.2) is better at schema handling, it should be used as the parser
+ * interface.
+ *
- * It uses a
+ * It uses a
- * It uses a
+ * It uses a
- * It uses a
+ * It uses a
+ *
* The node will be serialized using the UTF-8 encoding.
- *systemId
(namespace URI) is not already present in the
- * pool.
+ * Preparse a schema and add it to the schema pool. The method only adds the
+ * schema to the pool if a schema having the same systemId
+ * (namespace URI) is not already present in the pool.
*
- * @param inputStream An InputStream
providing the contents of the schema.
- * @param systemId The systemId (namespace URI) to use for the schema.
+ * @param inputStream An InputStream
providing the contents of the
+ * schema.
+ * @param systemId The systemId (namespace URI) to use for the schema.
* @throws IOException An error occurred reading the schema.
*/
public static void addSchemaToPool(final InputStream inputStream, final String systemId)
@@ -178,24 +180,32 @@ public class DomUtils {
/**
* Parse an XML document from an InputStream
.
*
- *MOAEntityResolver
as the EntityResolver
and a
- * MOAErrorHandler
as the ErrorHandler
.
- *MOAEntityResolver
as the EntityResolver
+ * and a MOAErrorHandler
as the ErrorHandler
.
+ * InputStream
containing the XML document.
- * @param validating If true
, parse validating.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
- * @param parserFeatures Map of features that should be set into XML parser
+ * @param inputStream The InputStream
+ * containing the XML document.
+ * @param validating If true
, parse
+ * validating.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
+ * @param parserFeatures Map of features that should be set
+ * into XML parser
* @return The parsed XML document as a DOM tree.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Document parseDocument(final InputStream inputStream, final boolean validating,
final String externalSchemaLocations, final String externalNoNamespaceSchemaLocation,
@@ -209,24 +219,31 @@ public class DomUtils {
/**
* Parse an XML document from a String
.
*
- *MOAEntityResolver
as the EntityResolver
and a
- * MOAErrorHandler
as the ErrorHandler
.
- *MOAEntityResolver
as the EntityResolver
+ * and a MOAErrorHandler
as the ErrorHandler
.
+ * String
containing the XML document.
- * @param encoding The encoding of the XML document.
- * @param validating If true
, parse validating.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
+ * @param xmlString The String
containing
+ * the XML document.
+ * @param encoding The encoding of the XML document.
+ * @param validating If true
, parse
+ * validating.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
* @return The parsed XML document as a DOM tree.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Document parseDocument(final String xmlString, final String encoding,
final boolean validating, final String externalSchemaLocations,
@@ -241,24 +258,31 @@ public class DomUtils {
/**
* Parse an XML document from a String
.
*
- *MOAEntityResolver
as the EntityResolver
and a
- * MOAErrorHandler
as the ErrorHandler
.
- *MOAEntityResolver
as the EntityResolver
+ * and a MOAErrorHandler
as the ErrorHandler
.
+ * String
containing the XML document.
- * @param encoding The encoding of the XML document.
- * @param validating If true
, parse validating.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
+ * @param xmlString The String
containing
+ * the XML document.
+ * @param encoding The encoding of the XML document.
+ * @param validating If true
, parse
+ * validating.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
* @return The parsed XML document as a DOM tree.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Document parseDocument(final String xmlString, final String encoding,
final boolean validating, final String externalSchemaLocations,
@@ -273,18 +297,25 @@ public class DomUtils {
/**
* Parse an UTF-8 encoded XML document from a String
.
*
- * @param xmlString The String
containing the XML document.
- * @param validating If true
, parse validating.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
+ * @param xmlString The String
containing
+ * the XML document.
+ * @param validating If true
, parse
+ * validating.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
* @return The parsed XML document as a DOM tree.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Document parseDocument(final String xmlString, final boolean validating,
final String externalSchemaLocations, final String externalNoNamespaceSchemaLocation)
@@ -297,22 +328,33 @@ public class DomUtils {
/**
* Parse an XML document from an InputStream
.
*
- * @param inputStream The InputStream
containing the XML document.
- * @param validating If true
, parse validating.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
- * @param entityResolver An EntityResolver
to resolve external entities (schemas and
- * DTDs). If null
, it will not be set.
- * @param errorHandler An ErrorHandler
to decide what to do with parsing errors. If
- * null
, it will not be set.
+ * @param inputStream The InputStream
+ * containing the XML document.
+ * @param validating If true
, parse
+ * validating.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
+ * @param entityResolver An EntityResolver
to
+ * resolve external entities (schemas
+ * and DTDs). If null
, it
+ * will not be set.
+ * @param errorHandler An ErrorHandler
to
+ * decide what to do with parsing
+ * errors. If null
, it
+ * will not be set.
* @return The parsed XML document as a DOM tree.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Document parseDocument(final InputStream inputStream, final boolean validating,
final String externalSchemaLocations, final String externalNoNamespaceSchemaLocation,
@@ -330,8 +372,8 @@ public class DomUtils {
// }
// }
-
- // if Debug is enabled make a copy of inputStream to enable debug output in case of SAXException
+ // if Debug is enabled make a copy of inputStream to enable debug output in case
+ // of SAXException
byte[] buffer = null;
ByteArrayInputStream baStream = null;
if (true == log.isDebugEnabled()) {
@@ -340,8 +382,6 @@ public class DomUtils {
}
-
-
// create the DOM parser
if (symbolTable != null) {
parser = new DOMParser(symbolTable, grammarPool);
@@ -379,8 +419,8 @@ public class DomUtils {
}
// fix XXE problem
- // parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-
+ // parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl",
+ // true);
if (validating) {
if (externalSchemaLocations != null) {
@@ -423,9 +463,9 @@ public class DomUtils {
*
* @param inputStream data to parse
* @return Element
- * @throws SAXException In case of an error
- * @throws IOException In case of an error
- * @throws ParserConfigurationException In case of an error
+ * @throws SAXException In case of an error
+ * @throws IOException In case of an error
+ * @throws ParserConfigurationException In case of an error
*/
public static Document parseDocumentSimple(final InputStream inputStream)
throws SAXException, IOException, ParserConfigurationException {
@@ -446,62 +486,56 @@ public class DomUtils {
return parser.getDocument();
}
-
-
-
-
-
-
-
-
-
-
/**
* A convenience method to parse an XML document validating.
*
* @param inputStream The InputStream
containing the XML document.
* @return The root element of the parsed XML document.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Element parseXmlValidating(final InputStream inputStream)
throws ParserConfigurationException, SAXException, IOException {
return DomUtils
- .parseDocument(inputStream, true, XMLNamespaceConstants.ALL_SCHEMA_LOCATIONS, null, null)
+ .parseDocument(inputStream, true, XmlNamespaceConstants.ALL_SCHEMA_LOCATIONS, null, null)
.getDocumentElement();
}
/**
* A convenience method to parse an XML document validating.
*
- * @param inputStream The InputStream
containing the XML document.
+ * @param inputStream The InputStream
containing the XML
+ * document.
* @param parserFeatures Set additional features to XML parser
* @return The root element of the parsed XML document.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Element parseXmlValidating(final InputStream inputStream,
final MapInputStream
containing the XML document.
* @return The root element of the parsed XML document.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document.
- * @throws ParserConfigurationException An error occurred configuring the XML parser.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document.
+ * @throws ParserConfigurationException An error occurred configuring the XML
+ * parser.
*/
public static Element parseXmlNonValidating(final InputStream inputStream)
throws ParserConfigurationException, SAXException, IOException {
- return DomUtils.parseDocument(inputStream, false, XMLNamespaceConstants.ALL_SCHEMA_LOCATIONS,
+ return DomUtils.parseDocument(inputStream, false, XmlNamespaceConstants.ALL_SCHEMA_LOCATIONS,
null, Collections.unmodifiableMap(new HashMapString
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
- * @return true
, if the element
validates against the schemas declared
- * in it.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document from its serialized representation.
+ * @param element The element to validate.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
+ * @return true
, if the element
validates against the
+ * schemas declared in it.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document
+ * from its serialized representation.
* @throws ParserConfigurationException An error occurred configuring the XML
- * @throws TransformerException An error occurred serializing the element.
+ * @throws TransformerException An error occurred serializing the
+ * element.
*/
public static boolean validateElement(final Element element, final String externalSchemaLocations,
final String externalNoNamespaceSchemaLocation)
@@ -552,7 +592,6 @@ public class DomUtils {
parser.setFeature(EXTERNAL_GENERAL_ENTITIES_FEATURE, false);
parser.setFeature(DISALLOW_DOCTYPE_FEATURE, true);
-
if (externalSchemaLocations != null) {
parser.setProperty(EXTERNAL_SCHEMA_LOCATION_PROPERTY, externalSchemaLocations);
}
@@ -569,23 +608,28 @@ public class DomUtils {
return true;
}
-
/**
* Schema validate a given DOM element.
*
- * @param element The element to validate.
- * @param externalSchemaLocations A String
containing namespace URI to schema
- * location pairs, the same way it is accepted by the xsi:
- * schemaLocation
attribute.
- * @param externalNoNamespaceSchemaLocation The schema location of the schema for elements without
- * a namespace, the same way it is accepted by the
- * xsi:noNamespaceSchemaLocation
attribute.
- * @return true
, if the element
validates against the schemas declared
- * in it.
- * @throws SAXException An error occurred parsing the document.
- * @throws IOException An error occurred reading the document from its serialized representation.
+ * @param element The element to validate.
+ * @param externalSchemaLocations A String
containing
+ * namespace URI to schema location
+ * pairs, the same way it is accepted
+ * by the xsi:
+ * schemaLocation
attribute.
+ * @param externalNoNamespaceSchemaLocation The schema location of the schema
+ * for elements without a namespace,
+ * the same way it is accepted by the
+ * xsi:noNamespaceSchemaLocation
+ * attribute.
+ * @return true
, if the element
validates against the
+ * schemas declared in it.
+ * @throws SAXException An error occurred parsing the document.
+ * @throws IOException An error occurred reading the document
+ * from its serialized representation.
* @throws ParserConfigurationException An error occurred configuring the XML
- * @throws TransformerException An error occurred serializing the element.
+ * @throws TransformerException An error occurred serializing the
+ * element.
*/
public static boolean validateElement(final Element element, final String externalSchemaLocations,
final String externalNoNamespaceSchemaLocation, final EntityResolver entityResolver)
@@ -628,32 +672,35 @@ public class DomUtils {
/**
* Serialize the given DOM node.
*
- *
String
representation of the given DOM node.
- * @throws TransformerException An error occurred transforming the node to a String
.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @throws TransformerException An error occurred transforming the node to a
+ * String
.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static String serializeNode(final Node node) throws TransformerException, IOException {
return new String(serializeNode(node, "UTF-8", false), "UTF-8");
}
-
/**
* Serialize the given DOM node.
*
- *+ *
* The node will be serialized using the UTF-8 encoding. - *
+ * * - * @param node The node to serialize. + * @param node The node to serialize. * @param omitXmlDeclaration The boolean value for omitting the XML Declaration. * @return String TheString
representation of the given DOM node.
- * @throws TransformerException An error occurred transforming the node to a String
.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @throws TransformerException An error occurred transforming the node to a
+ * String
.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static String serializeNode(final Node node, final boolean omitXmlDeclaration)
throws TransformerException, IOException {
@@ -663,16 +710,18 @@ public class DomUtils {
/**
* Serialize the given DOM node.
*
- *+ *
* The node will be serialized using the UTF-8 encoding. - *
+ * * - * @param node The node to serialize. + * @param node The node to serialize. * @param omitXmlDeclaration The boolean value for omitting the XML Declaration. - * @param lineSeperator Sets the line seperator String of the parser + * @param lineSeperator Sets the line seperator String of the parser * @return String TheString
representation of the given DOM node.
- * @throws TransformerException An error occurred transforming the node to a String
.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @throws TransformerException An error occurred transforming the node to a
+ * String
.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static String serializeNode(final Node node, final boolean omitXmlDeclaration,
final String lineSeperator) throws TransformerException, IOException {
@@ -682,12 +731,14 @@ public class DomUtils {
/**
* Serialize the given DOM node to a byte array.
*
- * @param node The node to serialize.
+ * @param node The node to serialize.
* @param xmlEncoding The XML encoding to use.
- * @return The serialized node, as a byte array. Using a compatible encoding this can easily be
- * converted into a String
.
- * @throws TransformerException An error occurred transforming the node to a byte array.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @return The serialized node, as a byte array. Using a compatible encoding
+ * this can easily be converted into a String
.
+ * @throws TransformerException An error occurred transforming the node to a
+ * byte array.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static byte[] serializeNode(final Node node, final String xmlEncoding)
throws TransformerException, IOException {
@@ -697,31 +748,34 @@ public class DomUtils {
/**
* Serialize the given DOM node to a byte array.
*
- * @param node The node to serialize.
- * @param xmlEncoding The XML encoding to use.
+ * @param node The node to serialize.
+ * @param xmlEncoding The XML encoding to use.
* @param omitDeclaration The boolean value for omitting the XML Declaration.
- * @return The serialized node, as a byte array. Using a compatible encoding this can easily be
- * converted into a String
.
- * @throws TransformerException An error occurred transforming the node to a byte array.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @return The serialized node, as a byte array. Using a compatible encoding
+ * this can easily be converted into a String
.
+ * @throws TransformerException An error occurred transforming the node to a
+ * byte array.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static byte[] serializeNode(final Node node, final String xmlEncoding,
final boolean omitDeclaration) throws TransformerException, IOException {
return serializeNode(node, xmlEncoding, omitDeclaration, null);
}
-
/**
* Serialize the given DOM node to a byte array.
*
- * @param node The node to serialize.
- * @param xmlEncoding The XML encoding to use.
+ * @param node The node to serialize.
+ * @param xmlEncoding The XML encoding to use.
* @param omitDeclaration The boolean value for omitting the XML Declaration.
- * @param lineSeperator Sets the line seperator String of the parser
- * @return The serialized node, as a byte array. Using a compatible encoding this can easily be
- * converted into a String
.
- * @throws TransformerException An error occurred transforming the node to a byte array.
- * @throws IOException An IO error occurred writing the node to a byte array.
+ * @param lineSeperator Sets the line seperator String of the parser
+ * @return The serialized node, as a byte array. Using a compatible encoding
+ * this can easily be converted into a String
.
+ * @throws TransformerException An error occurred transforming the node to a
+ * byte array.
+ * @throws IOException An IO error occurred writing the node to a byte
+ * array.
*/
public static byte[] serializeNode(final Node node, final String xmlEncoding,
final boolean omitDeclaration, final String lineSeperator)
@@ -737,7 +791,7 @@ public class DomUtils {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omit);
if (null != lineSeperator) {
transformer.setOutputProperty("{http://xml.apache.org/xalan}line-separator", lineSeperator);
- // does not work for xalan <= 2.5.1
+ // does not work for xalan <= 2.5.1
}
transformer.transform(new DOMSource(node), new StreamResult(bos));
@@ -750,15 +804,15 @@ public class DomUtils {
/**
* Return the text that a node contains.
*
- *+ *
* This routine: *
*String
value to
- * String
value mapping).
+ * @return The namespace prefix to namespace URL mapping ( a String
+ * value to String
value mapping).
*/
public static Map getNamespaceDeclarations(Node node) {
final Map nsDecls = new HashMap();
@@ -822,8 +877,8 @@ public class DomUtils {
}
/**
- * Add all namespace declarations declared in the parent(s) of a given element and used in the
- * subtree of the given element to the given element.
+ * Add all namespace declarations declared in the parent(s) of a given element
+ * and used in the subtree of the given element to the given element.
*
* @param context The element to which to add the namespaces.
*/
@@ -843,7 +898,7 @@ public class DomUtils {
final String nsUri = (String) e.getValue();
final String nsAttrName = "".equals(prefix) ? "xmlns" : "xmlns:" + prefix;
- context.setAttributeNS(XMLNamespaceConstants.XMLNS_NS_URI, nsAttrName, nsUri);
+ context.setAttributeNS(XmlNamespaceConstants.XMLNS_NS_URI, nsAttrName, nsUri);
}
}
}
@@ -853,8 +908,8 @@ public class DomUtils {
* Collect all the namespace URIs used in the subtree of a given element.
*
* @param context The element that should be searched for namespace URIs.
- * @return All namespace URIs used in the subtree of context
, including the ones used
- * in context
itself.
+ * @return All namespace URIs used in the subtree of context
,
+ * including the ones used in context
itself.
*/
public static Set collectNamespaceUris(final Element context) {
final Set result = new HashSet();
@@ -867,8 +922,8 @@ public class DomUtils {
* A recursive method to do the work of collectNamespaceURIs
.
*
* @param context The context element to evaluate.
- * @param result The result, passed as a parameter to avoid unnecessary instantiations of
- * Set
.
+ * @param result The result, passed as a parameter to avoid unnecessary
+ * instantiations of Set
.
*/
private static void collectNamespaceUrisImpl(final Element context, final Set result) {
final NamedNodeMap attrs = context.getAttributes();
@@ -878,14 +933,14 @@ public class DomUtils {
// add the namespace of the context element
nsUri = context.getNamespaceURI();
- if (nsUri != null && nsUri != XMLNamespaceConstants.XMLNS_NS_URI) {
+ if (nsUri != null && nsUri != XmlNamespaceConstants.XMLNS_NS_URI) {
result.add(nsUri);
}
// add all namespace URIs from attributes
for (i = 0; i < attrs.getLength(); i++) {
nsUri = attrs.item(i).getNamespaceURI();
- if (nsUri != null && nsUri != XMLNamespaceConstants.XMLNS_NS_URI) {
+ if (nsUri != null && nsUri != XmlNamespaceConstants.XMLNS_NS_URI) {
result.add(nsUri);
}
}
@@ -901,12 +956,12 @@ public class DomUtils {
}
/**
- * Check, that each attribute node in the given NodeList
has its parent in the
- * NodeList
as well.
+ * Check, that each attribute node in the given NodeList
has its
+ * parent in the NodeList
as well.
*
* @param nodes The NodeList
to check.
- * @return true
, if each attribute node in nodes
has its parent in
- * nodes
as well.
+ * @return true
, if each attribute node in nodes
has
+ * its parent in nodes
as well.
*/
public static boolean checkAttributeParentsInNodeList(final NodeList nodes) {
final Set nodeSet = new HashSet();
@@ -939,15 +994,19 @@ public class DomUtils {
}
/**
- * Convert an unstructured NodeList
into a DocumentFragment
.
+ * Convert an unstructured NodeList
into a
+ * DocumentFragment
.
*
- * @param nodeList Contains the node list to be converted into a DOM DocumentFragment.
- * @return the resulting DocumentFragment. The DocumentFragment will be backed by a new DOM
- * Document, i.e. all noded of the node list will be cloned.
- * @throws ParserConfigurationException An error occurred creating the DocumentFragment.
+ * @param nodeList Contains the node list to be converted into a DOM
+ * DocumentFragment.
+ * @return the resulting DocumentFragment. The DocumentFragment will be backed
+ * by a new DOM Document, i.e. all noded of the node list will be
+ * cloned.
+ * @throws ParserConfigurationException An error occurred creating the
+ * DocumentFragment.
* @precondition The nodes in the node list appear in document order
- * @precondition for each Attr node in the node list, the owning Element is in the node list as
- * well.
+ * @precondition for each Attr node in the node list, the owning Element is in
+ * the node list as well.
* @precondition each Element or Attr node in the node list is namespace aware.
*/
public static DocumentFragment nodeList2DocumentFragment(final NodeList nodeList)
@@ -973,10 +1032,10 @@ public class DomUtils {
/**
* Helper method for the nodeList2DocumentFragment
.
*
- * @param nodeList The NodeList
to convert.
- * @param currPos The current position in the nodeList
.
- * @param result The resulting DocumentFragment
.
- * @param currOrgElem The current original element.
+ * @param nodeList The NodeList
to convert.
+ * @param currPos The current position in the nodeList
.
+ * @param result The resulting DocumentFragment
.
+ * @param currOrgElem The current original element.
* @param currClonedElem The current cloned element.
* @return The current position.
*/
@@ -1052,7 +1111,7 @@ public class DomUtils {
}
default: {
- log.trace("Node type: {} not supported", currentNode.getNodeType());
+ log.trace("Node type: {} not supported", currentNode.getNodeType());
// All other nodes will be ignored
}
}
@@ -1067,20 +1126,20 @@ public class DomUtils {
* Check, if the given attribute is a namespace declaration.
*
* @param attr The attribute to check.
- * @return true
, if the attribute is a namespace declaration, false
- * otherwise.
+ * @return true
, if the attribute is a namespace declaration,
+ * false
otherwise.
*/
private static boolean isNamespaceDeclaration(final Attr attr) {
- return XMLNamespaceConstants.XMLNS_NS_URI.equals(attr.getNamespaceURI());
+ return XmlNamespaceConstants.XMLNS_NS_URI.equals(attr.getNamespaceURI());
}
/**
* Check, if a given DOM element is an ancestor of a given node.
*
* @param candAnc The DOM element to check for being the ancestor.
- * @param cand The node to check for being the child.
- * @return true
, if candAnc
is an (indirect) ancestor of
- * cand
; false
otherwise.
+ * @param cand The node to check for being the child.
+ * @return true
, if candAnc
is an (indirect) ancestor
+ * of cand
; false
otherwise.
*/
public static boolean isAncestor(final Element candAnc, final Node cand) {
Node currPar = cand.getParentNode();
@@ -1098,8 +1157,9 @@ public class DomUtils {
* Selects the (first) element from a node list and returns it.
*
* @param nl The NodeList to get the element from.
- * @return The (first) element included in the node list or null
if the node list is
- * null
or empty or no element is included in the list.
+ * @return The (first) element included in the node list or null
if
+ * the node list is null
or empty or no element is included
+ * in the list.
*/
public static Element getElementFromNodeList(final NodeList nl) {
if (nl == null || nl.getLength() == 0) {
@@ -1119,8 +1179,8 @@ public class DomUtils {
*
* @param parent The element to get the child elements from.
*
- * @return A list including all child elements of the given element. Maybe empty if the parent
- * element has no child elements.
+ * @return A list including all child elements of the given element. Maybe empty
+ * if the parent element has no child elements.
*/
public static List getChildElements(final Element parent) {
final Vector v = new Vector();
@@ -1153,5 +1213,4 @@ public class DomUtils {
return out.toByteArray();
}
-
}
--
cgit v1.2.3