use of javax.xml.transform.Source in project camel by apache.
the class JmsXMLRouteTest method testTampaWithFileStreamAsObject.
@Test
public void testTampaWithFileStreamAsObject() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tampa");
mock.expectedMessageCount(1);
mock.message(0).body(String.class).contains("Hiram");
Source source = new StreamSource(new FileInputStream(TEST_TAMPA));
assertNotNull(source);
template.sendBody("direct:object", source);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.Source in project camel by apache.
the class XmlFixture method transform.
protected static Document transform(Document aDocument, String aResourcePath) throws Exception {
TransformerFactory tf = TransformerFactory.newInstance();
InputStream in = XmlFixture.class.getResourceAsStream(aResourcePath);
Source src = new StreamSource(in);
src.setSystemId(XmlFixture.class.getResource(aResourcePath).toExternalForm());
Transformer t = tf.newTransformer(src);
DOMResult result = new DOMResult();
t.transform(new DOMSource(aDocument), result);
return (Document) result.getNode();
}
use of javax.xml.transform.Source in project tomcat by apache.
the class DefaultServlet method secureXslt.
private Source secureXslt(InputStream is) {
// Need to filter out any external entities
Source result = null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(secureEntityResolver);
Document document = builder.parse(is);
result = new DOMSource(document);
} catch (ParserConfigurationException | SAXException | IOException e) {
if (debug > 0) {
log(e.getMessage(), e);
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
return result;
}
use of javax.xml.transform.Source in project che by eclipse.
the class BuildFileGenerator method documentToString.
/** Convert document to formatted XML string. */
private String documentToString(Document doc) throws TransformerException {
StringWriter writer = new StringWriter();
Source source = new DOMSource(doc);
Result result = new StreamResult(writer);
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute("indent-number", "4");
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
return writer.toString();
}
use of javax.xml.transform.Source in project qi4j-sdk by Qi4j.
the class QuikitServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
try {
mountPoints = new TreeMap<String, Page>();
documentFactory = DocumentBuilderFactory.newInstance();
documentFactory.setNamespaceAware(true);
ClassLoader cl = getClass().getClassLoader();
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Source[] schemaSources = new Source[2];
schemaSources[0] = new StreamSource(cl.getResourceAsStream("xhtml1-strict.xsd"));
schemaSources[1] = new StreamSource(cl.getResourceAsStream("xml.xsd"));
Schema schema = schemaFactory.newSchema(schemaSources);
documentFactory.setSchema(schema);
ApplicationAssembler assembler = createApplicationAssembler(config);
Energy4Java qi4j = new Energy4Java();
application = qi4j.newApplication(assembler);
application.activate();
Module module = application.findModule("WebLayer", "PagesModule");
finder = module;
if (application.mode() == Application.Mode.development) {
DataInitializer initializer = module.newTransient(DataInitializer.class);
initializer.initialize();
}
Iterable<ServiceReference<Page>> iterable = finder.findServices(Page.class);
for (ServiceReference<Page> page : iterable) {
PageMetaInfo pageMetaInfo = page.metaInfo(PageMetaInfo.class);
String mountPoint = pageMetaInfo.mountPoint();
mountPoints.put(mountPoint, page.get());
}
} catch (Exception e) {
throw new ServletException("Can not initialize Qi4j.", e);
}
}
Aggregations