use of org.xml.sax.InputSource in project spring-boot by spring-projects.
the class Versions method evaluateExpression.
private static String evaluateExpression(String expression) {
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xpath = xPathFactory.newXPath();
XPathExpression expr = xpath.compile(expression);
String version = expr.evaluate(new InputSource(new FileReader("target/dependencies-pom.xml")));
return version;
} catch (Exception ex) {
throw new IllegalStateException("Failed to evaluate expression", ex);
}
}
use of org.xml.sax.InputSource in project spring-framework by spring-projects.
the class XmlBeanDefinitionReaderTests method withInputSource.
@Test(expected = BeanDefinitionStoreException.class)
public void withInputSource() {
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
InputSource resource = new InputSource(getClass().getResourceAsStream("test.xml"));
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
}
use of org.xml.sax.InputSource in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method convert.
public Spanned convert() {
mReader.setContentHandler(this);
try {
mReader.parse(new InputSource(new StringReader(mSource)));
} catch (IOException e) {
// We are reading from a string. There should not be IO problems.
throw new RuntimeException(e);
} catch (SAXException e) {
// TagSoup doesn't throw parse exceptions.
throw new RuntimeException(e);
}
// Fix flags and range for paragraph-type markup.
Object[] obj = mSpannableStringBuilder.getSpans(0, mSpannableStringBuilder.length(), ParagraphStyle.class);
for (int i = 0; i < obj.length; i++) {
int start = mSpannableStringBuilder.getSpanStart(obj[i]);
int end = mSpannableStringBuilder.getSpanEnd(obj[i]);
// If the last line of the range is blank, back off by one.
if (end - 2 >= 0) {
if (mSpannableStringBuilder.charAt(end - 1) == '\n' && mSpannableStringBuilder.charAt(end - 2) == '\n') {
end--;
}
}
if (end == start) {
mSpannableStringBuilder.removeSpan(obj[i]);
} else {
mSpannableStringBuilder.setSpan(obj[i], start, end, Spannable.SPAN_PARAGRAPH);
}
}
return mSpannableStringBuilder;
}
use of org.xml.sax.InputSource in project es6draft by anba.
the class IntlDataTools method xml.
private static Document xml(Reader xml) throws IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// turn off any validation or namespace features
factory.setNamespaceAware(false);
factory.setValidating(false);
List<String> features = Arrays.asList("http://xml.org/sax/features/namespaces", "http://xml.org/sax/features/validation", "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", "http://apache.org/xml/features/nonvalidating/load-external-dtd");
for (String feature : features) {
try {
factory.setFeature(feature, false);
} catch (ParserConfigurationException e) {
// ignore invalid feature names
}
}
try {
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource source = new InputSource(xml);
return builder.parse(source);
} catch (ParserConfigurationException | SAXException e) {
throw new IOException(e);
}
}
use of org.xml.sax.InputSource in project hadoop by apache.
the class TestAMWebServices method verifyBlacklistedNodesInfoXML.
public void verifyBlacklistedNodesInfoXML(String xml, AppContext ctx) throws JSONException, Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList infonodes = dom.getElementsByTagName("blacklistednodesinfo");
assertEquals("incorrect number of elements", 1, infonodes.getLength());
NodeList nodes = dom.getElementsByTagName("blacklistedNodes");
Set<String> blacklistedNodes = ctx.getBlacklistedNodes();
assertEquals("incorrect number of elements", blacklistedNodes.size(), nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
assertTrue(blacklistedNodes.contains(element.getFirstChild().getNodeValue()));
}
}
Aggregations