]> source.dussan.org Git - poi.git/commitdiff
POIXMLproperties: created, creator, modified, lastprinted, identifier, revision ...
authorPaolo Mottadelli <paolo@apache.org>
Tue, 21 Jul 2009 10:23:05 +0000 (10:23 +0000)
committerPaolo Mottadelli <paolo@apache.org>
Tue, 21 Jul 2009 10:23:05 +0000 (10:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@796239 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLProperties.java
src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
src/scratchpad/testcases/org/apache/poi/hwpf/data/documentProperties.docx

index ca2ca808b966d89aa8dda325510c565601e8459d..1ccf7367448dc4f41172fc46a44d35efdb520a9c 100644 (file)
@@ -18,16 +18,22 @@ package org.apache.poi;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Map;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.Map;
 
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.*;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.util.Nullable;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument;
 
 /**
  * Wrapper around the two different kinds of OOXML properties 
@@ -159,11 +165,32 @@ public class POIXMLProperties {
                        this.part = part;
                }
                
-               public void setTitle(String title) {
-                       part.setTitleProperty(title);
+               public String getCategory() {
+                       return part.getCategoryProperty().getValue();
                }
-               public String getTitle() {
-                       return part.getTitleProperty().getValue();
+               public void setCategory(String category) {
+                       part.setCategoryProperty(category);
+               }
+               public String getContentStatus() {
+                       return part.getContentStatusProperty().getValue();
+               }
+               public void setContentStatus(String contentStatus) {
+                       part.setContentStatusProperty(contentStatus);
+               }
+               public String getContentType() {
+                       return part.getContentTypeProperty().getValue();
+               }
+               public void setContentType(String contentType) {
+                       part.setContentTypeProperty(contentType);
+               }
+               public Date getCreated() {
+                       return part.getCreatedProperty().getValue();
+               }
+               public void setCreated(Nullable<Date> date) {
+                       part.setCreatedProperty(date);
+               }
+               public void setCreated(String date) {
+                       part.setCreatedProperty(date);
                }
                public String getCreator() {
                        return part.getCreatorProperty().getValue();
@@ -171,12 +198,58 @@ public class POIXMLProperties {
                public void setCreator(String creator) {
                        part.setCreatorProperty(creator);
                }
+               public String getDescription() {
+                       return part.getDescriptionProperty().getValue();
+               }
+               public void setDescription(String description) {
+                       part.setDescriptionProperty(description);
+               }
+               public String getIdentifier() {
+                       return part.getIdentifierProperty().getValue();
+               }
+               public void setIdentifier(String identifier) {
+                       part.setIdentifierProperty(identifier);
+               }
+               public Date getLastPrinted() {
+                       return part.getLastPrintedProperty().getValue();
+               }
+               public void setLastPrinted(Nullable<Date> date) {
+                       part.setLastPrintedProperty(date);
+               }
+               public void setLastPrinted(String date) {
+                       part.setLastPrintedProperty(date);
+               }
+               public Date getModified() {
+                       return part.getModifiedProperty().getValue();
+               }
+               public void setModified(Nullable<Date> date) {
+                       part.setModifiedProperty(date);
+               }
+               public void setModified(String date) {
+                       part.setModifiedProperty(date);
+               }
                public String getSubject() {
                        return part.getSubjectProperty().getValue();
                }
                public void setSubjectProperty(String subject) {
                        part.setSubjectProperty(subject);
                }
+               public void setTitle(String title) {
+                       part.setTitleProperty(title);
+               }
+               public String getTitle() {
+                       return part.getTitleProperty().getValue();
+               }
+               public String getRevision() {
+                       return part.getRevisionProperty().getValue();
+               }
+               public void setRevision(String revision) {
+                       try {
+                               new Long(revision);
+                               part.setRevisionProperty(revision);
+                       }
+                       catch (NumberFormatException e) {}
+               }
                
                public PackagePropertiesPart getUnderlyingProperties() {
                        return part;
index c27619cec0efb8a065e9ce02e3260bb133f70811..75d87105a6fddb39189d1bee1aff637349562e6e 100755 (executable)
 package org.apache.poi;
 
 import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.POIXMLProperties.CoreProperties;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
@@ -31,6 +33,23 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
  * Test setting extended and custom OOXML properties
  */
 public class TestPOIXMLProperties extends TestCase {
+       POIXMLProperties props;
+       CoreProperties coreProperties;
+       
+       public void setUp() throws Exception{
+               File sampleFile = new File(
+                               System.getProperty("HWPF.testdata.path") +
+                               File.separator + "documentProperties.docx"
+               );
+               assertTrue(sampleFile.exists());
+               XWPFDocument sampleDoc;
+               sampleDoc = new XWPFDocument(
+                               POIXMLDocument.openPackage(sampleFile.toString())
+               );
+               props = sampleDoc.getProperties();
+               coreProperties = props.getCoreProperties();
+               assertNotNull(props);
+       }
        
     public void testWorkbookExtendedProperties() throws Exception {
         XSSFWorkbook workbook = new XSSFWorkbook();
@@ -137,23 +156,29 @@ public class TestPOIXMLProperties extends TestCase {
 
     }
     
-    public void testDocumentProperties() throws Exception {
-               File sampleFile = new File(
-                               System.getProperty("HWPF.testdata.path") +
-                               File.separator + "documentProperties.docx"
-               );
-               assertTrue(sampleFile.exists());
-               XWPFDocument sampleDoc;
-               sampleDoc = new XWPFDocument(
-                               POIXMLDocument.openPackage(sampleFile.toString())
-               );
-               POIXMLProperties props = sampleDoc.getProperties();
-               assertNotNull(props);
-               String title = props.getCoreProperties().getTitle();
-               assertEquals("Hello World", title);
-               String creator = props.getCoreProperties().getCreator();
+    public void testDocumentProperties() {
+               String category = coreProperties.getCategory();
+               assertEquals("test", category);
+               String contentStatus = "Draft";
+               coreProperties.setContentStatus(contentStatus);
+               assertEquals("Draft", contentStatus);
+               Date created = coreProperties.getCreated();
+               SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, ''yy");
+               assertEquals("Mon, Jul 20, '09", formatter.format(created));
+               String creator = coreProperties.getCreator();
                assertEquals("Paolo Mottadelli", creator);
-               String subject = props.getCoreProperties().getSubject();
+               String subject = coreProperties.getSubject();
                assertEquals("Greetings", subject);
+               String title = coreProperties.getTitle();
+               assertEquals("Hello World", title);
+    }
+    
+    public void testGetSetRevision() {
+               String revision = coreProperties.getRevision();
+               assertTrue("Revision number is 1", new Integer(coreProperties.getRevision()).intValue() > 1);
+               coreProperties.setRevision("20");
+               assertEquals("20", coreProperties.getRevision());
+               coreProperties.setRevision("20xx");
+               assertEquals("20", coreProperties.getRevision());
     }
 }
\ No newline at end of file
index d18b31e2ce53c24cb5bddd2d974a0decbb471296..4ec577ee93ba32a1b1dc8b4b99b674dbe31cfdcf 100644 (file)
Binary files a/src/scratchpad/testcases/org/apache/poi/hwpf/data/documentProperties.docx and b/src/scratchpad/testcases/org/apache/poi/hwpf/data/documentProperties.docx differ