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 gephi by gephi.
the class LoadTask method readWorkspace.
private WorkspaceImpl readWorkspace(ProjectImpl project, String entryName, ZipFile zipFile) throws Exception {
ZipEntry entry = zipFile.getEntry(entryName);
if (entry != null) {
InputStream is = null;
try {
is = zipFile.getInputStream(entry);
InputStreamReader isReader = null;
Xml10FilterReader filterReader = null;
XMLStreamReader reader = null;
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
}
inputFactory.setXMLReporter(new XMLReporter() {
@Override
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
}
});
isReader = new InputStreamReader(is, "UTF-8");
filterReader = new Xml10FilterReader(isReader);
reader = inputFactory.createXMLStreamReader(filterReader);
return GephiReader.readWorkspace(reader, project);
} finally {
if (reader != null) {
reader.close();
}
if (filterReader != null) {
filterReader.close();
}
if (isReader != null) {
isReader.close();
}
}
} finally {
if (is != null) {
is.close();
}
}
}
return null;
}
use of javax.xml.stream.XMLInputFactory in project gephi by gephi.
the class ImporterGraphML method execute.
@Override
public boolean execute(ContainerLoader container) {
this.container = container;
this.report = new Report();
Progress.start(progress);
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
if (inputFactory.isPropertySupported("javax.xml.stream.isValidating")) {
inputFactory.setProperty("javax.xml.stream.isValidating", Boolean.FALSE);
}
inputFactory.setXMLReporter(new XMLReporter() {
@Override
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException {
}
});
xmlReader = inputFactory.createXMLStreamReader(reader);
while (xmlReader.hasNext()) {
Integer eventType = xmlReader.next();
if (eventType.equals(XMLEvent.START_ELEMENT)) {
String name = xmlReader.getLocalName();
if (GRAPHML.equalsIgnoreCase(name)) {
} else if (GRAPH.equalsIgnoreCase(name)) {
readGraph(xmlReader);
} else if (NODE.equalsIgnoreCase(name)) {
readNode(xmlReader, null);
} else if (EDGE.equalsIgnoreCase(name)) {
readEdge(xmlReader);
} else if (ATTRIBUTE.equalsIgnoreCase(name)) {
readAttribute(xmlReader);
}
} else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
String name = xmlReader.getLocalName();
if (NODE.equalsIgnoreCase(name)) {
}
}
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
} finally {
try {
xmlReader.close();
} catch (XMLStreamException e) {
}
}
Progress.finish(progress);
return !cancel;
}
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;
}
Aggregations