diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2018-12-09 02:08:50 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2018-12-09 02:08:50 +0000 |
commit | fba0181413a937234ca0cb65f72d8182b8987356 (patch) | |
tree | 53bc2fa016802f59b85dd60836b193da6bc02353 /src/java/org | |
parent | dc3c437d145599fb3993325b3b90d6544656885e (diff) | |
download | poi-fba0181413a937234ca0cb65f72d8182b8987356.tar.gz poi-fba0181413a937234ca0cb65f72d8182b8987356.zip |
#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
Diffstat (limited to 'src/java/org')
-rw-r--r-- | src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java | 45 |
1 files changed, 24 insertions, 21 deletions
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<String, CustomGeometry> { }; 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<CTCustomGeometry2D> 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<CTCustomGeometry2D> 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(); + } } /** |