use of javax.xml.transform.stream.StreamSource in project gradle by gradle.
the class XslTransformer method main.
public static void main(String[] args) throws TransformerException, IOException {
if (args.length < 3 || args.length > 4) {
throw new IllegalArgumentException("USAGE: <style-sheet> <source-file> <dest-file> [dest-dir]");
}
File stylesheet = new File(args[0]);
File source = new File(args[1]);
File dest = new File(args[2]);
String destDir = "";
if (args.length > 3) {
destDir = args[3];
}
System.out.format("=> stylesheet %s%n", stylesheet);
System.out.format("=> source %s%n", source);
System.out.format("=> dest %s%n", dest);
System.out.format("=> destDir %s%n", destDir);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(stylesheet));
System.out.format("=> transformer %s (%s)%n", transformer, transformer.getClass().getName());
if (destDir.length() > 0) {
transformer.setParameter("base.dir", destDir + "/");
}
FileOutputStream outstr = new FileOutputStream(dest);
try {
transformer.transform(new StreamSource(source), new StreamResult(outstr));
} finally {
outstr.close();
}
}
use of javax.xml.transform.stream.StreamSource in project graphhopper by graphhopper.
the class InstructionListTest method verifyGPX.
public void verifyGPX(String gpx) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = null;
try {
Source schemaFile = new StreamSource(getClass().getResourceAsStream("gpx-schema.xsd"));
schema = schemaFactory.newSchema(schemaFile);
// using more schemas: http://stackoverflow.com/q/1094893/194609
} catch (SAXException e1) {
throw new IllegalStateException("There was a problem with the schema supplied for validation. Message:" + e1.getMessage());
}
Validator validator = schema.newValidator();
try {
validator.validate(new StreamSource(new StringReader(gpx)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.xml.transform.stream.StreamSource in project hazelcast by hazelcast.
the class DiscoverySpiTest method testSchema.
@Test
public void testSchema() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi.xml";
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaResource = DiscoverySpiTest.class.getClassLoader().getResource("hazelcast-config-3.9.xsd");
assertNotNull(schemaResource);
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Source source = new StreamSource(xmlResource);
Schema schema = factory.newSchema(schemaResource);
Validator validator = schema.newValidator();
validator.validate(source);
}
use of javax.xml.transform.stream.StreamSource in project zaproxy by zaproxy.
the class ReportGenerator method XMLToHtml.
public static File XMLToHtml(Document xmlDocument, String infilexsl, File outFile) {
File stylesheet = null;
outFile = new File(outFile.getAbsolutePath());
try {
stylesheet = new File(infilexsl);
DOMSource source = new DOMSource(xmlDocument);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
// Make the transformation and write to the output file
StreamResult result = new StreamResult(outFile);
transformer.transform(source, result);
} catch (TransformerException e) {
logger.error(e.getMessage(), e);
}
return outFile;
}
use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.
the class SaajEmptyNamespaceTest method createSoapMessage.
// Create SOAP message with empty body
private static SOAPMessage createSoapMessage() throws SOAPException, UnsupportedEncodingException {
String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<SOAP-ENV:Body/></SOAP-ENV:Envelope>";
MessageFactory mFactory = MessageFactory.newInstance();
SOAPMessage msg = mFactory.createMessage();
msg.getSOAPPart().setContent(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))));
return msg;
}
Aggregations