aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Allison <tallison@apache.org>2017-04-27 18:50:22 +0000
committerTim Allison <tallison@apache.org>2017-04-27 18:50:22 +0000
commit2e303725668dd86c0084d323a8fd44e9e5756c13 (patch)
treee4345e90668fe61ad31794dd4a956cbb9bd05a92
parent62ce8f211e9d34ac9e522d53a61da675391baa32 (diff)
downloadpoi-2e303725668dd86c0084d323a8fd44e9e5756c13.tar.gz
poi-2e303725668dd86c0084d323a8fd44e9e5756c13.zip
bug 61051 -- add new worksheet-like relations for xlsb
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1792940 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java22
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java27
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java21
3 files changed, 64 insertions, 6 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
index 0606ecec48..6653ee655d 100644
--- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
+++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
@@ -19,10 +19,14 @@ package org.apache.poi.xssf.eventusermodel;
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.XSSFRelation;
*/
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 XSSFReader {
}
-
public static class SheetIterator extends XSSFReader.SheetIterator {
/**
@@ -117,6 +130,11 @@ public class XSSFBReader extends XSSFReader {
super(wb);
}
+ @Override
+ Set<String> getSheetRelationships() {
+ return WORKSHEET_RELS;
+ }
+
Iterator<XSSFSheetRef> createSheetIteratorFromWB(PackagePart wb) throws IOException {
SheetRefLoader sheetRefLoader = new SheetRefLoader(wb.getInputStream());
sheetRefLoader.parse();
diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
index 08dfaa6ff8..68a85df546 100644
--- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
+++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
@@ -20,13 +20,16 @@ import javax.xml.parsers.ParserConfigurationException;
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.DefaultHandler;
*/
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.
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
index 019d552a28..dee6706f30 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
@@ -286,6 +286,27 @@ public final class XSSFRelation extends POIXMLRelation {
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",