Commit bfadf0ec authored by R.W.Majeed's avatar R.W.Majeed

DOM printing moved to separate class

parent ff0107b1
......@@ -17,12 +17,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
......@@ -40,6 +35,7 @@ import de.sekmi.histream.ObservationException;
import de.sekmi.histream.ObservationSupplier;
import de.sekmi.histream.impl.ExternalSourceImpl;
import de.sekmi.histream.impl.Meta;
import de.sekmi.histream.xml.XMLUtils;
public class TestXMLWriter {
private Path debugFile;
......@@ -59,13 +55,6 @@ public class TestXMLWriter {
Files.delete(debugFile);
}
private void printDocument(Document doc) throws TransformerException{
DOMSource source = new DOMSource(doc);
Transformer t;
t = TransformerFactory.newInstance().newTransformer();
t.transform(source, new StreamResult(debugLog));
}
private Document createDocument() throws ParserConfigurationException{
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
......@@ -179,7 +168,7 @@ public class TestXMLWriter {
s.close();
doc.normalizeDocument();
printDocument(doc);
XMLUtils.printDOM(doc, debugLog);
}
@Test
public void testWriteStream() throws Exception{
......
package de.sekmi.histream.xml;
import java.io.OutputStream;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;
public class XMLUtils {
public static void printDOM(Node node, OutputStream out) throws TransformerException{
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(node),
new StreamResult(out));
}
}
package de.sekmi.histream.export.config;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.junit.Test;
import org.w3c.dom.Node;
import de.sekmi.histream.ObservationSupplier;
import de.sekmi.histream.export.VisitFragmentSupplier;
import de.sekmi.histream.io.FileObservationProviderTest;
import de.sekmi.histream.xml.XMLUtils;
public class TestVisitFragmentParser {
......@@ -28,20 +19,8 @@ public class TestVisitFragmentParser {
VisitFragmentSupplier sup = new VisitFragmentSupplier(s);
Node n = sup.get();
//System.out.println(n.toString());
printDOM(n);
XMLUtils.printDOM(n, System.out);
}
}
private void printDOM(Node node) throws UnsupportedEncodingException, TransformerException{
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(node),
new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment