use of javax.xml.stream.XMLEventReader in project poi by apache.
the class PresetGeometries method init.
@SuppressWarnings("unused")
public void init(InputStream is) throws XMLStreamException, JAXBException {
// StAX:
EventFilter startElementFilter = new EventFilter() {
@Override
public boolean accept(XMLEvent event) {
return event.isStartElement();
}
};
XMLInputFactory staxFactory = XMLInputFactory.newFactory();
XMLEventReader staxReader = staxFactory.createXMLEventReader(is);
XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter);
// ignore StartElement:
/* XMLEvent evDoc = */
staxFiltRd.nextEvent();
// JAXB:
JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
long cntElem = 0;
while (staxFiltRd.peek() != null) {
StartElement evRoot = (StartElement) staxFiltRd.peek();
String name = evRoot.getName().getLocalPart();
JAXBElement<CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class);
CTCustomGeometry2D cus = el.getValue();
cntElem++;
if (containsKey(name)) {
LOG.log(POILogger.WARN, "Duplicate definition of " + name);
}
put(name, new CustomGeometry(cus));
}
}
use of javax.xml.stream.XMLEventReader in project tomee by apache.
the class StaxCompare method compare.
public static void compare(final String a, final String b) throws Exception {
final StringBuilder message = new StringBuilder();
final XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
final XMLEventReader rA = factory.createXMLEventReader(new StringReader(a));
final XMLEventReader rB = factory.createXMLEventReader(new StringReader(b));
if (!compare(rA, rB, message)) {
throw new Exception(message.toString());
}
}
Aggregations