POIXMLproperties: core properties improvement + test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@795923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Paolo Mottadelli 2009-07-20 17:10:43 +00:00
parent 9196f6e6dd
commit 76752c5db7
3 changed files with 39 additions and 2 deletions

View File

@ -165,6 +165,18 @@ public class POIXMLProperties {
public String getTitle() {
return part.getTitleProperty().getValue();
}
public String getCreator() {
return part.getCreatorProperty().getValue();
}
public void setCreator(String creator) {
part.setCreatorProperty(creator);
}
public String getSubject() {
return part.getSubjectProperty().getValue();
}
public void setSubjectProperty(String subject) {
part.setSubjectProperty(subject);
}
public PackagePropertiesPart getUnderlyingProperties() {
return part;

View File

@ -18,15 +18,20 @@
package org.apache.poi;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
import java.io.File;
import junit.framework.TestCase;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Test setting extended and custom OOXML properties
*/
public class TestPOIXMLProperties extends TestCase {
public void testWorkbookExtendedProperties() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
POIXMLProperties props = workbook.getProperties();
@ -131,4 +136,24 @@ 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();
assertEquals("Paolo Mottadelli", creator);
String subject = props.getCoreProperties().getSubject();
assertEquals("Greetings", subject);
}
}