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();
}
-
}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/EaafDomEntityResolver.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/EaafDomEntityResolver.java
index 6139e914..5a7dadc7 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/EaafDomEntityResolver.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/EaafDomEntityResolver.java
@@ -17,19 +17,20 @@
* works that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
-
package at.gv.egiz.eaaf.core.impl.utils;
import java.io.InputStream;
-import at.gv.egiz.eaaf.core.api.data.XMLNamespaceConstants;
+
import org.apache.xerces.util.URI;
import org.apache.xerces.util.URI.MalformedURIException;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import at.gv.egiz.eaaf.core.api.data.XmlNamespaceConstants;
+
/**
- * An EntityResolver
that looks up entities stored as local resources.
+ * An EntityResolver
that looks up entities stored as local
+ * resources.
*
* * The following DTDs are mapped to local resources: @@ -39,25 +40,27 @@ import org.xml.sax.InputSource; * *
* - * For all other resources, an attempt is made to resolve them as resources, either absolute or - * relative toConstants.SCHEMA_ROOT
.
+ * For all other resources, an attempt is made to resolve them as resources,
+ * either absolute or relative to Constants.SCHEMA_ROOT
.
*
*/
public class EaafDomEntityResolver implements EntityResolver {
/**
* Resolve an entity.
- *
- * The systemId
parameter is used to perform the lookup of the entity as a resource,
- * either by interpreting the systemId
as an absolute resource path, or by appending
- * the last path component of systemId
to Constants.SCHEMA_ROOT
.
- *
+ * The systemId
parameter is used to perform the lookup of the
+ * entity as a resource, either by interpreting the systemId
as an
+ * absolute resource path, or by appending the last path component of
+ * systemId
to Constants.SCHEMA_ROOT
.
+ *
InputSource
from which the entity can be read, or null
, if
- * the entity could not be found.
- * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
+ * @return An InputSource
from which the entity can be read, or
+ * null
, if the entity could not be found.
+ * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String,
+ * java.lang.String)
*/
@Override
public InputSource resolveEntity(final String publicId, String systemId) {
@@ -68,10 +71,10 @@ public class EaafDomEntityResolver implements EntityResolver {
// check if we can resolve some standard dtd's
if (publicId.equalsIgnoreCase("-//W3C//DTD XMLSchema 200102//EN")) {
return new InputSource(
- getClass().getResourceAsStream(XMLNamespaceConstants.SCHEMA_ROOT + "XMLSchema.dtd"));
+ getClass().getResourceAsStream(XmlNamespaceConstants.SCHEMA_ROOT + "XMLSchema.dtd"));
} else if (publicId.equalsIgnoreCase("datatypes")) {
return new InputSource(
- getClass().getResourceAsStream(XMLNamespaceConstants.SCHEMA_ROOT + "datatypes.dtd"));
+ getClass().getResourceAsStream(XmlNamespaceConstants.SCHEMA_ROOT + "datatypes.dtd"));
}
} else if (systemId != null) {
// get the URI path
@@ -100,7 +103,7 @@ public class EaafDomEntityResolver implements EntityResolver {
slashPos = systemId.lastIndexOf('/');
if (slashPos >= 0 && systemId.length() > slashPos) {
systemId = systemId.substring(slashPos + 1, systemId.length());
- stream = getClass().getResourceAsStream(XMLNamespaceConstants.SCHEMA_ROOT + systemId);
+ stream = getClass().getResourceAsStream(XmlNamespaceConstants.SCHEMA_ROOT + systemId);
if (stream != null) {
final InputSource source = new InputSource(stream);
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
index d6745c78..3adbe3f5 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/utils/XPathUtils.java
@@ -17,14 +17,11 @@
* works that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
-
package at.gv.egiz.eaaf.core.impl.utils;
import java.util.List;
import java.util.Map;
-import at.gv.egiz.eaaf.core.api.data.XMLNamespaceConstants;
-import at.gv.egiz.eaaf.core.exceptions.XPathException;
+
import org.jaxen.JaxenException;
import org.jaxen.NamespaceContext;
import org.jaxen.Navigator;
@@ -37,6 +34,9 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.traversal.NodeIterator;
+import at.gv.egiz.eaaf.core.api.data.XmlNamespaceConstants;
+import at.gv.egiz.eaaf.core.exceptions.XPathException;
+
/**
* Utility methods to evaluate XPath expressions on DOM nodes.
*
@@ -46,7 +46,8 @@ import org.w3c.dom.traversal.NodeIterator;
public class XPathUtils {
/**
- * The XPath expression selecting all nodes under a given root (including the root node itself).
+ * The XPath expression selecting all nodes under a given root (including the
+ * root node itself).
*/
public static final String ALL_NODES_XPATH = "(.//. | .//@* | .//namespace::*)";
@@ -57,49 +58,50 @@ public class XPathUtils {
static {
final SimpleNamespaceContext ctx = new SimpleNamespaceContext();
- ctx.addNamespace(XMLNamespaceConstants.MOA_PREFIX, XMLNamespaceConstants.MOA_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MOA_CONFIG_PREFIX,
- XMLNamespaceConstants.MOA_CONFIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MOA_ID_CONFIG_PREFIX,
- XMLNamespaceConstants.MOA_ID_CONFIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL10_PREFIX, XMLNamespaceConstants.SL10_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL11_PREFIX, XMLNamespaceConstants.SL11_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SL12_PREFIX, XMLNamespaceConstants.SL12_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.ECDSA_PREFIX, XMLNamespaceConstants.ECDSA_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.PD_PREFIX, XMLNamespaceConstants.PD_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML_PREFIX, XMLNamespaceConstants.SAML_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAMLP_PREFIX, XMLNamespaceConstants.SAMLP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_PREFIX, XMLNamespaceConstants.DSIG_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XSLT_PREFIX, XMLNamespaceConstants.XSLT_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XSI_PREFIX, XMLNamespaceConstants.XSI_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_FILTER2_PREFIX,
- XMLNamespaceConstants.DSIG_FILTER2_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.DSIG_EC_PREFIX, XMLNamespaceConstants.DSIG_EC_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MD_PREFIX, XMLNamespaceConstants.MD_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MDP_PREFIX, XMLNamespaceConstants.MDP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.MVV_PREFIX, XMLNamespaceConstants.MVV_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STB_PREFIX, XMLNamespaceConstants.STB_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.WRR_PREFIX, XMLNamespaceConstants.WRR_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STORK_PREFIX, XMLNamespaceConstants.STORK_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.STORKP_PREFIX, XMLNamespaceConstants.STORKP_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML2_PREFIX, XMLNamespaceConstants.SAML2_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.SAML2P_PREFIX, XMLNamespaceConstants.SAML2P_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XENC_PREFIX, XMLNamespaceConstants.XENC_NS_URI);
- ctx.addNamespace(XMLNamespaceConstants.XADES_1_1_1_NS_PREFIX,
- XMLNamespaceConstants.XADES_1_1_1_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_PREFIX, XmlNamespaceConstants.MOA_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_CONFIG_PREFIX,
+ XmlNamespaceConstants.MOA_CONFIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MOA_ID_CONFIG_PREFIX,
+ XmlNamespaceConstants.MOA_ID_CONFIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL10_PREFIX, XmlNamespaceConstants.SL10_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL11_PREFIX, XmlNamespaceConstants.SL11_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SL12_PREFIX, XmlNamespaceConstants.SL12_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.ECDSA_PREFIX, XmlNamespaceConstants.ECDSA_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.PD_PREFIX, XmlNamespaceConstants.PD_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML_PREFIX, XmlNamespaceConstants.SAML_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAMLP_PREFIX, XmlNamespaceConstants.SAMLP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_PREFIX, XmlNamespaceConstants.DSIG_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XSLT_PREFIX, XmlNamespaceConstants.XSLT_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XSI_PREFIX, XmlNamespaceConstants.XSI_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_FILTER2_PREFIX,
+ XmlNamespaceConstants.DSIG_FILTER2_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.DSIG_EC_PREFIX, XmlNamespaceConstants.DSIG_EC_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MD_PREFIX, XmlNamespaceConstants.MD_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MDP_PREFIX, XmlNamespaceConstants.MDP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.MVV_PREFIX, XmlNamespaceConstants.MVV_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STB_PREFIX, XmlNamespaceConstants.STB_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.WRR_PREFIX, XmlNamespaceConstants.WRR_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STORK_PREFIX, XmlNamespaceConstants.STORK_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.STORKP_PREFIX, XmlNamespaceConstants.STORKP_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML2_PREFIX, XmlNamespaceConstants.SAML2_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.SAML2P_PREFIX, XmlNamespaceConstants.SAML2P_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XENC_PREFIX, XmlNamespaceConstants.XENC_NS_URI);
+ ctx.addNamespace(XmlNamespaceConstants.XADES_1_1_1_NS_PREFIX,
+ XmlNamespaceConstants.XADES_1_1_1_NS_URI);
NS_CONTEXT = ctx;
}
/**
- * Return a NodeIterator
over the nodes matching the XPath expression.
+ * Return a NodeIterator
over the nodes matching the XPath
+ * expression.
*
- *
- * All namespace URIs and prefixes declared in the Constants
interface are used for
- * resolving namespaces.
- *
+ * All namespace URIs and prefixes declared in the Constants
+ * interface are used for resolving namespaces.
+ *
NodeIterator
over the nodes matching the XPath expression.
+ * Return a NodeIterator
over the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -134,12 +138,15 @@ public class XPathUtils {
}
/**
- * Return a NodeIterator
over the nodes matching the XPath expression.
+ * Return a NodeIterator
over the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (String
to
- * String
) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (String
to String
) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -152,12 +159,14 @@ public class XPathUtils {
}
/**
- * Return a NodeIterator
over the nodes matching the XPath expression.
+ * Return a NodeIterator
over the nodes matching the XPath
+ * expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The NamespaceContext
for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param nsContext The NamespaceContext
for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
* @return An iterator over the resulting nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -179,13 +188,15 @@ public class XPathUtils {
}
/**
- * Return a NodeList
of all the nodes matching the XPath expression.
- *
- * All namespace URIs and prefixes declared in the Constants
interface are used for
- * resolving namespaces.
- *
NodeList
of all the nodes matching the XPath
+ * expression.
+ *
+ * All namespace URIs and prefixes declared in the Constants
+ * interface are used for resolving namespaces.
+ *
NodeList
containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -196,12 +207,14 @@ public class XPathUtils {
}
/**
- * Return a NodeList
of all the nodes matching the XPath expression.
+ * Return a NodeList
of all the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
* @return A NodeList
containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -221,12 +234,15 @@ public class XPathUtils {
}
/**
- * Return a NodeList
of all the nodes matching the XPath expression.
+ * Return a NodeList
of all the nodes matching the XPath
+ * expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (String
to
- * String
) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (String
to String
) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
* @return A NodeList
containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -239,12 +255,14 @@ public class XPathUtils {
}
/**
- * Return a NodeList
of all the nodes matching the XPath expression.
+ * Return a NodeList
of all the nodes matching the XPath
+ * expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The NamespaceContext
for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
+ * @param nsContext The NamespaceContext
for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
* @return A NodeList
containing the matching nodes.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
@@ -265,14 +283,15 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
- *
- * All namespace URIs and prefixes declared in the Constants
interface are used for
- * resolving namespaces.
- *
+ * All namespace URIs and prefixes declared in the Constants
+ * interface are used for resolving namespaces.
+ *
null
, if no node
- * matched.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * null
, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final String exp)
@@ -284,12 +303,13 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceElement An element from which to build the namespace mapping for evaluating the
- * XPath expression
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or null
, if no node
- * matched.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceElement An element from which to build the namespace mapping
+ * for evaluating the XPath expression
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * null
, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final Element namespaceElement,
@@ -309,12 +329,14 @@ public class XPathUtils {
/**
* Select the first node matching an XPath expression.
*
- * @param contextNode The root node from which to evaluate the XPath expression.
- * @param namespaceMapping A namespace prefix to namespace URI mapping (String
to
- * String
) for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or null
, if no node
- * matched.
+ * @param contextNode The root node from which to evaluate the XPath
+ * expression.
+ * @param namespaceMapping A namespace prefix to namespace URI mapping
+ * (String
to String
) for
+ * evaluating the XPath expression.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * null
, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final Map namespaceMapping,
@@ -329,11 +351,12 @@ public class XPathUtils {
* Select the first node matching an XPath expression.
*
* @param contextNode The root node from which to evaluate the XPath expression.
- * @param nsContext The NamespaceContext
for resolving namespace prefixes to
- * namespace URIs for evaluating the XPath expression.
- * @param exp The XPath expression to evaluate.
- * @return Node The first node matching the XPath expression, or null
, if no node
- * matched.
+ * @param nsContext The NamespaceContext
for resolving namespace
+ * prefixes to namespace URIs for evaluating the XPath
+ * expression.
+ * @param exp The XPath expression to evaluate.
+ * @return Node The first node matching the XPath expression, or
+ * null
, if no node matched.
* @throws XPathException An error occurred evaluating the XPath expression.
*/
public static Node selectSingleNode(final Node contextNode, final NamespaceContext nsContext,
@@ -351,14 +374,16 @@ public class XPathUtils {
}
/**
- * Return the value of a DOM element whose location is given by an XPath expression.
+ * Return the value of a DOM element whose location is given by an XPath
+ * expression.
*
- * @param root The root element from which to evaluate the XPath.
- * @param xpath The XPath expression pointing to the element whose value to return.
- * @param def The default value to return, if no element can be found using the given
- * xpath
.
- * @return The element value, if it can be located using the xpath
. Otherwise,
- * def
is returned.
+ * @param root The root element from which to evaluate the XPath.
+ * @param xpath The XPath expression pointing to the element whose value to
+ * return.
+ * @param def The default value to return, if no element can be found using
+ * the given xpath
.
+ * @return The element value, if it can be located using the xpath
.
+ * Otherwise, def
is returned.
*/
public static String getElementValue(final Element root, final String xpath, final String def) {
@@ -367,14 +392,16 @@ public class XPathUtils {
}
/**
- * Return the value of a DOM attribute whose location is given by an XPath expression.
+ * Return the value of a DOM attribute whose location is given by an XPath
+ * expression.
*
- * @param root The root element from which to evaluate the XPath.
- * @param xpath The XPath expression pointing to the attribute whose value to return.
- * @param def The default value to return, if no attribute can be found using the given
- * xpath
.
- * @return The element value, if it can be located using the xpath
. Otherwise,
- * def
is returned.
+ * @param root The root element from which to evaluate the XPath.
+ * @param xpath The XPath expression pointing to the attribute whose value to
+ * return.
+ * @param def The default value to return, if no attribute can be found using
+ * the given xpath
.
+ * @return The element value, if it can be located using the xpath
.
+ * Otherwise, def
is returned.
*/
public static String getAttributeValue(final Element root, final String xpath, final String def) {
@@ -383,31 +410,36 @@ public class XPathUtils {
}
/**
- * Returns the namespace prefix used within XPathUtils
for referring to the namespace
- * of the specified (Security Layer command) element.
- *
- * This namespace prefix can be used in various XPath expression evaluation methods within
- * XPathUtils
without explicitely binding it to the particular namespace.
- *
XPathUtils
for
+ * referring to the namespace of the specified (Security Layer command) element.
+ *
+ * This namespace prefix can be used in various XPath expression evaluation
+ * methods within XPathUtils
without explicitely binding it to the
+ * particular namespace.
+ *
XPathUtils
for referring to the namespace
- * of the specified (Security Layer command) element.
+ * @return the namespace prefix used within XPathUtils
for
+ * referring to the namespace of the specified (Security Layer command)
+ * element.
*
- * throws XpathException If the specified element has a namespace other than the ones
- * known by this implementation as valid Security Layer namespaces (cf.
- * @link Constants#SL10_NS_URI, @link Constants#SL11_NS_URI, @link Constants#SL12_NS_URI).
+ * throws XpathException If the specified element has a namespace other
+ * than the ones known by this implementation as valid Security Layer
+ * namespaces (cf.
+ * @link Constants#SL10_NS_URI, @link Constants#SL11_NS_URI, @link
+ * Constants#SL12_NS_URI).
*/
public static String getSlPrefix(final Element contextElement) throws XPathException {
final String sLNamespace = contextElement.getNamespaceURI();
String slPrefix = null;
- if (sLNamespace.equals(XMLNamespaceConstants.SL10_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL10_PREFIX;
- } else if (sLNamespace.equals(XMLNamespaceConstants.SL12_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL12_PREFIX;
- } else if (sLNamespace.equals(XMLNamespaceConstants.SL11_NS_URI)) {
- slPrefix = XMLNamespaceConstants.SL11_PREFIX;
+ if (sLNamespace.equals(XmlNamespaceConstants.SL10_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL10_PREFIX;
+ } else if (sLNamespace.equals(XmlNamespaceConstants.SL12_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL12_PREFIX;
+ } else if (sLNamespace.equals(XmlNamespaceConstants.SL11_NS_URI)) {
+ slPrefix = XmlNamespaceConstants.SL11_PREFIX;
} else {
throw new XPathException("XPath operation FAILED. Reason: ");
}
@@ -415,36 +447,38 @@ public class XPathUtils {
return slPrefix;
}
-
/**
- * Return the SecurityLayer namespace prefix of the context element. If the context element is not
- * the element that lies within the SecurityLayer namespace. The Securitylayer namespace is
- * derived from the xmlns:sl10
, sl11
or sl
attribute of the
- * context element.
- *
+ * Return the SecurityLayer namespace prefix of the context element. If the
+ * context element is not the element that lies within the SecurityLayer
+ * namespace. The Securitylayer namespace is derived from the
+ * xmlns:sl10
, sl11
or sl
attribute of
+ * the context element.
+ *
* The returned prefix is needed for evaluating XPATH expressions. - *
- * @param contextElement The element to get a prefix for the Securitylayer namespace, that is used - * within the corresponding document. + * + * + * @param contextElement The element to get a prefix for the Securitylayer + * namespace, that is used within the corresponding + * document. * - * @return The stringsl10
, sl11
or sl
, depending on the
- * SecurityLayer namespace of the contextElement.
+ * @return The string sl10
, sl11
or sl
,
+ * depending on the SecurityLayer namespace of the contextElement.
*
- * throws XPathException If no (vlalid) SecurityLayer namespace prefix or namespace is
- * defined.
+ * throws XPathException If no (vlalid) SecurityLayer namespace prefix
+ * or namespace is defined.
*/
public static String getSlPrefixFromNoRoot(final Element contextElement) throws XPathException {
- String slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL10_PREFIX,
- XMLNamespaceConstants.SL10_NS_URI);
+ String slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL10_PREFIX,
+ XmlNamespaceConstants.SL10_NS_URI);
if (slPrefix == null) {
- slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL11_PREFIX,
- XMLNamespaceConstants.SL11_NS_URI);
+ slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL11_PREFIX,
+ XmlNamespaceConstants.SL11_NS_URI);
}
if (slPrefix == null) {
- slPrefix = checkSLnsDeclaration(contextElement, XMLNamespaceConstants.SL12_PREFIX,
- XMLNamespaceConstants.SL12_NS_URI);
+ slPrefix = checkSLnsDeclaration(contextElement, XmlNamespaceConstants.SL12_PREFIX,
+ XmlNamespaceConstants.SL12_NS_URI);
}
return slPrefix;
@@ -452,15 +486,18 @@ public class XPathUtils {
}
/**
- * Checks if the context element has an attribute xmlns:slPrefix
and if the prefix of
- * that attribute corresponds with a valid SecurityLayer namespace.
+ * Checks if the context element has an attribute xmlns:slPrefix
+ * and if the prefix of that attribute corresponds with a valid SecurityLayer
+ * namespace.
*
* @param contextElement The element to be checked.
- * @param slPrefix The prefix which should be checked. Must be a valid SecurityLayer namespace
- * prefix.
- * @param slNameSpace The SecurityLayer namespace that corresponds to the specified prefix.
+ * @param slPrefix The prefix which should be checked. Must be a valid
+ * SecurityLayer namespace prefix.
+ * @param slNameSpace The SecurityLayer namespace that corresponds to the
+ * specified prefix.
*
- * @return The valid SecurityLayer prefix or null
if this prefix is not used.
+ * @return The valid SecurityLayer prefix or null
if this prefix is
+ * not used.
* @throws XPathException In case of an error
*/
private static String checkSLnsDeclaration(final Element contextElement, final String slPrefix,
--
cgit v1.2.3