]> source.dussan.org Git - poi.git/commitdiff
Fixed NPE when retrieving core properties from a newly created workbook, see Bugzilla...
authorYegor Kozlov <yegor@apache.org>
Sun, 12 Jul 2009 08:21:09 +0000 (08:21 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 12 Jul 2009 08:21:09 +0000 (08:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@793291 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/POIXMLProperties.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

index 9955b603cc5375873e7b8cc9d5f60c16c99b4b07..79993d965f13ebde04f4b37848126307676eeb48 100644 (file)
@@ -33,6 +33,7 @@
 
     <changes>
         <release version="3.5-beta7" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47460 - Fixed NPE when retrieving core properties from a newly created workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">47498 - Fixed HyperlinkRecord to properly handle URL monikers</action>
            <action dev="POI-DEVELOPERS" type="fix">47504 - Fixed XSSFWorkbook to read files with hyperlinks to document locations</action>
            <action dev="POI-DEVELOPERS" type="fix">47479 - Fix BoolErrRecord to tolerate incorrect format written by OOO</action>
index dcb6a9ce3fe0afdce31e5dff00a8eb7145d3c492..9729309bcd28c791fe7906d9900508fe78adbb7f 100644 (file)
@@ -38,14 +38,7 @@ public class POIXMLProperties {
                this.pkg = docPackage;
                
                // Core properties
-               PackageRelationshipCollection coreRel =
-                       pkg.getRelationshipsByType(POIXMLDocument.CORE_PROPERTIES_REL_TYPE);
-               if(coreRel.size() == 1) {
-                       core = new CoreProperties( (PackagePropertiesPart)
-                                       pkg.getPart(coreRel.getRelationship(0)) );
-               } else {
-                       throw new IllegalArgumentException("A document must always have core properties defined!");
-               }
+        core = new CoreProperties((PackagePropertiesPart)pkg.getPackageProperties() );
                
                // Extended properties
                PackageRelationshipCollection extRel =
index 6ab1edbf755479277cbc41b94b06a80ff3a916e5..6c48e2fb164f4f693fc58763eee3ade5a8454783 100644 (file)
@@ -33,7 +33,9 @@ import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.POIXMLProperties;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
@@ -250,4 +252,27 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
         sheetId = (int)wb.createSheet().sheet.getSheetId();
         assertEquals(lastSheetId+1, sheetId);
     }
+
+    /**
+     *  Test setting of core properties such as Title and Author
+     */
+    public void testWorkbookProperties() throws Exception {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        POIXMLProperties props = workbook.getProperties();
+        assertNotNull(props);
+
+        PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
+        assertNotNull(opcProps);
+
+        opcProps.setTitleProperty("Testing Bugzilla #47460");
+        assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
+        opcProps.setCreatorProperty("poi-dev@poi.apache.org");
+
+        workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
+        assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
+        assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
+
+
+    }
 }