-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from davidwatkins73/master
Another attempt at getting visio to work
- Loading branch information
Showing
8 changed files
with
169 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
waltz-common/src/main/java/com/khartec/waltz/common/XmlUtilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.khartec.waltz.common; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
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 java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.util.stream.Stream; | ||
|
||
public class XmlUtilities { | ||
|
||
public static Stream<Node> stream(NodeList nodeList) { | ||
Node[] nodes = new Node[nodeList.getLength()]; | ||
|
||
for (int i = 0; i < nodeList.getLength(); i++) { | ||
nodes[i] = nodeList.item(i); | ||
} | ||
return Stream.of(nodes); | ||
} | ||
|
||
|
||
public static String printDocument(Document doc) throws IOException, TransformerException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
printDocument(doc, baos); | ||
return new String(baos.toByteArray()); | ||
} | ||
|
||
|
||
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { | ||
TransformerFactory tf = TransformerFactory.newInstance(); | ||
Transformer transformer = tf.newTransformer(); | ||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); | ||
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(doc), | ||
new StreamResult(new OutputStreamWriter(out, "UTF-8"))); | ||
} | ||
|
||
public static DocumentBuilderFactory createNonValidatingDocumentBuilderFactory() throws ParserConfigurationException { | ||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
|
||
factory.setValidating(false); | ||
factory.setNamespaceAware(true); | ||
factory.setFeature("http://xml.org/sax/features/namespaces", false); | ||
factory.setFeature("http://xml.org/sax/features/validation", false); | ||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); | ||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); | ||
|
||
return factory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters