]> source.dussan.org Git - poi.git/commitdiff
#62966 - init presetShapeDefinitions.xml fail under IBM jdk
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 9 Dec 2018 02:08:50 +0000 (02:08 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 9 Dec 2018 02:08:50 +0000 (02:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1848494 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/draw/geom/PresetGeometries.java

index a188e6e255ed77f1a1742e9ba4a0463291b74d01..f8b461f929437d16d7ab3ae763338fd263b727ae 100644 (file)
@@ -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();
+        }
     }
     
     /**