[github-157] add setters for ExtendedProperties. Thanks to Thibaut Cuvelier. This closes #157

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1863432 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2019-07-19 19:48:14 +00:00
parent 65c4aafe3e
commit 10b5a462dc
2 changed files with 108 additions and 0 deletions

View File

@ -376,36 +376,60 @@ public class POIXMLProperties {
}
return null;
}
/** @since POI 4.1.1 */
public void setTemplate(String template) {
props.getProperties().setTemplate(template);
}
public String getManager() {
if (props.getProperties().isSetManager()) {
return props.getProperties().getManager();
}
return null;
}
/** @since POI 4.1.1 */
public void setManager(String manager) {
props.getProperties().setManager(manager);
}
public String getCompany() {
if (props.getProperties().isSetCompany()) {
return props.getProperties().getCompany();
}
return null;
}
/** @since POI 4.1.1 */
public void setCompany(String company) {
props.getProperties().setCompany(company);
}
public String getPresentationFormat() {
if (props.getProperties().isSetPresentationFormat()) {
return props.getProperties().getPresentationFormat();
}
return null;
}
/** @since POI 4.1.1 */
public void setPresentationFormat(String presentationFormat) {
props.getProperties().setPresentationFormat(presentationFormat);
}
public String getApplication() {
if (props.getProperties().isSetApplication()) {
return props.getProperties().getApplication();
}
return null;
}
/** @since POI 4.1.1 */
public void setApplication(String application) {
props.getProperties().setApplication(application);
}
public String getAppVersion() {
if (props.getProperties().isSetAppVersion()) {
return props.getProperties().getAppVersion();
}
return null;
}
/** @since POI 4.1.1 */
public void setAppVersion(String appVersion) {
props.getProperties().setAppVersion(appVersion);
}
public int getPages() {
if (props.getProperties().isSetPages()) {
@ -413,66 +437,110 @@ public class POIXMLProperties {
}
return -1;
}
/** @since POI 4.1.1 */
public void setPages(int pages) {
props.getProperties().setPages(pages);
}
public int getWords() {
if (props.getProperties().isSetWords()) {
return props.getProperties().getWords();
}
return -1;
}
/** @since POI 4.1.1 */
public void setWords(int words) {
props.getProperties().setWords(words);
}
public int getCharacters() {
if (props.getProperties().isSetCharacters()) {
return props.getProperties().getCharacters();
}
return -1;
}
/** @since POI 4.1.1 */
public void setCharacters(int characters) {
props.getProperties().setCharacters(characters);
}
public int getCharactersWithSpaces() {
if (props.getProperties().isSetCharactersWithSpaces()) {
return props.getProperties().getCharactersWithSpaces();
}
return -1;
}
/** @since POI 4.1.1 */
public void setCharactersWithSpaces(int charactersWithSpaces) {
props.getProperties().setCharactersWithSpaces(charactersWithSpaces);
}
public int getLines() {
if (props.getProperties().isSetLines()) {
return props.getProperties().getLines();
}
return -1;
}
/** @since POI 4.1.1 */
public void setLines(int lines) {
props.getProperties().setLines(lines);
}
public int getParagraphs() {
if (props.getProperties().isSetParagraphs()) {
return props.getProperties().getParagraphs();
}
return -1;
}
/** @since POI 4.1.1 */
public void setParagraphs(int paragraphs) {
props.getProperties().setParagraphs(paragraphs);
}
public int getSlides() {
if (props.getProperties().isSetSlides()) {
return props.getProperties().getSlides();
}
return -1;
}
/** @since POI 4.1.1 */
public void setSlides(int slides) {
props.getProperties().setSlides(slides);
}
public int getNotes() {
if (props.getProperties().isSetNotes()) {
return props.getProperties().getNotes();
}
return -1;
}
/** @since POI 4.1.1 */
public void setNotes(int notes) {
props.getProperties().setNotes(notes);
}
public int getTotalTime() {
if (props.getProperties().isSetTotalTime()) {
return props.getProperties().getTotalTime();
}
return -1;
}
/** @since POI 4.1.1 */
public void setTotalTime(int totalTime) {
props.getProperties().setTotalTime(totalTime);
}
public int getHiddenSlides() {
if (props.getProperties().isSetHiddenSlides()) {
return props.getProperties().getHiddenSlides();
}
return -1;
}
/** @since POI 4.1.1 */
public void setHiddenSlides(int hiddenSlides) {
props.getProperties().setHiddenSlides(hiddenSlides);
}
public int getMMClips() {
if (props.getProperties().isSetMMClips()) {
return props.getProperties().getMMClips();
}
return -1;
}
/** @since POI 4.1.1 */
public void setMMClips(int mmClips) {
props.getProperties().setMMClips(mmClips);
}
public String getHyperlinkBase() {
if (props.getProperties().isSetHyperlinkBase()) {
@ -480,6 +548,10 @@ public class POIXMLProperties {
}
return null;
}
/** @since POI 4.1.1 */
public void setHyperlinkBase(String hyperlinkBase) {
props.getProperties().setHyperlinkBase(hyperlinkBase);
}
}
/**

View File

@ -116,6 +116,42 @@ public final class TestPOIXMLProperties {
newWorkbook.close();
}
@Test
public void testWorkbookExtendedPropertiesGettersSetters() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook();
POIXMLProperties props = workbook.getProperties();
assertNotNull(props);
POIXMLProperties.ExtendedProperties properties =
props.getExtendedProperties();
String appVersion = "3.5 beta";
String application = "POI Modified";
assertEquals("Apache POI", properties.getApplication());
properties.setApplication(application);
assertEquals(properties.getApplication(), application);
assertNull(properties.getAppVersion());
properties.setAppVersion(appVersion);
assertEquals(properties.getAppVersion(), appVersion);
XSSFWorkbook newWorkbook =
XSSFTestDataSamples.writeOutAndReadBack(workbook);
workbook.close();
assertNotSame(workbook, newWorkbook);
POIXMLProperties newProps = newWorkbook.getProperties();
assertNotNull(newProps);
POIXMLProperties.ExtendedProperties newProperties =
newProps.getExtendedProperties();
assertEquals(application, newProperties.getApplication());
assertEquals(appVersion, newProperties.getAppVersion());
newWorkbook.close();
}
/**
* Test usermodel API for setting custom properties