use of javax.xml.transform.dom.DOMSource in project spring-framework by spring-projects.
the class SourceHttpMessageConverterTests method readDOMSourceExternal.
@Test
public void readDOMSourceExternal() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
converter.setSupportDtd(true);
DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage);
Document document = (Document) result.getNode();
assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName());
assertNotEquals("Invalid result", "Foo Bar", document.getDocumentElement().getTextContent());
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class SaxonConverterTest method convertToDOMSource.
@Test
public void convertToDOMSource() throws XPathException {
DOMSource source = context.getTypeConverter().convertTo(DOMSource.class, exchange, doc);
assertNotNull(source);
String string = context.getTypeConverter().convertTo(String.class, exchange, source);
assertEquals(CONTENT, string);
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class XAdESSignaturePropertiesTest method validateAgainstSchema.
private void validateAgainstSchema(Document doc) throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source schema1 = new StreamSource(new File("target/test-classes/org/apache/camel/component/xmlsecurity/xades/XAdES.xsd"));
Source schema2 = new StreamSource(new File("target/test-classes/org/apache/camel/component/xmlsecurity/xades/xmldsig-core-schema.xsd"));
Schema schema = factory.newSchema(new Source[] { schema2, schema1 });
Validator validator = schema.newValidator();
validator.validate(new DOMSource(doc));
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class EipDocumentationEnricherMojo method saveToFile.
private void saveToFile(Document document, File outputFile, Transformer transformer) throws FileNotFoundException, TransformerException {
StreamResult result = new StreamResult(new FileOutputStream(outputFile));
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class SpringBootStarterMojo method writeXmlFormatted.
private void writeXmlFormatted(Document pom, File destination) throws Exception {
XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("//text()[normalize-space(.) = '']");
NodeList emptyNodes = (NodeList) xpath.evaluate(pom, XPathConstants.NODESET);
// Remove empty text nodes
for (int i = 0; i < emptyNodes.getLength(); i++) {
Node emptyNode = emptyNodes.item(i);
emptyNode.getParentNode().removeChild(emptyNode);
}
pom.setXmlStandalone(true);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(pom);
String content;
try (StringWriter out = new StringWriter()) {
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
content = out.toString();
}
// Fix header formatting problem
content = content.replaceFirst("-->", "-->\n").replaceFirst("\\?><!--", "\\?>\n<!--");
writeIfChanged(content, destination);
}
Aggregations