X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxml%2FDomUtils.java;h=d5e3bee47e1bc8b74612748829d8948ed46120a6;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=36f6077310b4b17f1ddbccfa76dfdaf37404f65f;hpb=89c06d4d52b46c154128c97d6e758fa1f4fc7a6e;p=utils diff --git a/support/general/src/main/java/org/wamblee/xml/DomUtils.java b/support/general/src/main/java/org/wamblee/xml/DomUtils.java index 36f60773..d5e3bee4 100644 --- a/support/general/src/main/java/org/wamblee/xml/DomUtils.java +++ b/support/general/src/main/java/org/wamblee/xml/DomUtils.java @@ -54,21 +54,17 @@ import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; - /** * Some basic XML utilities for common reoccuring tasks for DOM documents. - * + * * @author Erik Brakkee */ public final class DomUtils { - /** - * DOCUMENT ME! - */ private static final Log LOG = LogFactory.getLog(DomUtils.class); -/** + /** * Disabled default constructor. - * + * */ private DomUtils() { // Empty. @@ -76,12 +72,12 @@ public final class DomUtils { /** * Parses an XML document from a string. - * - * @param aDocument document. - * + * + * @param aDocument + * document. + * * @return - * - * @throws XMLException DOCUMENT ME! + * */ public static Document read(String aDocument) throws XMLException { ByteArrayInputStream is = new ByteArrayInputStream(aDocument.getBytes()); @@ -91,12 +87,12 @@ public final class DomUtils { /** * Parses an XML document from a stream. - * - * @param aIs Input stream. - * + * + * @param aIs + * Input stream. + * * @return - * - * @throws XMLException DOCUMENT ME! + * */ public static Document read(InputStream aIs) throws XMLException { try { @@ -121,19 +117,21 @@ public final class DomUtils { /** * Reads and validates a document against a schema. - * - * @param aIs Input stream. - * @param aSchema Schema. - * + * + * @param aIs + * Input stream. + * @param aSchema + * Schema. + * * @return Parsed and validated document. - * - * @throws XMLException DOCUMENT ME! + * */ public static Document readAndValidate(InputStream aIs, InputStream aSchema) throws XMLException { try { - final Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) - .newSchema(new StreamSource(aSchema)); + final Schema schema = SchemaFactory.newInstance( + XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema( + new StreamSource(aSchema)); final DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); @@ -165,11 +163,12 @@ public final class DomUtils { /** * Serializes an XML document to a stream. - * - * @param aDocument Document to serialize. - * @param aOs Output stream. - * - * @throws IOException DOCUMENT ME! + * + * @param aDocument + * Document to serialize. + * @param aOs + * Output stream. + * */ public static void serialize(Document aDocument, OutputStream aOs) throws IOException { @@ -179,15 +178,14 @@ public final class DomUtils { /** * Serializes an XML document. - * - * @param aDocument Document to serialize. - * + * + * @param aDocument + * Document to serialize. + * * @return Serialized document. - * - * @throws IOException DOCUMENT ME! + * */ - public static String serialize(Document aDocument) - throws IOException { + public static String serialize(Document aDocument) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); serialize(aDocument, os); @@ -196,12 +194,12 @@ public final class DomUtils { /** * Converts a dom4j document into a w3c DOM document. - * - * @param aDocument Document to convert. - * + * + * @param aDocument + * Document to convert. + * * @return W3C DOM document. - * - * @throws DocumentException DOCUMENT ME! + * */ public static Document convert(org.dom4j.Document aDocument) throws DocumentException { @@ -210,9 +208,10 @@ public final class DomUtils { /** * Converts a W3C DOM document into a dom4j document. - * - * @param aDocument Document to convert. - * + * + * @param aDocument + * Document to convert. + * * @return Dom4j document. */ public static org.dom4j.Document convert(Document aDocument) { @@ -222,10 +221,11 @@ public final class DomUtils { /** * Removes duplicate attributes from a DOM tree.This is useful for * postprocessing the output of JTidy as a workaround for a bug in JTidy. - * - * @param aNode Node to remove duplicate attributes from (recursively). - * Attributes of the node itself are not dealt with. Only the child - * nodes are dealt with. + * + * @param aNode + * Node to remove duplicate attributes from (recursively). + * Attributes of the node itself are not dealt with. Only the + * child nodes are dealt with. */ public static void removeDuplicateAttributes(Node aNode) { NodeList list = aNode.getChildNodes(); @@ -242,20 +242,21 @@ public final class DomUtils { /** * Removes duplicate attributes from an element. - * - * @param aElement Element. + * + * @param aElement + * Element. */ private static void removeDuplicateAttributes(Element aElement) { - NamedNodeMap attributes = aElement.getAttributes(); + NamedNodeMap attributes = aElement.getAttributes(); Map uniqueAttributes = new TreeMap(); - List attlist = new ArrayList(); + List attlist = new ArrayList(); for (int i = 0; i < attributes.getLength(); i++) { Attr attribute = (Attr) attributes.item(i); if (uniqueAttributes.containsKey(attribute.getNodeName())) { - LOG.info("Detected duplicate attribute (will be removed)'" - + attribute.getNodeName() + "'"); + LOG.info("Detected duplicate attribute (will be removed)'" + + attribute.getNodeName() + "'"); } uniqueAttributes.put(attribute.getNodeName(), attribute);