Fix bug #51955 - XSSFReader supplied StylesTables need to have the theme data available

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1179440 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-10-05 21:05:00 +00:00
parent abba248c50
commit ea20b0b885
4 changed files with 36 additions and 3 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta5" date="2011-??-??">
<action dev="poi-developers" type="fix">51955 - XSSFReader supplied StylesTables need to have the theme data available</action>
<action dev="poi-developers" type="fix">51716 - Removed incorrect assert in SXSSFSheet#getSXSSFSheet</action>
<action dev="poi-developers" type="fix">51834 - Opening and Writing .doc file results in corrupt document</action>
<action dev="poi-developers" type="fix">51902 - Picture.fillRawImageContent - ArrayIndexOutOfBoundsException (duplicate)</action>

View File

@ -36,6 +36,7 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
@ -83,7 +84,15 @@ public class XSSFReader {
*/
public StylesTable getStylesTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType( XSSFRelation.STYLES.getContentType());
return parts.size() == 0 ? null : new StylesTable(parts.get(0), null);
if(parts.size() == 0) return null;
// Create the Styles Table, and associate the Themes if present
StylesTable styles = new StylesTable(parts.get(0), null);
parts = pkg.getPartsByContentType( XSSFRelation.THEME.getContentType());
if(parts.size() != 0) {
styles.setTheme(new ThemesTable(parts.get(0), null));
}
return styles;
}
@ -104,6 +113,14 @@ public class XSSFReader {
return XSSFRelation.STYLES.getContents(workbookPart);
}
/**
* Returns an InputStream to read the contents of the
* themes table.
*/
public InputStream getThemesData() throws IOException, InvalidFormatException {
return XSSFRelation.THEME.getContents(workbookPart);
}
/**
* Returns an InputStream to read the contents of the
* main Workbook, which contains key overall data for

View File

@ -16,10 +16,13 @@
==================================================================== */
package org.apache.poi.xssf.model;
import java.io.IOException;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme;
import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument;
@ -34,9 +37,14 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
public class ThemesTable extends POIXMLDocumentPart {
private ThemeDocument theme;
public ThemesTable(PackagePart part, PackageRelationship rel) throws Exception {
public ThemesTable(PackagePart part, PackageRelationship rel) throws IOException {
super(part, rel);
theme = ThemeDocument.Factory.parse(part.getInputStream());
try {
theme = ThemeDocument.Factory.parse(part.getInputStream());
} catch(XmlException e) {
throw new IOException(e.getLocalizedMessage());
}
}
public ThemesTable(ThemeDocument theme) {

View File

@ -55,6 +55,13 @@ public final class TestXSSFReader extends TestCase {
assertEquals(3, r.getStylesTable().getFonts().size());
assertEquals(0, r.getStylesTable()._getNumberFormatSize());
// The Styles Table should have the themes associated with it too
assertNotNull(r.getStylesTable().getTheme());
// Check we get valid data for the two
assertNotNull(r.getStylesData());
assertNotNull(r.getThemesData());
}
public void testStrings() throws Exception {