added XMLDocument, XMLSchema, and XSLTransformation classes.
[utils] / support / general / src / main / java / org / wamblee / xml / DomUtils.java
index a0a118c1062cd82e8fd0aac29bb84fb01a371fb3..f283ee07d9d51ff344d9f803fede157a70eba521 100644 (file)
@@ -71,50 +71,6 @@ public final class DomUtils {
         // Empty.
     }
 
-    /**
-     * Parses an XML document from a string.
-     * 
-     * @param aDocument
-     *            document.
-     * 
-     * @return
-     * 
-     */
-    public static Document read(String aDocument) throws XMLException {
-        ByteArrayInputStream is = new ByteArrayInputStream(aDocument.getBytes());
-
-        return read(is);
-    }
-
-    /**
-     * Parses an XML document from a stream.
-     * 
-     * @param aIs
-     *            Input stream.
-     * 
-     * @return
-     * 
-     */
-    public static Document read(InputStream aIs) throws XMLException {
-        try {
-            DOMImplementationLS impl = getDomImplementationLS();
-
-            LSParser builder = impl.createLSParser(
-                DOMImplementationLS.MODE_SYNCHRONOUS, null);
-            LSInput input = impl.createLSInput();
-            input.setByteStream(aIs);
-            return builder.parse(input);
-        } catch (LSException e) {
-            throw new XMLException(e.getMessage(), e);
-        } finally {
-            try {
-                aIs.close();
-            } catch (Exception e) {
-                LOG.log(Level.WARNING, "Error closing XML file", e);
-            }
-        }
-    }
-
     /**
      * Gets a dom level 3 implementation. 
      * @return Dom implementation.
@@ -142,85 +98,6 @@ public final class DomUtils {
         }
     }
 
-    /**
-     * Reads and validates a document against a schema.
-     * 
-     * @param aIs
-     *            Input stream.
-     * @param aSchema
-     *            Schema.
-     * 
-     * @return Parsed and validated document.
-     * 
-     */
-    public static Document readAndValidate(InputStream aIs, InputStream aSchema)
-        throws XMLException {
-        try {
-            Document doc = read(aIs);
-            final Schema schema = SchemaFactory.newInstance(
-                XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
-                new StreamSource(aSchema));
-            Validator validator = schema.newValidator();
-            validator.validate(new DOMSource(doc));
-
-            return doc;
-        } catch (SAXException e) {
-            throw new XMLException(e.getMessage(), e);
-        } catch (IOException e) {
-            throw new XMLException(e.getMessage(), e);
-        } finally {
-            try {
-                aSchema.close();
-            } catch (Exception e) {
-                LOG.log(Level.WARNING, "Error closing schema", e);
-            }
-
-            try {
-                aIs.close();
-            } catch (Exception e) {
-                LOG.log(Level.WARNING, "Error closing XML file", e);
-            }
-        }
-    }
-
-    /**
-     * Serializes an XML document to a stream.
-     * 
-     * @param aDocument
-     *            Document to serialize.
-     * @param aOs
-     *            Output stream.
-     * 
-     */
-    public static void serialize(Document aDocument, OutputStream aOs)
-        throws IOException {
-        try {
-            TransformerFactory factory = TransformerFactory.newInstance();
-            Transformer identityTransform = factory.newTransformer();
-            DOMSource source = new DOMSource(aDocument);
-            StreamResult result = new StreamResult(aOs);
-            identityTransform.transform(source, result);
-        } catch (TransformerException e) {
-            throw new IOException(e.getMessage(), e);
-        }
-    }
-
-    /**
-     * Serializes an XML document.
-     * 
-     * @param aDocument
-     *            Document to serialize.
-     * 
-     * @return Serialized document.
-     * 
-     */
-    public static String serialize(Document aDocument) throws IOException {
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        serialize(aDocument, os);
-
-        return os.toString();
-    }
-
     /**
      * Removes duplicate attributes from a DOM tree.This is useful for
      * postprocessing the output of JTidy as a workaround for a bug in JTidy.