use of javax.xml.transform.dom.DOMSource in project jersey by jersey.
the class WadlResourceTest method extractWadlAsDocument.
/**
* Extracts WADL as {@link Document} from given {@link Response}.
*
* @param response The response to extract {@code Document} from.
* @return The extracted {@code Document}.
* @throws ParserConfigurationException In case of parser configuration issues.
* @throws SAXException In case of parsing issues.
* @throws IOException In case of IO error.
*/
static Document extractWadlAsDocument(final Response response) throws ParserConfigurationException, SAXException, IOException {
assertEquals(200, response.getStatus());
final File tmpFile = response.readEntity(File.class);
final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
bf.setXIncludeAware(false);
}
final DocumentBuilder b = bf.newDocumentBuilder();
final Document d = b.parse(tmpFile);
Wadl5Test.printSource(new DOMSource(d));
return d;
}
use of javax.xml.transform.dom.DOMSource in project android-selector-intellij-plugin by importre.
the class AndroidSelectorDialog method createDrawableV21.
private void createDrawableV21(String filename, String color, String pressed) throws Exception {
VirtualFile child = dir.findChild(drawableV21Dir);
if (child == null) {
child = dir.createChildDirectory(null, drawableV21Dir);
}
VirtualFile newXmlFile = child.findChild(filename);
if (newXmlFile != null && newXmlFile.exists()) {
newXmlFile.delete(null);
}
newXmlFile = child.createChildData(null, filename);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("ripple");
root.setAttributeNS(nsUri, "xmlns:android", androidUri);
root.setAttribute("android:color", pressed);
doc.appendChild(root);
Element item = doc.createElement("item");
item.setAttribute("android:drawable", color);
root.appendChild(item);
OutputStream os = newXmlFile.getOutputStream(null);
PrintWriter out = new PrintWriter(os);
StringWriter writer = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(INDENT_SPACE, "4");
transformer.transform(new DOMSource(doc), new StreamResult(writer));
out.println(writer.getBuffer().toString());
out.close();
}
use of javax.xml.transform.dom.DOMSource in project AndroidAsync by koush.
the class DocumentBody method prepare.
private void prepare() {
if (bout != null)
return;
try {
DOMSource source = new DOMSource(document);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
bout = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(bout, Charsets.UTF_8);
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
writer.flush();
} catch (Exception e) {
}
}
use of javax.xml.transform.dom.DOMSource in project languagetool by languagetool-org.
the class XMLValidator method mergeIntoSource.
private static Source mergeIntoSource(InputStream baseXmlStream, InputStream xmlStream) throws Exception {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setIgnoringComments(true);
domFactory.setValidating(false);
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document baseDoc = builder.parse(baseXmlStream);
Document ruleDoc = builder.parse(xmlStream);
// Shall this be more generic, i.e. reuse not just unification ???
NodeList unificationNodes = baseDoc.getElementsByTagName("unification");
Node ruleNode = ruleDoc.getElementsByTagName("rules").item(0);
Node firstChildRuleNode = ruleNode.getChildNodes().item(1);
for (int i = 0; i < unificationNodes.getLength(); i++) {
Node unificationNode = ruleDoc.importNode(unificationNodes.item(i), true);
ruleNode.insertBefore(unificationNode, firstChildRuleNode);
}
return new DOMSource(ruleDoc);
}
use of javax.xml.transform.dom.DOMSource in project jop by jop-devel.
the class XmlBuilder method writeDom.
/**
* @param dom
* @param s
* @throws TransformerFactoryConfigurationError
* @throws XmlSerializationException
*/
public static void writeDom(Document dom, Writer s) throws TransformerFactoryConfigurationError, XmlSerializationException {
DOMSource domSource = new DOMSource(dom);
StreamResult streamResult = new StreamResult(s);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer;
try {
serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.transform(domSource, streamResult);
} catch (Exception e) {
throw new XmlSerializationException("Error in domToString()", e);
}
}
Aggregations