Author: tallison
Date: Thu Apr 27 18:50:22 2017
New Revision: 1792940

URL: http://svn.apache.org/viewvc?rev=1792940&view=rev
Log:
bug 61051 -- add new worksheet-like relations for xlsb

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java?rev=1792940&r1=1792939&r2=1792940&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java 
(original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java 
Thu Apr 27 18:50:22 2017
@@ -19,10 +19,14 @@ package org.apache.poi.xssf.eventusermod
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
@@ -53,7 +57,17 @@ import org.apache.poi.xssf.usermodel.XSS
  */
 public class XSSFBReader extends XSSFReader {
 
-    private final static POILogger log = 
POILogFactory.getLogger(XSSFBReader.class);
+    private static final POILogger log = 
POILogFactory.getLogger(XSSFBReader.class);
+    private static final Set<String> WORKSHEET_RELS =
+            Collections.unmodifiableSet(new HashSet<String>(
+                    Arrays.asList(new String[]{
+                            XSSFRelation.WORKSHEET.getRelation(),
+                            XSSFRelation.CHARTSHEET.getRelation(),
+                            XSSFRelation.MACRO_SHEET_BIN.getRelation(),
+                            XSSFRelation.INTL_MACRO_SHEET_BIN.getRelation(),
+                            XSSFRelation.DIALOG_SHEET_BIN.getRelation()
+                    })
+            ));
 
     /**
      * Creates a new XSSFReader, for the given package
@@ -105,7 +119,6 @@ public class XSSFBReader extends XSSFRea
 
     }
 
-
     public static class SheetIterator extends XSSFReader.SheetIterator {
 
         /**
@@ -117,6 +130,11 @@ public class XSSFBReader extends XSSFRea
             super(wb);
         }
 
+        @Override
+        Set<String> getSheetRelationships() {
+            return WORKSHEET_RELS;
+        }
+
         Iterator<XSSFSheetRef> createSheetIteratorFromWB(PackagePart wb) 
throws IOException {
             SheetRefLoader sheetRefLoader = new 
SheetRefLoader(wb.getInputStream());
             sheetRefLoader.parse();

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java?rev=1792940&r1=1792939&r2=1792940&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java 
Thu Apr 27 18:50:22 2017
@@ -20,13 +20,16 @@ import javax.xml.parsers.ParserConfigura
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.poi.POIXMLException;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -64,6 +67,13 @@ import org.xml.sax.helpers.DefaultHandle
  */
 public class XSSFReader {
 
+    private static final Set<String> WORKSHEET_RELS =
+            Collections.unmodifiableSet(new HashSet<String>(
+                    Arrays.asList(new String[]{
+                            XSSFRelation.WORKSHEET.getRelation(),
+                            XSSFRelation.CHARTSHEET.getRelation(),
+                    })
+            ));
     private static final POILogger LOGGER = 
POILogFactory.getLogger(XSSFReader.class);
 
     protected OPCPackage pkg;
@@ -123,7 +133,6 @@ public class XSSFReader {
     }
 
 
-
     /**
      * Returns an InputStream to read the contents of the
      *  shared strings table.
@@ -223,11 +232,10 @@ public class XSSFReader {
                 //step 1. Map sheet's relationship Id and the corresponding 
PackagePart
                 sheetMap = new HashMap<String, PackagePart>();
                 OPCPackage pkg = wb.getPackage();
-                String REL_WORKSHEET = XSSFRelation.WORKSHEET.getRelation();
-                String REL_CHARTSHEET = XSSFRelation.CHARTSHEET.getRelation();
+                Set<String> worksheetRels = getSheetRelationships();
                 for(PackageRelationship rel : wb.getRelationships()){
                     String relType = rel.getRelationshipType();
-                    if (relType.equals(REL_WORKSHEET) || 
relType.equals(REL_CHARTSHEET)) {
+                    if (worksheetRels.contains(relType)) {
                         PackagePartName relName = 
PackagingURIHelper.createPartName(rel.getTargetURI());
                         sheetMap.put(rel.getId(), pkg.getPart(relName));
                     }
@@ -269,6 +277,17 @@ public class XSSFReader {
             return validSheets.iterator();
         }
 
+        /**
+         * Gets string representations of relationships
+         * that are sheet-like.  Added to allow subclassing
+         * by XSSFBReader.  This is used to decide what
+         * relationships to load into the sheetRefs
+         *
+         * @return
+         */
+        Set<String> getSheetRelationships() {
+            return WORKSHEET_RELS;
+        }
 
         /**
          * Returns <tt>true</tt> if the iteration has more elements.

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java?rev=1792940&r1=1792939&r2=1792940&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java 
Thu Apr 27 18:50:22 2017
@@ -286,6 +286,27 @@ public final class XSSFRelation extends
         null
     );
 
+    public static final XSSFRelation MACRO_SHEET_BIN = new XSSFRelation(
+            null,//TODO: figure out what this should be?
+            
"http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet";,
+            "/xl/macroSheets/sheet#.bin",
+            null
+    );
+
+    public static final XSSFRelation INTL_MACRO_SHEET_BIN = new XSSFRelation(
+            null,//TODO: figure out what this should be?
+            
"http://schemas.microsoft.com/office/2006/relationships/xlIntlMacrosheet";,
+            "/xl/macroSheets/sheet#.bin",
+            null
+    );
+
+    public static final XSSFRelation DIALOG_SHEET_BIN = new XSSFRelation(
+            null,//TODO: figure out what this should be?
+            
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet";,
+            "/xl/dialogSheets/sheet#.bin",
+            null
+    );
+
     public static final XSSFRelation THEME = new XSSFRelation(
         "application/vnd.openxmlformats-officedocument.theme+xml",
         
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";,



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to