use of javax.xml.transform.dom.DOMResult in project lucene-solr by apache.
the class Config method copyDoc.
private static Document copyDoc(Document doc) throws TransformerException {
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer tx = tfactory.newTransformer();
DOMSource source = new DOMSource(doc);
DOMResult result = new DOMResult();
tx.transform(source, result);
return (Document) result.getNode();
}
use of javax.xml.transform.dom.DOMResult in project webservices-axiom by apache.
the class TestTransformerWithStylesheet method runTest.
protected void runTest() throws Throwable {
DocumentBuilder builder = dbf.newDocumentBuilder();
Document input = builder.parse(TestTransformerWithStylesheet.class.getResourceAsStream("input.xml"));
Document stylesheet = builder.parse(TestTransformerWithStylesheet.class.getResourceAsStream("stylesheet.xslt"));
Document expected = builder.parse(TestTransformerWithStylesheet.class.getResourceAsStream("output.xml"));
Document actual = builder.newDocument();
Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer(new DOMSource(stylesheet));
transformer.transform(new DOMSource(input), new DOMResult(actual));
assertAbout(xml()).that(xml(Document.class, actual)).ignoringWhitespace().hasSameContentAs(xml(Document.class, expected));
}
use of javax.xml.transform.dom.DOMResult in project webservices-axiom by apache.
the class SecureEchoTest method runTest.
@Override
protected void runTest() throws Throwable {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document requestDocument = documentBuilder.newDocument();
Element request = requestDocument.createElementNS("urn:test", "p:Echo");
request.setTextContent("Hello");
Document responseDocument = documentBuilder.newDocument();
context.getBean(WebServiceTemplate.class).sendSourceAndReceiveToResult(new DOMSource(request), new SoapActionCallback("http://www.example.com/echo"), new DOMResult(responseDocument));
Element response = responseDocument.getDocumentElement();
assertEquals("urn:test", response.getNamespaceURI());
assertEquals("Echo", response.getLocalName());
assertEquals("Hello", response.getTextContent());
}
use of javax.xml.transform.dom.DOMResult in project ddf by codice.
the class SchematronValidationService method generateReport.
private SchematronReport generateReport(String metadata, Templates validator) throws SchematronValidationException {
XMLReader xmlReader = null;
try {
XMLReader xmlParser = XMLReaderFactory.createXMLReader();
xmlParser.setFeature("http://xml.org/sax/features/external-general-entities", false);
xmlParser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
xmlParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
xmlReader = new XMLFilterImpl(xmlParser);
} catch (SAXException e) {
throw new SchematronValidationException(e);
}
SchematronReport report;
try {
Transformer transformer = validator.newTransformer();
DOMResult schematronResult = new DOMResult();
transformer.transform(new SAXSource(xmlReader, new InputSource(new StringReader(metadata))), schematronResult);
report = new SvrlReport(schematronResult);
} catch (TransformerException e) {
throw new SchematronValidationException("Could not setup validator to perform validation.", e);
}
return report;
}
use of javax.xml.transform.dom.DOMResult in project ddf by codice.
the class SchematronValidationService method compileSchematronRules.
private Templates compileSchematronRules(String schematronFileName) throws SchematronInitializationException {
Templates template;
File schematronFile = new File(schematronFileName);
if (!schematronFile.exists()) {
throw new SchematronInitializationException("Could not locate schematron file " + schematronFileName);
}
try {
URL schUrl = schematronFile.toURI().toURL();
Source schSource = new StreamSource(schUrl.toString());
// Stage 1: Perform inclusion expansion on Schematron schema file
DOMResult stage1Result = performStage(schSource, getClass().getClassLoader().getResource("iso-schematron/iso_dsdl_include.xsl"));
DOMSource stage1Output = new DOMSource(stage1Result.getNode());
// Stage 2: Perform abstract expansion on output file from Stage 1
DOMResult stage2Result = performStage(stage1Output, getClass().getClassLoader().getResource("iso-schematron/iso_abstract_expand.xsl"));
DOMSource stage2Output = new DOMSource(stage2Result.getNode());
// Stage 3: Compile the .sch rules that have been prepocessed by Stages 1 and 2 (i.e.,
// the output of Stage 2)
DOMResult stage3Result = performStage(stage2Output, getClass().getClassLoader().getResource("iso-schematron/iso_svrl_for_xslt2.xsl"));
DOMSource stage3Output = new DOMSource(stage3Result.getNode());
// Setting the system ID let's us resolve relative paths in the schematron files.
// We need the URL string so that the string is properly formatted (e.g. space = %20).
stage3Output.setSystemId(schUrl.toString());
template = transformerFactory.newTemplates(stage3Output);
} catch (Exception e) {
throw new SchematronInitializationException("Error trying to create SchematronValidationService using sch file " + schematronFileName, e);
}
return template;
}
Aggregations