use of javax.xml.stream.XMLInputFactory in project hibernate-orm by hibernate.
the class JaxbCfgProcessor method buildStaxFactory.
@SuppressWarnings({ "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
staxFactory.setXMLResolver(xmlResourceResolver);
return staxFactory;
}
use of javax.xml.stream.XMLInputFactory in project hibernate-orm by hibernate.
the class AbstractBinder method buildStaxFactory.
@SuppressWarnings({ "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
staxFactory.setXMLResolver(xmlResourceResolver);
return staxFactory;
}
use of javax.xml.stream.XMLInputFactory in project languagetool by languagetool-org.
the class IpaExtractor method run.
private void run(FileInputStream fis) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(fis);
String title = null;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
String elementName = event.asStartElement().getName().getLocalPart();
switch(elementName) {
case "title":
XMLEvent nextEvent = reader.nextEvent();
title = nextEvent.asCharacters().getData();
articleCount++;
break;
case "text":
ipaCount += handleTextElement(title, reader);
break;
}
}
}
}
use of javax.xml.stream.XMLInputFactory in project languagetool by languagetool-org.
the class AtomFeedParser method getAtomFeedItems.
List<AtomFeedItem> getAtomFeedItems(InputStream xml) throws XMLStreamException {
String id = null;
String title = null;
Date date = null;
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(xml);
try {
List<AtomFeedItem> items = new ArrayList<>();
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
String localPart = event.asStartElement().getName().getLocalPart();
switch(localPart) {
case "id":
id = getCharacterData(eventReader);
break;
case "title":
title = getCharacterData(eventReader);
break;
case "updated":
String dateString = getCharacterData(eventReader);
try {
// e.g. 2013-12-03T09:48:29Z - got this from http://stackoverflow.com/questions/6038136,
// with SimpleDateParser the hour is off by one:
date = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateString).toGregorianCalendar().getTime();
} catch (Exception e) {
throw new RuntimeException("Could not parse date string '" + dateString + "'", e);
}
break;
case "summary":
if (id == null || title == null || date == null) {
throw new RuntimeException("id, title and/or date is null: id=" + id + ", title=" + title + ", date=" + date);
}
items.add(new AtomFeedItem(id, title, getCharacterData(eventReader), date));
id = null;
title = null;
date = null;
break;
}
}
}
return items;
} finally {
eventReader.close();
}
}
use of javax.xml.stream.XMLInputFactory in project sonarqube by SonarSource.
the class DebtRulesXMLImporter method initStax.
private static SMInputFactory initStax() {
XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
xmlFactory.setProperty(IS_COALESCING, TRUE);
xmlFactory.setProperty(IS_NAMESPACE_AWARE, FALSE);
xmlFactory.setProperty(SUPPORT_DTD, FALSE);
xmlFactory.setProperty(IS_VALIDATING, FALSE);
return new SMInputFactory(xmlFactory);
}
Aggregations