use of javax.xml.transform.sax.SAXSource in project opennms by OpenNMS.
the class RrdConvertUtils method dumpRrd.
/**
* Dumps a RRD.
*
* @param sourceFile the source file
* @return the RRD Object
* @throws IOException Signals that an I/O exception has occurred.
* @throws RrdException the RRD exception
*/
public static RRDv3 dumpRrd(File sourceFile) throws IOException, RrdException {
String rrdBinary = System.getProperty("rrd.binary");
if (rrdBinary == null) {
throw new IllegalArgumentException("rrd.binary property must be set");
}
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
Process process = Runtime.getRuntime().exec(new String[] { rrdBinary, "dump", sourceFile.getAbsolutePath() });
SAXSource source = new SAXSource(xmlReader, new InputSource(new InputStreamReader(process.getInputStream())));
JAXBContext jc = JAXBContext.newInstance(RRDv3.class);
Unmarshaller u = jc.createUnmarshaller();
return (RRDv3) u.unmarshal(source);
} catch (Exception e) {
throw new RrdException("Can't parse RRD Dump", e);
}
}
use of javax.xml.transform.sax.SAXSource in project uPortal by Jasig.
the class SpELDataTemplatingStrategy method processTemplates.
@Override
public Source processTemplates(Document data, String filename) {
log.trace("Processing templates for document XML={}", data.asXML());
for (String xpath : XPATH_EXPRESSIONS) {
@SuppressWarnings("unchecked") List<Node> nodes = data.selectNodes(xpath);
for (Node n : nodes) {
String inpt, otpt;
switch(n.getNodeType()) {
case org.w3c.dom.Node.ATTRIBUTE_NODE:
Attribute a = (Attribute) n;
inpt = a.getValue();
otpt = processText(inpt);
if (otpt == null) {
throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename);
}
if (!otpt.equals(inpt)) {
a.setValue(otpt);
}
break;
case org.w3c.dom.Node.TEXT_NODE:
case org.w3c.dom.Node.CDATA_SECTION_NODE:
inpt = n.getText();
otpt = processText(inpt);
if (otpt == null) {
throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename);
}
if (!otpt.equals(inpt)) {
n.setText(otpt);
}
break;
default:
String msg = "Unsupported node type: " + n.getNodeTypeName();
throw new RuntimeException(msg);
}
}
}
final SAXSource rslt = new DocumentSource(data);
// must be set, else import chokes
rslt.setSystemId(filename);
return rslt;
}
use of javax.xml.transform.sax.SAXSource in project jdk8u_jdk by JetBrains.
the class ValidationWarningsTest method doOneTestIteration.
//One iteration of xml validation test case. It will be called from each
//TestWorker task defined in WarningsTestBase class.
void doOneTestIteration() throws Exception {
Source src = new StreamSource(new StringReader(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
SAXSource xsdSource = new SAXSource(new InputSource(new ByteArrayInputStream(xsd.getBytes())));
Schema schema = schemaFactory.newSchema(xsdSource);
Validator v = schema.newValidator();
v.validate(src);
}
use of javax.xml.transform.sax.SAXSource in project jdk8u_jdk by JetBrains.
the class XSLTExFuncTest method transform.
void transform(TransformerFactory factory) throws TransformerConfigurationException, TransformerException {
SAXSource xslSource = new SAXSource(new InputSource(xslFile));
xslSource.setSystemId(xslFileId);
Transformer transformer = factory.newTransformer(xslSource);
StringWriter stringResult = new StringWriter();
Result result = new StreamResult(stringResult);
transformer.transform(new SAXSource(new InputSource(xmlFile)), result);
}
use of javax.xml.transform.sax.SAXSource in project voltdb by VoltDB.
the class JDBCSQLXML method createSAXSource.
/**
* Retrieves a new SAXSource for reading the XML value designated by this
* SQLXML instance. <p>
*
* @param sourceClass The class of the source
* @throws java.sql.SQLException if there is an error processing the XML
* value or if the given <tt>sourceClass</tt> is not supported.
* @return a new SAXSource for reading the XML value designated by this
* SQLXML instance
*/
@SuppressWarnings("unchecked")
protected <T extends Source> T createSAXSource(Class<T> sourceClass) throws SQLException {
SAXSource source = null;
try {
source = (sourceClass == null) ? new SAXSource() : (SAXSource) sourceClass.newInstance();
} catch (SecurityException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (InstantiationException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (IllegalAccessException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (ClassCastException ex) {
throw Exceptions.sourceInstantiation(ex);
}
Reader reader = getCharacterStreamImpl();
InputSource inputSource = new InputSource(reader);
source.setInputSource(inputSource);
return (T) source;
}
Aggregations