reduced dependencies
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / util / xml / XMLHelper.java
1 package com.quantum.util.xml;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6 import java.io.Writer;
7
8 import javax.xml.parsers.DocumentBuilder;
9 import javax.xml.parsers.DocumentBuilderFactory;
10 import javax.xml.parsers.FactoryConfigurationError;
11 import javax.xml.parsers.ParserConfigurationException;
12
13 import org.w3c.dom.Document;
14 import org.xml.sax.SAXException;
15
16
17 /**
18  * <p>This class constructs a pretty-printing XML Serializer
19  * 
20  * @author BC
21  */
22 public class XMLHelper {
23     
24     private XMLHelper() {}
25     
26     public static Document createEmptyDocument() throws ParserConfigurationException {
27         DocumentBuilder builder = createDocumentBuilder();
28         return builder.newDocument();
29     }
30     
31     public static Document createFromInputStream(InputStream stream) 
32         throws IOException, SAXException, ParserConfigurationException {
33         DocumentBuilder builder = createDocumentBuilder();
34         return builder.parse(stream);
35     }
36
37     private static DocumentBuilder createDocumentBuilder()
38         throws FactoryConfigurationError, ParserConfigurationException {
39         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
40         return factory.newDocumentBuilder();
41     }
42     
43     public static void write(Writer writer, Document document) 
44         throws IOException {
45         writer.write(XMLRenderer.render(document));
46     }
47
48     public static void write(OutputStream stream, Document document) 
49         throws IOException {
50         stream.write(XMLRenderer.render(document).getBytes());
51     }
52 }