use of javax.xml.transform.sax.SAXSource in project asterixdb by apache.
the class TestSuiteParser method parse.
public org.apache.asterix.testframework.xml.TestSuite parse(File testSuiteCatalog) throws Exception {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setXIncludeAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "file");
JAXBContext ctx = JAXBContext.newInstance(org.apache.asterix.testframework.xml.TestSuite.class);
Unmarshaller um = ctx.createUnmarshaller();
return (org.apache.asterix.testframework.xml.TestSuite) um.unmarshal(new SAXSource(saxParser.getXMLReader(), new InputSource(testSuiteCatalog.toURI().toString())));
}
use of javax.xml.transform.sax.SAXSource in project geode by apache.
the class ManagedEntityConfigXmlGenerator method generate.
/////////////////////// Instance Methods ///////////////////////
/**
* Generates XML and writes it to the given <code>PrintWriter</code>
*/
private void generate(PrintWriter pw) {
// XML text
try {
Source src = new SAXSource(this, new InputSource());
Result res = new StreamResult(pw);
TransformerFactory xFactory = TransformerFactory.newInstance();
Transformer xform = xFactory.newTransformer();
xform.setOutputProperty(OutputKeys.METHOD, "xml");
xform.setOutputProperty(OutputKeys.INDENT, "yes");
xform.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, SYSTEM_ID);
xform.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, PUBLIC_ID);
xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
xform.transform(src, res);
pw.flush();
} catch (Exception ex) {
RuntimeException ex2 = new RuntimeException(LocalizedStrings.ManagedEntityConfigXmlGenerator_EXCEPTION_THROWN_WHILE_GENERATING_XML.toLocalizedString());
ex2.initCause(ex);
throw ex2;
}
}
use of javax.xml.transform.sax.SAXSource in project karaf by apache.
the class JaxbUtil method unmarshalNoValidate.
private static Features unmarshalNoValidate(String uri, InputStream stream) {
try {
Unmarshaller unmarshaller = FEATURES_CONTEXT.createUnmarshaller();
NoSourceAndNamespaceFilter xmlFilter = new NoSourceAndNamespaceFilter(XmlUtils.xmlReader());
xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
InputSource is = new InputSource(uri);
if (stream != null) {
is.setByteStream(stream);
}
SAXSource source = new SAXSource(xmlFilter, is);
Features features = (Features) unmarshaller.unmarshal(source);
features.setNamespace(xmlFilter.getNamespace());
return features;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Unable to load " + uri, e);
}
}
use of javax.xml.transform.sax.SAXSource in project sling by apache.
the class XmlUtil method prettyPrint.
public static String prettyPrint(InputSource is) {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
// initialize StreamResult with File object to save to file
StreamResult result = new StreamResult(new StringWriter());
Source source = new SAXSource(is);
transformer.transform(source, result);
return result.getWriter().toString();
} catch (Exception e) {
// Catch generic error as panel should still work if xml apis are
// not
// resolved
log.warn("Error occurred while transforming xml", e);
} finally {
Util.close(is);
}
return "Source not found";
}
use of javax.xml.transform.sax.SAXSource in project uPortal by Jasig.
the class BaseXsltDataUpgraderTest method loadSchema.
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException {
Assert.notEmpty(resources, "No resources given");
Assert.hasLength(schemaLanguage, "No schema language provided");
Source[] schemaSources = new Source[resources.length];
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
for (int i = 0; i < resources.length; i++) {
Assert.notNull(resources[i], "Resource is null");
Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist");
InputSource inputSource = SaxResourceUtils.createInputSource(resources[i]);
schemaSources[i] = new SAXSource(xmlReader, inputSource);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
return schemaFactory.newSchema(schemaSources);
}
Aggregations