From: Paolo Mottadelli Date: Tue, 21 Jul 2009 10:23:05 +0000 (+0000) Subject: POIXMLproperties: created, creator, modified, lastprinted, identifier, revision ... X-Git-Tag: REL_3_5-FINAL~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=60836558ade474c541ed8087c5cbeb9501c613b2;p=poi.git POIXMLproperties: created, creator, modified, lastprinted, identifier, revision + test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@796239 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/POIXMLProperties.java b/src/ooxml/java/org/apache/poi/POIXMLProperties.java index ca2ca808b9..1ccf736744 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLProperties.java +++ b/src/ooxml/java/org/apache/poi/POIXMLProperties.java @@ -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) { + 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) { + part.setLastPrintedProperty(date); + } + public void setLastPrinted(String date) { + part.setLastPrintedProperty(date); + } + public Date getModified() { + return part.getModifiedProperty().getValue(); + } + public void setModified(Nullable 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; diff --git a/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java b/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java index c27619cec0..75d87105a6 100755 --- a/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java +++ b/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java @@ -19,10 +19,12 @@ 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 diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/documentProperties.docx b/src/scratchpad/testcases/org/apache/poi/hwpf/data/documentProperties.docx index d18b31e2ce..4ec577ee93 100644 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