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
This commit is contained in:
Tim Allison 2017-04-27 18:50:22 +00:00
parent 5f567f29a1
commit a98eaeb917
3 changed files with 64 additions and 6 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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",