From: Andreas Beeker Date: Sun, 9 Dec 2018 02:08:50 +0000 (+0000) Subject: #62966 - init presetShapeDefinitions.xml fail under IBM jdk X-Git-Tag: REL_4_1_0~202 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fba0181413a937234ca0cb65f72d8182b8987356;p=poi.git #62966 - init presetShapeDefinitions.xml fail under IBM jdk git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1848494 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java index a188e6e255..f8b461f929 100644 --- a/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java +++ b/src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java @@ -27,12 +27,12 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.EventFilter; -import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; +import javax.xml.transform.stream.StreamSource; import org.apache.poi.sl.draw.binding.CTCustomGeometry2D; import org.apache.poi.util.POILogFactory; @@ -61,27 +61,30 @@ public class PresetGeometries extends LinkedHashMap { }; XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory(); - 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(); + XMLStreamReader streamReader = staxFactory.createXMLStreamReader(new StreamSource(is)); + try { + // ignore StartElement: + streamReader.nextTag(); - long cntElem = 0; - while (staxFiltRd.peek() != null) { - StartElement evRoot = (StartElement)staxFiltRd.peek(); - String name = evRoot.getName().getLocalPart(); - JAXBElement el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class); - CTCustomGeometry2D cus = el.getValue(); - cntElem++; - - if(containsKey(name)) { - LOG.log(POILogger.WARN, "Duplicate definition of " + name); + // JAXB: + JAXBContext jaxbContext = JAXBContext.newInstance(BINDING_PACKAGE); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + long cntElem = 0; + while (streamReader.hasNext() && streamReader.nextTag() == XMLStreamConstants.START_ELEMENT) { + String name = streamReader.getLocalName(); + JAXBElement el = unmarshaller.unmarshal(streamReader, CTCustomGeometry2D.class); + CTCustomGeometry2D cus = el.getValue(); + cntElem++; + + if (containsKey(name)) { + LOG.log(POILogger.WARN, "Duplicate definition of " + name); + } + put(name, new CustomGeometry(cus)); } - put(name, new CustomGeometry(cus)); - } + } finally { + streamReader.close(); + } } /**