From 5fb0fd281e5d46800e01bd1ca06ddf435f0be4b8 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 7 Jun 2018 12:39:35 +0100 Subject: [PATCH 1/6] remove nullable --- .../apache/poi/ooxml/POIXMLProperties.java | 38 +++--- .../POIXMLPropertiesTextExtractor.java | 42 +++--- .../apache/poi/ooxml/util/PackageHelper.java | 27 ++-- .../apache/poi/openxml4j/opc/OPCPackage.java | 10 +- .../poi/openxml4j/opc/PackageProperties.java | 41 +++--- .../opc/internal/PackagePropertiesPart.java | 125 +++++++++--------- .../PackagePropertiesMarshaller.java | 12 +- .../apache/poi/openxml4j/util/Nullable.java | 72 ---------- .../poi/ooxml/TestPOIXMLProperties.java | 4 +- .../opc/TestPackageCoreProperties.java | 123 +++++++++-------- .../TestOPCComplianceCoreProperties.java | 18 +-- .../apache/poi/poifs/crypt/TestEncryptor.java | 13 +- .../apache/poi/xslf/TestXSLFSlideShow.java | 10 +- .../poi/xslf/usermodel/TestXMLSlideShow.java | 2 +- .../poi/xssf/usermodel/TestXSSFWorkbook.java | 6 +- .../poi/xwpf/usermodel/TestXWPFDocument.java | 4 +- 16 files changed, 225 insertions(+), 322 deletions(-) delete mode 100644 src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java index 04ca65fb214..7866ced5453 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java @@ -22,6 +22,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.io.InputStream; import java.io.OutputStream; import java.util.Date; +import java.util.Optional; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; @@ -35,7 +36,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.apache.poi.openxml4j.opc.StreamHelper; 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.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty; @@ -241,61 +241,59 @@ private CoreProperties(PackagePropertiesPart part) { this.part = part; } - public String getCategory() { - return part.getCategoryProperty().getValue(); - } + public String getCategory() { return part.getCategoryProperty().orElse(null); } public void setCategory(String category) { part.setCategoryProperty(category); } public String getContentStatus() { - return part.getContentStatusProperty().getValue(); + return part.getContentStatusProperty().orElse(null); } public void setContentStatus(String contentStatus) { part.setContentStatusProperty(contentStatus); } public String getContentType() { - return part.getContentTypeProperty().getValue(); + return part.getContentTypeProperty().orElse(null); } public void setContentType(String contentType) { part.setContentTypeProperty(contentType); } public Date getCreated() { - return part.getCreatedProperty().getValue(); + return part.getCreatedProperty().orElse(null); } - public void setCreated(Nullable date) { + public void setCreated(Optional date) { part.setCreatedProperty(date); } public void setCreated(String date) { part.setCreatedProperty(date); } public String getCreator() { - return part.getCreatorProperty().getValue(); + return part.getCreatorProperty().orElse(null); } public void setCreator(String creator) { part.setCreatorProperty(creator); } public String getDescription() { - return part.getDescriptionProperty().getValue(); + return part.getDescriptionProperty().orElse(null); } public void setDescription(String description) { part.setDescriptionProperty(description); } public String getIdentifier() { - return part.getIdentifierProperty().getValue(); + return part.getIdentifierProperty().orElse(null); } public void setIdentifier(String identifier) { part.setIdentifierProperty(identifier); } public String getKeywords() { - return part.getKeywordsProperty().getValue(); + return part.getKeywordsProperty().orElse(null); } public void setKeywords(String keywords) { part.setKeywordsProperty(keywords); } public Date getLastPrinted() { - return part.getLastPrintedProperty().getValue(); + return part.getLastPrintedProperty().orElse(null); } - public void setLastPrinted(Nullable date) { + public void setLastPrinted(Optional date) { part.setLastPrintedProperty(date); } public void setLastPrinted(String date) { @@ -303,23 +301,23 @@ public void setLastPrinted(String date) { } /** @since POI 3.15 beta 3 */ public String getLastModifiedByUser() { - return part.getLastModifiedByProperty().getValue(); + return part.getLastModifiedByProperty().orElse(null); } /** @since POI 3.15 beta 3 */ public void setLastModifiedByUser(String user) { part.setLastModifiedByProperty(user); } public Date getModified() { - return part.getModifiedProperty().getValue(); + return part.getModifiedProperty().orElse(null); } - public void setModified(Nullable date) { + public void setModified(Optional date) { part.setModifiedProperty(date); } public void setModified(String date) { part.setModifiedProperty(date); } public String getSubject() { - return part.getSubjectProperty().getValue(); + return part.getSubjectProperty().orElse(null); } public void setSubjectProperty(String subject) { part.setSubjectProperty(subject); @@ -328,10 +326,10 @@ public void setTitle(String title) { part.setTitleProperty(title); } public String getTitle() { - return part.getTitleProperty().getValue(); + return part.getTitleProperty().orElse(null); } public String getRevision() { - return part.getRevisionProperty().getValue(); + return part.getRevisionProperty().orElse(null); } public void setRevision(String revision) { try { diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java index 47c37e84b43..174cb771e1b 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java @@ -23,6 +23,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.Optional; import org.apache.poi.extractor.POITextExtractor; import org.apache.poi.ooxml.POIXMLDocument; @@ -77,6 +78,13 @@ private void appendIfPresent(StringBuilder text, String thing, Date value) { appendIfPresent(text, thing, dateFormat.format(value)); } + private void appendIfPresent(StringBuilder text, String thing, Optional value) { + if (!value.isPresent()) { + return; + } + appendIfPresent(text, thing, value.get()); + } + private void appendIfPresent(StringBuilder text, String thing, String value) { if (value == null) { return; @@ -103,26 +111,26 @@ public String getCorePropertiesText() { PackagePropertiesPart props = document.getProperties().getCoreProperties().getUnderlyingProperties(); - appendIfPresent(text, "Category", props.getCategoryProperty().getValue()); - appendIfPresent(text, "Category", props.getCategoryProperty().getValue()); - appendIfPresent(text, "ContentStatus", props.getContentStatusProperty().getValue()); - appendIfPresent(text, "ContentType", props.getContentTypeProperty().getValue()); - appendIfPresent(text, "Created", props.getCreatedProperty().getValue()); + appendIfPresent(text, "Category", props.getCategoryProperty()); + appendIfPresent(text, "Category", props.getCategoryProperty()); + appendIfPresent(text, "ContentStatus", props.getContentStatusProperty()); + appendIfPresent(text, "ContentType", props.getContentTypeProperty()); + appendIfPresent(text, "Created", props.getCreatedProperty().orElse(null)); appendIfPresent(text, "CreatedString", props.getCreatedPropertyString()); - appendIfPresent(text, "Creator", props.getCreatorProperty().getValue()); - appendIfPresent(text, "Description", props.getDescriptionProperty().getValue()); - appendIfPresent(text, "Identifier", props.getIdentifierProperty().getValue()); - appendIfPresent(text, "Keywords", props.getKeywordsProperty().getValue()); - appendIfPresent(text, "Language", props.getLanguageProperty().getValue()); - appendIfPresent(text, "LastModifiedBy", props.getLastModifiedByProperty().getValue()); - appendIfPresent(text, "LastPrinted", props.getLastPrintedProperty().getValue()); + appendIfPresent(text, "Creator", props.getCreatorProperty()); + appendIfPresent(text, "Description", props.getDescriptionProperty()); + appendIfPresent(text, "Identifier", props.getIdentifierProperty()); + appendIfPresent(text, "Keywords", props.getKeywordsProperty()); + appendIfPresent(text, "Language", props.getLanguageProperty()); + appendIfPresent(text, "LastModifiedBy", props.getLastModifiedByProperty()); + appendIfPresent(text, "LastPrinted", props.getLastPrintedProperty().orElse(null)); appendIfPresent(text, "LastPrintedString", props.getLastPrintedPropertyString()); - appendIfPresent(text, "Modified", props.getModifiedProperty().getValue()); + appendIfPresent(text, "Modified", props.getModifiedProperty().orElse(null)); appendIfPresent(text, "ModifiedString", props.getModifiedPropertyString()); - appendIfPresent(text, "Revision", props.getRevisionProperty().getValue()); - appendIfPresent(text, "Subject", props.getSubjectProperty().getValue()); - appendIfPresent(text, "Title", props.getTitleProperty().getValue()); - appendIfPresent(text, "Version", props.getVersionProperty().getValue()); + appendIfPresent(text, "Revision", props.getRevisionProperty()); + appendIfPresent(text, "Subject", props.getSubjectProperty()); + appendIfPresent(text, "Title", props.getTitleProperty()); + appendIfPresent(text, "Version", props.getVersionProperty()); return text.toString(); } diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java b/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java index 1385848428c..5068a81b5fd 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java +++ b/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java @@ -100,9 +100,6 @@ private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, Packa p = pkg.getPart(relName); part_tgt.addRelationship(p.getPartName(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId()); - - - PackagePart dest; if(!tgt.containPart(p.getPartName())){ dest = tgt.createPart(p.getPartName(), p.getContentType()); @@ -121,17 +118,17 @@ private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, Packa * @param tgt target properties */ private static void copyProperties(PackageProperties src, PackageProperties tgt){ - tgt.setCategoryProperty(src.getCategoryProperty().getValue()); - tgt.setContentStatusProperty(src.getContentStatusProperty().getValue()); - tgt.setContentTypeProperty(src.getContentTypeProperty().getValue()); - tgt.setCreatorProperty(src.getCreatorProperty().getValue()); - tgt.setDescriptionProperty(src.getDescriptionProperty().getValue()); - tgt.setIdentifierProperty(src.getIdentifierProperty().getValue()); - tgt.setKeywordsProperty(src.getKeywordsProperty().getValue()); - tgt.setLanguageProperty(src.getLanguageProperty().getValue()); - tgt.setRevisionProperty(src.getRevisionProperty().getValue()); - tgt.setSubjectProperty(src.getSubjectProperty().getValue()); - tgt.setTitleProperty(src.getTitleProperty().getValue()); - tgt.setVersionProperty(src.getVersionProperty().getValue()); + tgt.setCategoryProperty(src.getCategoryProperty().orElse(null)); + tgt.setContentStatusProperty(src.getContentStatusProperty().orElse(null)); + tgt.setContentTypeProperty(src.getContentTypeProperty().orElse(null)); + tgt.setCreatorProperty(src.getCreatorProperty().orElse(null)); + tgt.setDescriptionProperty(src.getDescriptionProperty().orElse(null)); + tgt.setIdentifierProperty(src.getIdentifierProperty().orElse(null)); + tgt.setKeywordsProperty(src.getKeywordsProperty().orElse(null)); + tgt.setLanguageProperty(src.getLanguageProperty().orElse(null)); + tgt.setRevisionProperty(src.getRevisionProperty().orElse(null)); + tgt.setSubjectProperty(src.getSubjectProperty().orElse(null)); + tgt.setTitleProperty(src.getTitleProperty().orElse(null)); + tgt.setVersionProperty(src.getVersionProperty().orElse(null)); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 7bb7e1367aa..5d9c7b9ae45 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -27,12 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,7 +46,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller; import org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller; import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext; -import org.apache.poi.openxml4j.util.Nullable; import org.apache.poi.openxml4j.util.ZipEntrySource; import org.apache.poi.util.IOUtils; import org.apache.poi.util.NotImplemented; @@ -394,7 +388,7 @@ private static void configurePackage(OPCPackage pkg) { pkg.packageProperties = new PackagePropertiesPart(pkg, PackagingURIHelper.CORE_PROPERTIES_PART_NAME); pkg.packageProperties.setCreatorProperty("Generated by Apache POI OpenXML4J"); - pkg.packageProperties.setCreatedProperty(new Nullable<>(new Date())); + pkg.packageProperties.setCreatedProperty(Optional.of(new Date())); } catch (InvalidFormatException e) { // Should never happen throw new IllegalStateException(e); diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java index 52fa46afa0f..ba087aebe56 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java @@ -18,8 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more package org.apache.poi.openxml4j.opc; import java.util.Date; - -import org.apache.poi.openxml4j.util.Nullable; +import java.util.Optional; /** * Represents the core properties of an OPC package. @@ -45,7 +44,7 @@ public interface PackageProperties { /** * Set the category of the content of this package. */ - Nullable getCategoryProperty(); + Optional getCategoryProperty(); /** * Set the category of the content of this package. @@ -55,7 +54,7 @@ public interface PackageProperties { /** * Set the status of the content. */ - Nullable getContentStatusProperty(); + Optional getContentStatusProperty(); /** * Get the status of the content. @@ -66,7 +65,7 @@ public interface PackageProperties { * Get the type of content represented, generally defined by a specific use * and intended audience. */ - Nullable getContentTypeProperty(); + Optional getContentTypeProperty(); /** * Set the type of content represented, generally defined by a specific use @@ -77,7 +76,7 @@ public interface PackageProperties { /** * Get the date of creation of the resource. */ - Nullable getCreatedProperty(); + Optional getCreatedProperty(); /** * Set the date of creation of the resource. @@ -87,13 +86,13 @@ public interface PackageProperties { /** * Set the date of creation of the resource. */ - void setCreatedProperty(Nullable created); + void setCreatedProperty(Optional created); /** * Get the entity primarily responsible for making the content of the * resource. */ - Nullable getCreatorProperty(); + Optional getCreatorProperty(); /** * Set the entity primarily responsible for making the content of the @@ -104,7 +103,7 @@ public interface PackageProperties { /** * Get the explanation of the content of the resource. */ - Nullable getDescriptionProperty(); + Optional getDescriptionProperty(); /** * Set the explanation of the content of the resource. @@ -114,7 +113,7 @@ public interface PackageProperties { /** * Get an unambiguous reference to the resource within a given context. */ - Nullable getIdentifierProperty(); + Optional getIdentifierProperty(); /** * Set an unambiguous reference to the resource within a given context. @@ -126,7 +125,7 @@ public interface PackageProperties { * is typically a list of terms that are not available elsewhere in the * properties */ - Nullable getKeywordsProperty(); + Optional getKeywordsProperty(); /** * Set a delimited set of keywords to support searching and indexing. This @@ -138,7 +137,7 @@ public interface PackageProperties { /** * Get the language of the intellectual content of the resource. */ - Nullable getLanguageProperty(); + Optional getLanguageProperty(); /** * Set the language of the intellectual content of the resource. @@ -148,7 +147,7 @@ public interface PackageProperties { /** * Get the user who performed the last modification. */ - Nullable getLastModifiedByProperty(); + Optional getLastModifiedByProperty(); /** * Set the user who performed the last modification. @@ -158,7 +157,7 @@ public interface PackageProperties { /** * Get the date and time of the last printing. */ - Nullable getLastPrintedProperty(); + Optional getLastPrintedProperty(); /** * Set the date and time of the last printing. @@ -168,12 +167,12 @@ public interface PackageProperties { /** * Set the date and time of the last printing. */ - void setLastPrintedProperty(Nullable lastPrinted); + void setLastPrintedProperty(Optional lastPrinted); /** * Get the date on which the resource was changed. */ - Nullable getModifiedProperty(); + Optional getModifiedProperty(); /** * Set the date on which the resource was changed. @@ -183,12 +182,12 @@ public interface PackageProperties { /** * Set the date on which the resource was changed. */ - void setModifiedProperty(Nullable modified); + void setModifiedProperty(Optional modified); /** * Get the revision number. */ - Nullable getRevisionProperty(); + Optional getRevisionProperty(); /** * Set the revision number. @@ -198,7 +197,7 @@ public interface PackageProperties { /** * Get the topic of the content of the resource. */ - Nullable getSubjectProperty(); + Optional getSubjectProperty(); /** * Set the topic of the content of the resource. @@ -208,7 +207,7 @@ public interface PackageProperties { /** * Get the name given to the resource. */ - Nullable getTitleProperty(); + Optional getTitleProperty(); /** * Set the name given to the resource. @@ -218,7 +217,7 @@ public interface PackageProperties { /** * Get the version number. */ - Nullable getVersionProperty(); + Optional getVersionProperty(); /** * Set the version number. diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index e52da5bded2..a24f743984d 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -23,6 +23,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,7 +35,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackageProperties; -import org.apache.poi.openxml4j.util.Nullable; import org.apache.poi.util.LocaleUtil; /** @@ -95,7 +95,7 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * value might be used by an application's user interface to facilitate * navigation of a large set of documents. end example] */ - protected Nullable category = new Nullable<>(); + protected Optional category = Optional.empty(); /** * The status of the content. @@ -103,7 +103,7 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * [Example: Values might include "Draft", "Reviewed", and "Final". end * example] */ - protected Nullable contentStatus = new Nullable<>(); + protected Optional contentStatus = Optional.empty(); /** * The type of content represented, generally defined by a specific use and @@ -113,17 +113,17 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * "Exam". end example] [Note: This property is distinct from MIME content * types as defined in RFC 2616. end note] */ - protected Nullable contentType = new Nullable<>(); + protected Optional contentType = Optional.empty(); /** * Date of creation of the resource. */ - protected Nullable created = new Nullable<>(); + protected Optional created = Optional.empty(); /** * An entity primarily responsible for making the content of the resource. */ - protected Nullable creator = new Nullable<>(); + protected Optional creator = Optional.empty(); /** * An explanation of the content of the resource. @@ -132,19 +132,19 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * to a graphical representation of content, and a free-text account of the * content. end example] */ - protected Nullable description = new Nullable<>(); + protected Optional description = Optional.empty(); /** * An unambiguous reference to the resource within a given context. */ - protected Nullable identifier = new Nullable<>(); + protected Optional identifier = Optional.empty(); /** * A delimited set of keywords to support searching and indexing. This is * typically a list of terms that are not available elsewhere in the * properties. */ - protected Nullable keywords = new Nullable<>(); + protected Optional keywords = Optional.empty(); /** * The language of the intellectual content of the resource. @@ -152,7 +152,7 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * [Note: IETF RFC 3066 provides guidance on encoding to represent * languages. end note] */ - protected Nullable language = new Nullable<>(); + protected Optional language = Optional.empty(); /** * The user who performed the last modification. The identification is @@ -161,17 +161,17 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * [Example: A name, email address, or employee ID. end example] It is * recommended that this value be as concise as possible. */ - protected Nullable lastModifiedBy = new Nullable<>(); + protected Optional lastModifiedBy = Optional.empty(); /** * The date and time of the last printing. */ - protected Nullable lastPrinted = new Nullable<>(); + protected Optional lastPrinted = Optional.empty(); /** * Date on which the resource was changed. */ - protected Nullable modified = new Nullable<>(); + protected Optional modified = Optional.empty(); /** * The revision number. @@ -179,22 +179,22 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * [Example: This value might indicate the number of saves or revisions, * provided the application updates it after each revision. end example] */ - protected Nullable revision = new Nullable<>(); + protected Optional revision = Optional.empty(); /** * The topic of the content of the resource. */ - protected Nullable subject = new Nullable<>(); + protected Optional subject = Optional.empty(); /** * The name given to the resource. */ - protected Nullable title = new Nullable<>(); + protected Optional title = Optional.empty(); /** * The version number. This value is set by the user or by the application. */ - protected Nullable version = new Nullable<>(); + protected Optional version = Optional.empty(); /* * Getters and setters @@ -205,7 +205,7 @@ public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) * * @see org.apache.poi.openxml4j.opc.PackageProperties#getCategoryProperty() */ - public Nullable getCategoryProperty() { + public Optional getCategoryProperty() { return category; } @@ -214,7 +214,7 @@ public Nullable getCategoryProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentStatusProperty() */ - public Nullable getContentStatusProperty() { + public Optional getContentStatusProperty() { return contentStatus; } @@ -223,7 +223,7 @@ public Nullable getContentStatusProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentTypeProperty() */ - public Nullable getContentTypeProperty() { + public Optional getContentTypeProperty() { return contentType; } @@ -232,7 +232,7 @@ public Nullable getContentTypeProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatedProperty() */ - public Nullable getCreatedProperty() { + public Optional getCreatedProperty() { return created; } @@ -250,7 +250,7 @@ public String getCreatedPropertyString() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatorProperty() */ - public Nullable getCreatorProperty() { + public Optional getCreatorProperty() { return creator; } @@ -259,7 +259,7 @@ public Nullable getCreatorProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getDescriptionProperty() */ - public Nullable getDescriptionProperty() { + public Optional getDescriptionProperty() { return description; } @@ -268,7 +268,7 @@ public Nullable getDescriptionProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getIdentifierProperty() */ - public Nullable getIdentifierProperty() { + public Optional getIdentifierProperty() { return identifier; } @@ -277,7 +277,7 @@ public Nullable getIdentifierProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getKeywordsProperty() */ - public Nullable getKeywordsProperty() { + public Optional getKeywordsProperty() { return keywords; } @@ -286,7 +286,7 @@ public Nullable getKeywordsProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getLanguageProperty() */ - public Nullable getLanguageProperty() { + public Optional getLanguageProperty() { return language; } @@ -295,7 +295,7 @@ public Nullable getLanguageProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastModifiedByProperty() */ - public Nullable getLastModifiedByProperty() { + public Optional getLastModifiedByProperty() { return lastModifiedBy; } @@ -304,7 +304,7 @@ public Nullable getLastModifiedByProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastPrintedProperty() */ - public Nullable getLastPrintedProperty() { + public Optional getLastPrintedProperty() { return lastPrinted; } @@ -322,7 +322,7 @@ public String getLastPrintedPropertyString() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getModifiedProperty() */ - public Nullable getModifiedProperty() { + public Optional getModifiedProperty() { return modified; } @@ -332,10 +332,10 @@ public Nullable getModifiedProperty() { * @return A string representation of the modified date. */ public String getModifiedPropertyString() { - if (modified.hasValue()) { + if (modified.isPresent()) { return getDateValue(modified); } - return getDateValue(new Nullable<>(new Date())); + return getDateValue(Optional.of(new Date())); } /** @@ -343,7 +343,7 @@ public String getModifiedPropertyString() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getRevisionProperty() */ - public Nullable getRevisionProperty() { + public Optional getRevisionProperty() { return revision; } @@ -352,7 +352,7 @@ public Nullable getRevisionProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getSubjectProperty() */ - public Nullable getSubjectProperty() { + public Optional getSubjectProperty() { return subject; } @@ -361,7 +361,7 @@ public Nullable getSubjectProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getTitleProperty() */ - public Nullable getTitleProperty() { + public Optional getTitleProperty() { return title; } @@ -370,7 +370,7 @@ public Nullable getTitleProperty() { * * @see org.apache.poi.openxml4j.opc.PackageProperties#getVersionProperty() */ - public Nullable getVersionProperty() { + public Optional getVersionProperty() { return version; } @@ -404,7 +404,7 @@ public void setContentTypeProperty(String contentType) { /** * Set the created date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) */ public void setCreatedProperty(String created) { try { @@ -417,10 +417,10 @@ public void setCreatedProperty(String created) { /** * Set the created date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) */ - public void setCreatedProperty(Nullable created) { - if (created.hasValue()) + public void setCreatedProperty(Optional created) { + if (created.isPresent()) this.created = created; } @@ -481,7 +481,7 @@ public void setLastModifiedByProperty(String lastModifiedBy) { /** * Set last printed date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) */ public void setLastPrintedProperty(String lastPrinted) { try { @@ -495,17 +495,17 @@ public void setLastPrintedProperty(String lastPrinted) { /** * Set last printed date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) */ - public void setLastPrintedProperty(Nullable lastPrinted) { - if (lastPrinted.hasValue()) + public void setLastPrintedProperty(Optional lastPrinted) { + if (lastPrinted.isPresent()) this.lastPrinted = lastPrinted; } /** * Set last modification date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) */ public void setModifiedProperty(String modified) { try { @@ -519,10 +519,10 @@ public void setModifiedProperty(String modified) { /** * Set last modification date. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(org.apache.poi.openxml4j.util.Nullable) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) */ - public void setModifiedProperty(Nullable modified) { - if (modified.hasValue()) + public void setModifiedProperty(Optional modified) { + if (modified.isPresent()) this.modified = modified; } @@ -563,24 +563,24 @@ public void setVersionProperty(String version) { } /** - * Convert a strig value into a Nullable + * Convert a string value into a Optional */ - private Nullable setStringValue(String s) { + private Optional setStringValue(String s) { if (s == null || s.isEmpty()) { - return new Nullable<>(); + return Optional.empty(); } - return new Nullable<>(s); + return Optional.of(s); } /** - * Convert a string value represented a date into a Nullable. + * Convert a string value represented a date into a Optional. * * @throws InvalidFormatException * Throws if the date format isnot valid. */ - private Nullable setDateValue(String dateStr) throws InvalidFormatException { + private Optional setDateValue(String dateStr) throws InvalidFormatException { if (dateStr == null || dateStr.isEmpty()) { - return new Nullable<>(); + return Optional.empty(); } Matcher m = TIME_ZONE_PAT.matcher(dateStr); @@ -592,7 +592,7 @@ private Nullable setDateValue(String dateStr) throws InvalidFormatExceptio df.setTimeZone(LocaleUtil.TIMEZONE_UTC); Date d = df.parse(dateTzStr, new ParsePosition(0)); if (d != null) { - return new Nullable<>(d); + return Optional.of(d); } } } @@ -602,7 +602,7 @@ private Nullable setDateValue(String dateStr) throws InvalidFormatExceptio df.setTimeZone(LocaleUtil.TIMEZONE_UTC); Date d = df.parse(dateTzStr, new ParsePosition(0)); if (d != null) { - return new Nullable<>(d); + return Optional.of(d); } } //if you're here, no pattern matched, throw exception @@ -622,25 +622,20 @@ private Nullable setDateValue(String dateStr) throws InvalidFormatExceptio } /** - * Convert a Nullable into a String. + * Convert a Optional into a String. * * @param d * The Date to convert. * @return The formated date or null. * @see java.text.SimpleDateFormat */ - private String getDateValue(Nullable d) { - if (d == null) { + private String getDateValue(Optional d) { + if (d == null || !d.isPresent()) { return ""; } - Date date = d.getValue(); - if (date == null) { - return ""; - } - SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT); df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - return df.format(date); + return df.format(d.get()); } @Override diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java index 34e9fc827a8..757fc975907 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java @@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more package org.apache.poi.openxml4j.opc.internal.marshallers; import java.io.OutputStream; +import java.util.Optional; import javax.xml.XMLConstants; import javax.xml.stream.XMLEventFactory; @@ -27,7 +28,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; import org.apache.poi.openxml4j.opc.internal.PartMarshaller; -import org.apache.poi.openxml4j.util.Nullable; import org.apache.poi.ooxml.util.DocumentHelper; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -126,16 +126,16 @@ public boolean marshall(PackagePart part, OutputStream out) /** * Sets the given element's text content, creating it if necessary. */ - private Element setElementTextContent(String localName, Namespace namespace, Nullable property) { - return setElementTextContent(localName, namespace, property, property.getValue()); + private Element setElementTextContent(String localName, Namespace namespace, Optional property) { + return setElementTextContent(localName, namespace, property, property.orElse(null)); } private String getQName(String localName, Namespace namespace) { return namespace.getPrefix().isEmpty() ? localName : namespace.getPrefix() + ':' + localName; } - private Element setElementTextContent(String localName, Namespace namespace, Nullable property, String propertyValue) { - if (!property.hasValue()) + private Element setElementTextContent(String localName, Namespace namespace, Optional property, String propertyValue) { + if (!property.isPresent()) return null; Element root = xmlDoc.getDocumentElement(); @@ -149,7 +149,7 @@ private Element setElementTextContent(String localName, Namespace namespace, Nul return elem; } - private Element setElementTextContent(String localName, Namespace namespace, Nullable property, String propertyValue, String xsiType) { + private Element setElementTextContent(String localName, Namespace namespace, Optional property, String propertyValue, String xsiType) { Element element = setElementTextContent(localName, namespace, property, propertyValue); if (element != null) { element.setAttributeNS(namespaceXSI.getNamespaceURI(), getQName("type", namespaceXSI), xsiType); diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java b/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java deleted file mode 100644 index 8c1a24c8636..00000000000 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.openxml4j.util; - -/** - * An immutable object that could be defined as null. - * - * @author Julien Chable - * @version 0.9 - */ -public final class Nullable { - - private E value; - - /** - * Constructor. - */ - public Nullable() { - // Do nothing - } - - /** - * Constructor. - * - * @param value - * The value to set to this nullable. - */ - public Nullable(E value) { - this.value = value; - } - - /** - * Get the store value if any. - * - * @return the store value - */ - public E getValue() { - return value; - } - - /** - * Get the status of this nullable. - * - * @return true if the nullable store a value (empty string is - * considered to be a value) else false. - */ - public boolean hasValue() { - return value != null; - } - - /** - * Set the stored value to null. - */ - public void nullify() { - value = null; - } -} diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java b/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java index a2d5f2b163a..d91b8191eb6 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLProperties.java @@ -27,9 +27,9 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.io.IOException; import java.util.Calendar; import java.util.Date; +import java.util.Optional; import org.apache.poi.ooxml.POIXMLProperties.CoreProperties; -import org.apache.poi.openxml4j.util.Nullable; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.XSSFTestDataSamples; @@ -189,7 +189,7 @@ public void testTransitiveSetters() throws IOException { Date dateCreated = LocaleUtil.getLocaleCalendar(2010, 6, 15, 10, 0, 0).getTime(); - cp.setCreated(new Nullable<>(dateCreated)); + cp.setCreated(Optional.of(dateCreated)); assertEquals(dateCreated, cp.getCreated()); XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc); diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java index 49a4da4422a..8132ae3dade 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java @@ -17,11 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more package org.apache.poi.openxml4j.opc; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -30,17 +25,19 @@ Licensed to the Apache Software Foundation (ASF) under one or more import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.Optional; import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart; -import org.apache.poi.openxml4j.util.Nullable; import org.apache.poi.util.LocaleUtil; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Test; import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty; +import static org.junit.Assert.*; + public final class TestPackageCoreProperties { /** * Test package core properties getters. @@ -77,28 +74,28 @@ public void testSetProperties() throws Exception { //test various date formats props.setCreatedProperty("2007-05-12T08:00:00Z"); - assertEquals(dateToInsert, props.getCreatedProperty().getValue()); + assertEquals(dateToInsert, props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T08:00:00"); //no Z, assume Z - assertEquals(dateToInsert, props.getCreatedProperty().getValue()); + assertEquals(dateToInsert, props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T08:00:00.123Z");//millis - assertEquals(msdf.parse("2007-05-12T08:00:00.123Z"), props.getCreatedProperty().getValue()); + assertEquals(msdf.parse("2007-05-12T08:00:00.123Z"), props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T10:00:00+0200"); - assertEquals(dateToInsert, props.getCreatedProperty().getValue()); + assertEquals(dateToInsert, props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T10:00:00+02:00");//colon in tz - assertEquals(dateToInsert, props.getCreatedProperty().getValue()); + assertEquals(dateToInsert, props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T06:00:00-0200"); - assertEquals(dateToInsert, props.getCreatedProperty().getValue()); + assertEquals(dateToInsert, props.getCreatedProperty().get()); props.setCreatedProperty("2015-07-27"); - assertEquals(msdf.parse("2015-07-27T00:00:00.000Z"), props.getCreatedProperty().getValue()); + assertEquals(msdf.parse("2015-07-27T00:00:00.000Z"), props.getCreatedProperty().get()); props.setCreatedProperty("2007-05-12T10:00:00.123+0200"); - assertEquals(msdf.parse("2007-05-12T08:00:00.123Z"), props.getCreatedProperty().getValue()); + assertEquals(msdf.parse("2007-05-12T08:00:00.123Z"), props.getCreatedProperty().get()); props.setCategoryProperty("MyCategory"); props.setContentStatusProperty("MyContentStatus"); @@ -109,8 +106,8 @@ public void testSetProperties() throws Exception { props.setKeywordsProperty("MyKeywords"); props.setLanguageProperty("MyLanguage"); props.setLastModifiedByProperty("Julien Chable"); - props.setLastPrintedProperty(new Nullable<>(dateToInsert)); - props.setModifiedProperty(new Nullable<>(dateToInsert)); + props.setLastPrintedProperty(Optional.of(dateToInsert)); + props.setModifiedProperty(Optional.of(dateToInsert)); props.setRevisionProperty("2"); props.setTitleProperty("MyTitle"); props.setSubjectProperty("MySubject"); @@ -134,22 +131,22 @@ private void compareProperties(OPCPackage p) throws InvalidFormatException { // Gets the core properties PackageProperties props = p.getPackageProperties(); - assertEquals("MyCategory", props.getCategoryProperty().getValue()); - assertEquals("MyContentStatus", props.getContentStatusProperty().getValue()); - assertEquals("MyContentType", props.getContentTypeProperty().getValue()); - assertEquals(expectedDate, props.getCreatedProperty().getValue()); - assertEquals("MyCreator", props.getCreatorProperty().getValue()); - assertEquals("MyDescription", props.getDescriptionProperty().getValue()); - assertEquals("MyIdentifier", props.getIdentifierProperty().getValue()); - assertEquals("MyKeywords", props.getKeywordsProperty().getValue()); - assertEquals("MyLanguage", props.getLanguageProperty().getValue()); - assertEquals("Julien Chable", props.getLastModifiedByProperty().getValue()); - assertEquals(expectedDate, props.getLastPrintedProperty().getValue()); - assertEquals(expectedDate, props.getModifiedProperty().getValue()); - assertEquals("2", props.getRevisionProperty().getValue()); - assertEquals("MySubject", props.getSubjectProperty().getValue()); - assertEquals("MyTitle", props.getTitleProperty().getValue()); - assertEquals("2", props.getVersionProperty().getValue()); + assertEquals("MyCategory", props.getCategoryProperty().get()); + assertEquals("MyContentStatus", props.getContentStatusProperty().get()); + assertEquals("MyContentType", props.getContentTypeProperty().get()); + assertEquals(expectedDate, props.getCreatedProperty().get()); + assertEquals("MyCreator", props.getCreatorProperty().get()); + assertEquals("MyDescription", props.getDescriptionProperty().get()); + assertEquals("MyIdentifier", props.getIdentifierProperty().get()); + assertEquals("MyKeywords", props.getKeywordsProperty().get()); + assertEquals("MyLanguage", props.getLanguageProperty().get()); + assertEquals("Julien Chable", props.getLastModifiedByProperty().get()); + assertEquals(expectedDate, props.getLastPrintedProperty().get()); + assertEquals(expectedDate, props.getModifiedProperty().get()); + assertEquals("2", props.getRevisionProperty().get()); + assertEquals("MySubject", props.getSubjectProperty().get()); + assertEquals("MyTitle", props.getTitleProperty().get()); + assertEquals("2", props.getVersionProperty().get()); } @Test @@ -164,48 +161,48 @@ public void testCoreProperties_bug51374() throws Exception { // created assertEquals("", props.getCreatedPropertyString()); - assertNull(props.getCreatedProperty().getValue()); + assertFalse(props.getCreatedProperty().isPresent()); props.setCreatedProperty((String)null); assertEquals("", props.getCreatedPropertyString()); - assertNull(props.getCreatedProperty().getValue()); - props.setCreatedProperty(new Nullable<>()); + assertFalse(props.getCreatedProperty().isPresent()); + props.setCreatedProperty(Optional.empty()); assertEquals("", props.getCreatedPropertyString()); - assertNull(props.getCreatedProperty().getValue()); - props.setCreatedProperty(new Nullable<>(date)); + assertFalse(props.getCreatedProperty().isPresent()); + props.setCreatedProperty(Optional.of(date)); assertEquals(strDate, props.getCreatedPropertyString()); - assertEquals(date, props.getCreatedProperty().getValue()); + assertEquals(date, props.getCreatedProperty().get()); props.setCreatedProperty(strDate); assertEquals(strDate, props.getCreatedPropertyString()); - assertEquals(date, props.getCreatedProperty().getValue()); + assertEquals(date, props.getCreatedProperty().get()); // lastPrinted assertEquals("", props.getLastPrintedPropertyString()); - assertNull(props.getLastPrintedProperty().getValue()); + assertFalse(props.getLastPrintedProperty().isPresent()); props.setLastPrintedProperty((String)null); assertEquals("", props.getLastPrintedPropertyString()); - assertNull(props.getLastPrintedProperty().getValue()); - props.setLastPrintedProperty(new Nullable<>()); + assertFalse(props.getLastPrintedProperty().isPresent()); + props.setLastPrintedProperty(Optional.empty()); assertEquals("", props.getLastPrintedPropertyString()); - assertNull(props.getLastPrintedProperty().getValue()); - props.setLastPrintedProperty(new Nullable<>(date)); + assertFalse(props.getLastPrintedProperty().isPresent()); + props.setLastPrintedProperty(Optional.of(date)); assertEquals(strDate, props.getLastPrintedPropertyString()); - assertEquals(date, props.getLastPrintedProperty().getValue()); + assertEquals(date, props.getLastPrintedProperty().get()); props.setLastPrintedProperty(strDate); assertEquals(strDate, props.getLastPrintedPropertyString()); - assertEquals(date, props.getLastPrintedProperty().getValue()); + assertEquals(date, props.getLastPrintedProperty().get()); // modified - assertNull(props.getModifiedProperty().getValue()); + assertFalse(props.getModifiedProperty().isPresent()); props.setModifiedProperty((String)null); - assertNull(props.getModifiedProperty().getValue()); - props.setModifiedProperty(new Nullable<>()); - assertNull(props.getModifiedProperty().getValue()); - props.setModifiedProperty(new Nullable<>(date)); + assertFalse(props.getModifiedProperty().isPresent()); + props.setModifiedProperty(Optional.empty()); + assertFalse(props.getModifiedProperty().isPresent()); + props.setModifiedProperty(Optional.of(date)); assertEquals(strDate, props.getModifiedPropertyString()); - assertEquals(date, props.getModifiedProperty().getValue()); + assertEquals(date, props.getModifiedProperty().get()); props.setModifiedProperty(strDate); assertEquals(strDate, props.getModifiedPropertyString()); - assertEquals(date, props.getModifiedProperty().getValue()); + assertEquals(date, props.getModifiedProperty().get()); // Tidy pkg.close(); @@ -216,7 +213,7 @@ public void testGetPropertiesLO() throws Exception { // Open the package OPCPackage pkg1 = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("51444.xlsx")); PackageProperties props1 = pkg1.getPackageProperties(); - assertEquals(null, props1.getTitleProperty().getValue()); + assertEquals(null, props1.getTitleProperty().get()); props1.setTitleProperty("Bug 51444 fixed"); ByteArrayOutputStream out = new ByteArrayOutputStream(); pkg1.save(out); @@ -253,7 +250,7 @@ public void testEntitiesInCoreProps_56164() throws Exception { PackagePropertiesPart props = (PackagePropertiesPart)p.getPackageProperties(); // Check - assertEquals("Stefan Kopf", props.getCreatorProperty().getValue()); + assertEquals("Stefan Kopf", props.getCreatorProperty().get()); p.close(); } @@ -287,20 +284,20 @@ public void testAlternateCorePropertyTimezones() throws Exception { df.setTimeZone(LocaleUtil.TIMEZONE_UTC); // Check text properties first - assertEquals("Lorem Ipsum", props.getTitleProperty().getValue()); - assertEquals("Apache POI", props.getCreatorProperty().getValue()); + assertEquals("Lorem Ipsum", props.getTitleProperty().get()); + assertEquals("Apache POI", props.getCreatorProperty().get()); // Created at has a +3 timezone and milliseconds // 2006-10-13T18:06:00.123+03:00 // = 2006-10-13T15:06:00.123+00:00 assertEquals("2006-10-13T15:06:00Z", props.getCreatedPropertyString()); - assertEquals("2006-10-13T15:06:00.123Z", df.format(props.getCreatedProperty().getValue())); + assertEquals("2006-10-13T15:06:00.123Z", df.format(props.getCreatedProperty().get())); // Modified at has a -13 timezone but no milliseconds // 2007-06-20T07:59:00-13:00 // = 2007-06-20T20:59:00-13:00 assertEquals("2007-06-20T20:59:00Z", props.getModifiedPropertyString()); - assertEquals("2007-06-20T20:59:00.000Z", df.format(props.getModifiedProperty().getValue())); + assertEquals("2007-06-20T20:59:00.000Z", df.format(props.getModifiedProperty().get())); // Ensure we can change them with other timezones and still read back OK @@ -312,16 +309,16 @@ public void testAlternateCorePropertyTimezones() throws Exception { pkg = OPCPackage.open(new ByteArrayInputStream(baos.toByteArray())); // Check text properties first - should be unchanged - assertEquals("Lorem Ipsum", props.getTitleProperty().getValue()); - assertEquals("Apache POI", props.getCreatorProperty().getValue()); + assertEquals("Lorem Ipsum", props.getTitleProperty().get()); + assertEquals("Apache POI", props.getCreatorProperty().get()); // Check the updated times // 2007-06-20T20:57:00+13:00 // = 2007-06-20T07:57:00Z - assertEquals("2007-06-20T07:57:00.000Z", df.format(props.getCreatedProperty().getValue())); + assertEquals("2007-06-20T07:57:00.000Z", df.format(props.getCreatedProperty().get())); // 2007-06-20T20:59:00.123-13:00 // = 2007-06-21T09:59:00.123Z - assertEquals("2007-06-21T09:59:00.123Z", df.format(props.getModifiedProperty().getValue())); + assertEquals("2007-06-21T09:59:00.123Z", df.format(props.getModifiedProperty().get())); } } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index 311db55c22e..d663bb4cd39 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -17,12 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more package org.apache.poi.openxml4j.opc.compliance; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -47,6 +41,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more import junit.framework.AssertionFailedError; +import static org.junit.Assert.*; + /** * Test core properties Open Packaging Convention compliance. * @@ -254,7 +250,7 @@ public void testNoCoreProperties_saveNew() throws Exception { assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); // Save and re-load ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -268,7 +264,7 @@ public void testNoCoreProperties_saveNew() throws Exception { assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); pkg.close(); // Open a new copy of it @@ -286,7 +282,7 @@ public void testNoCoreProperties_saveNew() throws Exception { assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); } /** @@ -314,7 +310,7 @@ public void testNoCoreProperties_saveInPlace() throws Exception { assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); // Save and close pkg.close(); @@ -326,7 +322,7 @@ public void testNoCoreProperties_saveInPlace() throws Exception { assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); // Finish and tidy pkg.revert(); diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java index a6244b9d675..5aecc656f18 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java @@ -16,12 +16,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more ==================================================================== */ package org.apache.poi.poifs.crypt; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -36,7 +30,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.opc.ContentTypes; import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.poifs.crypt.agile.AgileDecryptor; import org.apache.poi.poifs.crypt.agile.AgileEncryptionHeader; import org.apache.poi.poifs.crypt.agile.AgileEncryptionVerifier; @@ -54,6 +47,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.junit.Ignore; import org.junit.Test; +import static org.junit.Assert.*; + public class TestEncryptor { @Test public void binaryRC4Encryption() throws Exception { @@ -295,7 +290,7 @@ public void encryptPackageWithoutCoreProperties() throws Exception { assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(pkg.getPackageProperties()); assertNotNull(pkg.getPackageProperties().getLanguageProperty()); - assertNull(pkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(pkg.getPackageProperties().getLanguageProperty().isPresent()); // Encrypt it EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); @@ -327,7 +322,7 @@ public void encryptPackageWithoutCoreProperties() throws Exception { assertEquals(1, inpPkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); assertNotNull(inpPkg.getPackageProperties()); assertNotNull(inpPkg.getPackageProperties().getLanguageProperty()); - assertNull(inpPkg.getPackageProperties().getLanguageProperty().getValue()); + assertFalse(inpPkg.getPackageProperties().getLanguageProperty().isPresent()); } } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java index f4a7a1af2e4..c0acc2cca2e 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java @@ -16,12 +16,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more ==================================================================== */ package org.apache.poi.xslf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.awt.Color; import java.awt.geom.Rectangle2D; import java.io.IOException; @@ -45,6 +39,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; +import static org.junit.Assert.*; + public class TestXSLFSlideShow { private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); private OPCPackage pack; @@ -130,7 +126,7 @@ public void testMetadataBasics() throws IOException, OpenXML4JException, XmlExce CoreProperties cprops = xml.getProperties().getCoreProperties(); assertNull(cprops.getTitle()); - assertNull(cprops.getUnderlyingProperties().getSubjectProperty().getValue()); + assertFalse(cprops.getUnderlyingProperties().getSubjectProperty().isPresent()); xml.close(); } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java index 2d70d352f9e..afaf8d65b52 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java @@ -137,7 +137,7 @@ public void testMetadataBasics() throws IOException { assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines()); assertEquals(null, xml.getProperties().getCoreProperties().getTitle()); - assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); + assertFalse(xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().isPresent()); xml.close(); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 4889aeeab4a..0c6a0adeff1 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -324,14 +324,14 @@ public void workbookProperties() throws IOException { assertNotNull(opcProps); opcProps.setTitleProperty("Testing Bugzilla #47460"); - assertEquals("Apache POI", opcProps.getCreatorProperty().getValue()); + assertEquals("Apache POI", opcProps.getCreatorProperty().get()); opcProps.setCreatorProperty("poi-dev@poi.apache.org"); XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook); assertEquals("Apache POI", wbBack.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication()); opcProps = wbBack.getProperties().getCoreProperties().getUnderlyingProperties(); - assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue()); - assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue()); + assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().get()); + assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().get()); wbBack.close(); } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index d1b45a80a8f..c927949a268 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -97,7 +97,7 @@ public void testMetadataBasics() throws IOException { assertEquals(10, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines()); assertEquals(null, xml.getProperties().getCoreProperties().getTitle()); - assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); + assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().get()); xml.close(); } @@ -112,7 +112,7 @@ public void testMetadataComplex() throws IOException { assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines()); assertEquals(" ", xml.getProperties().getCoreProperties().getTitle()); - assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); + assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().get()); xml.close(); } From 7e5c7ad17e4ed9666ff4ff921fd5bc90dbdaeb9b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 8 Jun 2018 23:30:03 +0100 Subject: [PATCH 2/6] address review issues --- .../java/org/apache/poi/ooxml/POIXMLProperties.java | 4 +++- .../ooxml/extractor/POIXMLPropertiesTextExtractor.java | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java index 7866ced5453..c5158caddd5 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLProperties.java @@ -241,7 +241,9 @@ private CoreProperties(PackagePropertiesPart part) { this.part = part; } - public String getCategory() { return part.getCategoryProperty().orElse(null); } + public String getCategory() { + return part.getCategoryProperty().orElse(null); + } public void setCategory(String category) { part.setCategoryProperty(category); } diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java index 174cb771e1b..1ef9aab4d69 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java +++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLPropertiesTextExtractor.java @@ -71,8 +71,8 @@ private void appendIfPresent(StringBuilder text, String thing, int value) { appendIfPresent(text, thing, Integer.toString(value)); } - private void appendIfPresent(StringBuilder text, String thing, Date value) { - if (value == null) { + private void appendDateIfPresent(StringBuilder text, String thing, Optional value) { + if (!value.isPresent()) { return; } appendIfPresent(text, thing, dateFormat.format(value)); @@ -115,7 +115,7 @@ public String getCorePropertiesText() { appendIfPresent(text, "Category", props.getCategoryProperty()); appendIfPresent(text, "ContentStatus", props.getContentStatusProperty()); appendIfPresent(text, "ContentType", props.getContentTypeProperty()); - appendIfPresent(text, "Created", props.getCreatedProperty().orElse(null)); + appendDateIfPresent(text, "Created", props.getCreatedProperty()); appendIfPresent(text, "CreatedString", props.getCreatedPropertyString()); appendIfPresent(text, "Creator", props.getCreatorProperty()); appendIfPresent(text, "Description", props.getDescriptionProperty()); @@ -123,9 +123,9 @@ public String getCorePropertiesText() { appendIfPresent(text, "Keywords", props.getKeywordsProperty()); appendIfPresent(text, "Language", props.getLanguageProperty()); appendIfPresent(text, "LastModifiedBy", props.getLastModifiedByProperty()); - appendIfPresent(text, "LastPrinted", props.getLastPrintedProperty().orElse(null)); + appendDateIfPresent(text, "LastPrinted", props.getLastPrintedProperty()); appendIfPresent(text, "LastPrintedString", props.getLastPrintedPropertyString()); - appendIfPresent(text, "Modified", props.getModifiedProperty().orElse(null)); + appendDateIfPresent(text, "Modified", props.getModifiedProperty()); appendIfPresent(text, "ModifiedString", props.getModifiedPropertyString()); appendIfPresent(text, "Revision", props.getRevisionProperty()); appendIfPresent(text, "Subject", props.getSubjectProperty()); From 63dde52fb0133a697c27f0d9e3ab1fbd7be294c2 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 9 Jun 2018 00:07:08 +0100 Subject: [PATCH 3/6] support optional in setters --- .../apache/poi/ooxml/util/PackageHelper.java | 26 ++-- .../poi/openxml4j/opc/PackageProperties.java | 117 +++++++++++++++--- .../opc/internal/PackagePropertiesPart.java | 117 ++++++++++++++++-- 3 files changed, 217 insertions(+), 43 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java b/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java index 5068a81b5fd..9da60dbef9f 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java +++ b/src/ooxml/java/org/apache/poi/ooxml/util/PackageHelper.java @@ -117,18 +117,18 @@ private static void copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, Packa * @param src source properties * @param tgt target properties */ - private static void copyProperties(PackageProperties src, PackageProperties tgt){ - tgt.setCategoryProperty(src.getCategoryProperty().orElse(null)); - tgt.setContentStatusProperty(src.getContentStatusProperty().orElse(null)); - tgt.setContentTypeProperty(src.getContentTypeProperty().orElse(null)); - tgt.setCreatorProperty(src.getCreatorProperty().orElse(null)); - tgt.setDescriptionProperty(src.getDescriptionProperty().orElse(null)); - tgt.setIdentifierProperty(src.getIdentifierProperty().orElse(null)); - tgt.setKeywordsProperty(src.getKeywordsProperty().orElse(null)); - tgt.setLanguageProperty(src.getLanguageProperty().orElse(null)); - tgt.setRevisionProperty(src.getRevisionProperty().orElse(null)); - tgt.setSubjectProperty(src.getSubjectProperty().orElse(null)); - tgt.setTitleProperty(src.getTitleProperty().orElse(null)); - tgt.setVersionProperty(src.getVersionProperty().orElse(null)); + private static void copyProperties(PackageProperties src, PackageProperties tgt) { + tgt.setCategoryProperty(src.getCategoryProperty()); + tgt.setContentStatusProperty(src.getContentStatusProperty()); + tgt.setContentTypeProperty(src.getContentTypeProperty()); + tgt.setCreatorProperty(src.getCreatorProperty()); + tgt.setDescriptionProperty(src.getDescriptionProperty()); + tgt.setIdentifierProperty(src.getIdentifierProperty()); + tgt.setKeywordsProperty(src.getKeywordsProperty()); + tgt.setLanguageProperty(src.getLanguageProperty()); + tgt.setRevisionProperty(src.getRevisionProperty()); + tgt.setSubjectProperty(src.getSubjectProperty()); + tgt.setTitleProperty(src.getTitleProperty()); + tgt.setVersionProperty(src.getVersionProperty()); } } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java index ba087aebe56..5d00ce8d5e0 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java @@ -43,6 +43,7 @@ public interface PackageProperties { /** * Set the category of the content of this package. + * @return property value */ Optional getCategoryProperty(); @@ -51,8 +52,14 @@ public interface PackageProperties { */ void setCategoryProperty(String category); - /** + /** + * Set the category of the content of this package. + */ + void setCategoryProperty(Optional category); + + /** * Set the status of the content. + * @return property value */ Optional getContentStatusProperty(); @@ -61,9 +68,15 @@ public interface PackageProperties { */ void setContentStatusProperty(String contentStatus); - /** + /** + * Get the status of the content. + */ + void setContentStatusProperty(Optional contentStatus); + + /** * Get the type of content represented, generally defined by a specific use * and intended audience. + * @return property value */ Optional getContentTypeProperty(); @@ -73,8 +86,15 @@ public interface PackageProperties { */ void setContentTypeProperty(String contentType); + /** + * Set the type of content represented, generally defined by a specific use + * and intended audience. + */ + void setContentTypeProperty(Optional contentType); + /** * Get the date of creation of the resource. + * @return property value */ Optional getCreatedProperty(); @@ -91,6 +111,7 @@ public interface PackageProperties { /** * Get the entity primarily responsible for making the content of the * resource. + * @return property value */ Optional getCreatorProperty(); @@ -100,7 +121,13 @@ public interface PackageProperties { */ void setCreatorProperty(String creator); - /** + /** + * Set the entity primarily responsible for making the content of the + * resource. + */ + void setCreatorProperty(Optional creator); + + /** * Get the explanation of the content of the resource. */ Optional getDescriptionProperty(); @@ -110,8 +137,14 @@ public interface PackageProperties { */ void setDescriptionProperty(String description); + /** + * Set the explanation of the content of the resource. + */ + void setDescriptionProperty(Optional description); + /** * Get an unambiguous reference to the resource within a given context. + * @return property value */ Optional getIdentifierProperty(); @@ -120,10 +153,16 @@ public interface PackageProperties { */ void setIdentifierProperty(String identifier); - /** + /** + * Set an unambiguous reference to the resource within a given context. + */ + void setIdentifierProperty(Optional identifier); + + /** * Get a delimited set of keywords to support searching and indexing. This * is typically a list of terms that are not available elsewhere in the * properties + * @return property value */ Optional getKeywordsProperty(); @@ -134,8 +173,16 @@ public interface PackageProperties { */ void setKeywordsProperty(String keywords); + /** + * Set a delimited set of keywords to support searching and indexing. This + * is typically a list of terms that are not available elsewhere in the + * properties + */ + void setKeywordsProperty(Optional keywords); + /** * Get the language of the intellectual content of the resource. + * @return property value */ Optional getLanguageProperty(); @@ -144,7 +191,12 @@ public interface PackageProperties { */ void setLanguageProperty(String language); - /** + /** + * Set the language of the intellectual content of the resource. + */ + void setLanguageProperty(Optional language); + + /** * Get the user who performed the last modification. */ Optional getLastModifiedByProperty(); @@ -154,9 +206,15 @@ public interface PackageProperties { */ void setLastModifiedByProperty(String lastModifiedBy); - /** + /** + * Set the user who performed the last modification. + */ + void setLastModifiedByProperty(Optional lastModifiedBy); + + /** * Get the date and time of the last printing. - */ + * @return property value + */ Optional getLastPrintedProperty(); /** @@ -171,6 +229,7 @@ public interface PackageProperties { /** * Get the date on which the resource was changed. + * @return property value */ Optional getModifiedProperty(); @@ -184,8 +243,9 @@ public interface PackageProperties { */ void setModifiedProperty(Optional modified); - /** + /** * Get the revision number. + * @return property value */ Optional getRevisionProperty(); @@ -194,8 +254,14 @@ public interface PackageProperties { */ void setRevisionProperty(String revision); - /** + /** + * Set the revision number. + */ + void setRevisionProperty(Optional revision); + + /** * Get the topic of the content of the resource. + * @return property value */ Optional getSubjectProperty(); @@ -204,23 +270,40 @@ public interface PackageProperties { */ void setSubjectProperty(String subject); - /** + /** + * Set the topic of the content of the resource. + */ + void setSubjectProperty(Optional subject); + + /** * Get the name given to the resource. + * @return property value */ Optional getTitleProperty(); - /** + /** + * Set the name given to the resource. + */ + void setTitleProperty(String title); + + /** * Set the name given to the resource. */ - void setTitleProperty(String title); + void setTitleProperty(Optional title); - /** + /** * Get the version number. + * @return property value */ Optional getVersionProperty(); - /** - * Set the version number. - */ - void setVersionProperty(String version); + /** + * Set the version number. + */ + void setVersionProperty(String version); + + /** + * Set the version number. + */ + void setVersionProperty(Optional version); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index a24f743984d..dc2dda5d589 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -42,8 +42,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more * * @author Julien Chable */ -public final class PackagePropertiesPart extends PackagePart implements - PackageProperties { +public final class PackagePropertiesPart extends PackagePart implements PackageProperties { public final static String NAMESPACE_DC_URI = PackageProperties.NAMESPACE_DC; @@ -383,7 +382,14 @@ public void setCategoryProperty(String category) { this.category = setStringValue(category); } - /** + /** + * Set the category. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCategoryProperty(java.util.Optional) + */ + public void setCategoryProperty(Optional category) { this.category = category; } + + /** * Set the content status. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentStatusProperty(java.lang.String) @@ -392,7 +398,14 @@ public void setContentStatusProperty(String contentStatus) { this.contentStatus = setStringValue(contentStatus); } - /** + /** + * Set the content status. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentStatusProperty(java.util.Optional) + */ + public void setContentStatusProperty(Optional contentStatus) { this.contentStatus = contentStatus; } + + /** * Set the content type. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentTypeProperty(java.lang.String) @@ -401,6 +414,13 @@ public void setContentTypeProperty(String contentType) { this.contentType = setStringValue(contentType); } + /** + * Set the content type. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentTypeProperty(java.util.Optional) + */ + public void setContentTypeProperty(Optional contentType) { this.contentType = contentType; } + /** * Set the created date. * @@ -433,6 +453,13 @@ public void setCreatorProperty(String creator) { this.creator = setStringValue(creator); } + /** + * Set the creator. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatorProperty(java.util.Optional) + */ + public void setCreatorProperty(Optional creator) { this.creator = creator; } + /** * Set the description. * @@ -442,7 +469,14 @@ public void setDescriptionProperty(String description) { this.description = setStringValue(description); } - /** + /** + * Set the description. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setDescriptionProperty(java.util.Optional) + */ + public void setDescriptionProperty(Optional description) { this.description = description; } + + /** * Set identifier. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setIdentifierProperty(java.lang.String) @@ -451,7 +485,14 @@ public void setIdentifierProperty(String identifier) { this.identifier = setStringValue(identifier); } - /** + /** + * Set identifier. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setIdentifierProperty(java.util.Optional) + */ + public void setIdentifierProperty(Optional identifier) { this.identifier = identifier; } + + /** * Set keywords. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setKeywordsProperty(java.lang.String) @@ -460,7 +501,14 @@ public void setKeywordsProperty(String keywords) { this.keywords = setStringValue(keywords); } - /** + /** + * Set keywords. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setKeywordsProperty(java.util.Optional) + */ + public void setKeywordsProperty(Optional keywords) { this.keywords = keywords; } + + /** * Set language. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setLanguageProperty(java.lang.String) @@ -469,7 +517,14 @@ public void setLanguageProperty(String language) { this.language = setStringValue(language); } - /** + /** + * Set language. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLanguageProperty(java.util.Optional) + */ + public void setLanguageProperty(Optional language) { this.language = language; } + + /** * Set last modifications author. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastModifiedByProperty(java.lang.String) @@ -478,6 +533,15 @@ public void setLastModifiedByProperty(String lastModifiedBy) { this.lastModifiedBy = setStringValue(lastModifiedBy); } + /** + * Set last modifications author. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastModifiedByProperty(java.util.Optional) + */ + public void setLastModifiedByProperty(Optional lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + /** * Set last printed date. * @@ -529,12 +593,18 @@ public void setModifiedProperty(Optional modified) { /** * Set revision. * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setRevisionProperty(java.lang.String) + * @see org.apache.poi.openxml4j.opc.PackageProperties#setRevisionProperty(java.util.Optional) */ - public void setRevisionProperty(String revision) { - this.revision = setStringValue(revision); - } + public void setRevisionProperty(Optional revision) { this.revision = revision; } + /** + * Set revision. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setRevisionProperty(java.lang.String) + */ + public void setRevisionProperty(String revision) { + this.revision = setStringValue(revision); + } /** * Set subject. * @@ -544,7 +614,14 @@ public void setSubjectProperty(String subject) { this.subject = setStringValue(subject); } - /** + /** + * Set subject. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setSubjectProperty(java.util.Optional) + */ + public void setSubjectProperty(Optional subject) { this.subject = subject; } + + /** * Set title. * * @see org.apache.poi.openxml4j.opc.PackageProperties#setTitleProperty(java.lang.String) @@ -553,6 +630,13 @@ public void setTitleProperty(String title) { this.title = setStringValue(title); } + /** + * Set title. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setTitleProperty(java.util.Optional) + */ + public void setTitleProperty(Optional title) { this.title = title; } + /** * Set version. * @@ -562,6 +646,13 @@ public void setVersionProperty(String version) { this.version = setStringValue(version); } + /** + * Set version. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setVersionProperty(java.util.Optional) + */ + public void setVersionProperty(Optional version) { this.version = version; } + /** * Convert a string value into a Optional */ From 5264f7ba43ff7a154cee67948622a429b0e7bad3 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 9 Jun 2018 00:12:01 +0100 Subject: [PATCH 4/6] fix indents --- .../opc/internal/PackagePropertiesPart.java | 1188 ++++++++--------- 1 file changed, 594 insertions(+), 594 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index dc2dda5d589..eccb7f930d0 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -44,343 +44,343 @@ Licensed to the Apache Software Foundation (ASF) under one or more */ public final class PackagePropertiesPart extends PackagePart implements PackageProperties { - public final static String NAMESPACE_DC_URI = PackageProperties.NAMESPACE_DC; + public final static String NAMESPACE_DC_URI = PackageProperties.NAMESPACE_DC; - public final static String NAMESPACE_CP_URI = PackageNamespaces.CORE_PROPERTIES; + public final static String NAMESPACE_CP_URI = PackageNamespaces.CORE_PROPERTIES; - public final static String NAMESPACE_DCTERMS_URI = PackageProperties.NAMESPACE_DCTERMS; + public final static String NAMESPACE_DCTERMS_URI = PackageProperties.NAMESPACE_DCTERMS; - private final static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + private final static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private final static String[] DATE_FORMATS = new String[]{ - DEFAULT_DATEFORMAT, - "yyyy-MM-dd'T'HH:mm:ss.SS'Z'", + private final static String[] DATE_FORMATS = new String[]{ + DEFAULT_DATEFORMAT, + "yyyy-MM-dd'T'HH:mm:ss.SS'Z'", "yyyy-MM-dd" - }; - - //Had to add this and TIME_ZONE_PAT to handle tz with colons. - //When we move to Java 7, we should be able to add another - //date format to DATE_FORMATS that uses XXX and get rid of this - //and TIME_ZONE_PAT - // TODO Fix this after the Java 7 upgrade - private final String[] TZ_DATE_FORMATS = new String[]{ - "yyyy-MM-dd'T'HH:mm:ssz", + }; + + //Had to add this and TIME_ZONE_PAT to handle tz with colons. + //When we move to Java 7, we should be able to add another + //date format to DATE_FORMATS that uses XXX and get rid of this + //and TIME_ZONE_PAT + // TODO Fix this after the Java 7 upgrade + private final String[] TZ_DATE_FORMATS = new String[]{ + "yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd'T'HH:mm:ss.Sz", "yyyy-MM-dd'T'HH:mm:ss.SSz", - "yyyy-MM-dd'T'HH:mm:ss.SSSz", - }; - - private final Pattern TIME_ZONE_PAT = Pattern.compile("([-+]\\d\\d):?(\\d\\d)"); - /** - * Constructor. - * - * @param pack - * Container package. - * @param partName - * Name of this part. - * @throws InvalidFormatException - * Throws if the content is invalid. - */ - public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) - throws InvalidFormatException { - super(pack, partName, ContentTypes.CORE_PROPERTIES_PART); - } - - /** - * A categorization of the content of this package. - * - * [Example: Example values for this property might include: Resume, Letter, - * Financial Forecast, Proposal, Technical Presentation, and so on. This - * value might be used by an application's user interface to facilitate - * navigation of a large set of documents. end example] - */ - protected Optional category = Optional.empty(); - - /** - * The status of the content. - * - * [Example: Values might include "Draft", "Reviewed", and "Final". end - * example] - */ - protected Optional contentStatus = Optional.empty(); - - /** - * The type of content represented, generally defined by a specific use and - * intended audience. - * - * [Example: Values might include "Whitepaper", "Security Bulletin", and - * "Exam". end example] [Note: This property is distinct from MIME content - * types as defined in RFC 2616. end note] - */ - protected Optional contentType = Optional.empty(); - - /** - * Date of creation of the resource. - */ - protected Optional created = Optional.empty(); - - /** - * An entity primarily responsible for making the content of the resource. - */ - protected Optional creator = Optional.empty(); - - /** - * An explanation of the content of the resource. - * - * [Example: Values might include an abstract, table of contents, reference - * to a graphical representation of content, and a free-text account of the - * content. end example] - */ - protected Optional description = Optional.empty(); - - /** - * An unambiguous reference to the resource within a given context. - */ - protected Optional identifier = Optional.empty(); - - /** - * A delimited set of keywords to support searching and indexing. This is - * typically a list of terms that are not available elsewhere in the - * properties. - */ - protected Optional keywords = Optional.empty(); - - /** - * The language of the intellectual content of the resource. - * - * [Note: IETF RFC 3066 provides guidance on encoding to represent - * languages. end note] - */ - protected Optional language = Optional.empty(); - - /** - * The user who performed the last modification. The identification is - * environment-specific. - * - * [Example: A name, email address, or employee ID. end example] It is - * recommended that this value be as concise as possible. - */ - protected Optional lastModifiedBy = Optional.empty(); - - /** - * The date and time of the last printing. - */ - protected Optional lastPrinted = Optional.empty(); - - /** - * Date on which the resource was changed. - */ - protected Optional modified = Optional.empty(); - - /** - * The revision number. - * - * [Example: This value might indicate the number of saves or revisions, - * provided the application updates it after each revision. end example] - */ - protected Optional revision = Optional.empty(); - - /** - * The topic of the content of the resource. - */ - protected Optional subject = Optional.empty(); - - /** - * The name given to the resource. - */ - protected Optional title = Optional.empty(); - - /** - * The version number. This value is set by the user or by the application. - */ - protected Optional version = Optional.empty(); - - /* - * Getters and setters - */ - - /** - * Get the category property. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getCategoryProperty() - */ - public Optional getCategoryProperty() { - return category; - } - - /** - * Get content status. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentStatusProperty() - */ - public Optional getContentStatusProperty() { - return contentStatus; - } - - /** - * Get content type. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentTypeProperty() - */ - public Optional getContentTypeProperty() { - return contentType; - } - - /** - * Get created date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatedProperty() - */ - public Optional getCreatedProperty() { - return created; - } - - /** - * Get created date formated into a String. - * - * @return A string representation of the created date. - */ - public String getCreatedPropertyString() { - return getDateValue(created); - } - - /** - * Get creator. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatorProperty() - */ - public Optional getCreatorProperty() { - return creator; - } - - /** - * Get description. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getDescriptionProperty() - */ - public Optional getDescriptionProperty() { - return description; - } - - /** - * Get identifier. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getIdentifierProperty() - */ - public Optional getIdentifierProperty() { - return identifier; - } - - /** - * Get keywords. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getKeywordsProperty() - */ - public Optional getKeywordsProperty() { - return keywords; - } - - /** - * Get the language. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getLanguageProperty() - */ - public Optional getLanguageProperty() { - return language; - } - - /** - * Get the author of last modifications. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastModifiedByProperty() - */ - public Optional getLastModifiedByProperty() { - return lastModifiedBy; - } - - /** - * Get last printed date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastPrintedProperty() - */ - public Optional getLastPrintedProperty() { - return lastPrinted; - } - - /** - * Get last printed date formated into a String. - * - * @return A string representation of the last printed date. - */ - public String getLastPrintedPropertyString() { - return getDateValue(lastPrinted); - } - - /** - * Get modified date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getModifiedProperty() - */ - public Optional getModifiedProperty() { - return modified; - } - - /** - * Get modified date formated into a String. - * - * @return A string representation of the modified date. - */ - public String getModifiedPropertyString() { - if (modified.isPresent()) { - return getDateValue(modified); - } - return getDateValue(Optional.of(new Date())); - } - - /** - * Get revision. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getRevisionProperty() - */ - public Optional getRevisionProperty() { - return revision; - } - - /** - * Get subject. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getSubjectProperty() - */ - public Optional getSubjectProperty() { - return subject; - } - - /** - * Get title. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getTitleProperty() - */ - public Optional getTitleProperty() { - return title; - } - - /** - * Get version. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#getVersionProperty() - */ - public Optional getVersionProperty() { - return version; - } - - /** - * Set the category. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCategoryProperty(java.lang.String) - */ - public void setCategoryProperty(String category) { - this.category = setStringValue(category); - } + "yyyy-MM-dd'T'HH:mm:ss.SSSz", + }; + + private final Pattern TIME_ZONE_PAT = Pattern.compile("([-+]\\d\\d):?(\\d\\d)"); + /** + * Constructor. + * + * @param pack + * Container package. + * @param partName + * Name of this part. + * @throws InvalidFormatException + * Throws if the content is invalid. + */ + public PackagePropertiesPart(OPCPackage pack, PackagePartName partName) + throws InvalidFormatException { + super(pack, partName, ContentTypes.CORE_PROPERTIES_PART); + } + + /** + * A categorization of the content of this package. + * + * [Example: Example values for this property might include: Resume, Letter, + * Financial Forecast, Proposal, Technical Presentation, and so on. This + * value might be used by an application's user interface to facilitate + * navigation of a large set of documents. end example] + */ + protected Optional category = Optional.empty(); + + /** + * The status of the content. + * + * [Example: Values might include "Draft", "Reviewed", and "Final". end + * example] + */ + protected Optional contentStatus = Optional.empty(); + + /** + * The type of content represented, generally defined by a specific use and + * intended audience. + * + * [Example: Values might include "Whitepaper", "Security Bulletin", and + * "Exam". end example] [Note: This property is distinct from MIME content + * types as defined in RFC 2616. end note] + */ + protected Optional contentType = Optional.empty(); + + /** + * Date of creation of the resource. + */ + protected Optional created = Optional.empty(); + + /** + * An entity primarily responsible for making the content of the resource. + */ + protected Optional creator = Optional.empty(); + + /** + * An explanation of the content of the resource. + * + * [Example: Values might include an abstract, table of contents, reference + * to a graphical representation of content, and a free-text account of the + * content. end example] + */ + protected Optional description = Optional.empty(); + + /** + * An unambiguous reference to the resource within a given context. + */ + protected Optional identifier = Optional.empty(); + + /** + * A delimited set of keywords to support searching and indexing. This is + * typically a list of terms that are not available elsewhere in the + * properties. + */ + protected Optional keywords = Optional.empty(); + + /** + * The language of the intellectual content of the resource. + * + * [Note: IETF RFC 3066 provides guidance on encoding to represent + * languages. end note] + */ + protected Optional language = Optional.empty(); + + /** + * The user who performed the last modification. The identification is + * environment-specific. + * + * [Example: A name, email address, or employee ID. end example] It is + * recommended that this value be as concise as possible. + */ + protected Optional lastModifiedBy = Optional.empty(); + + /** + * The date and time of the last printing. + */ + protected Optional lastPrinted = Optional.empty(); + + /** + * Date on which the resource was changed. + */ + protected Optional modified = Optional.empty(); + + /** + * The revision number. + * + * [Example: This value might indicate the number of saves or revisions, + * provided the application updates it after each revision. end example] + */ + protected Optional revision = Optional.empty(); + + /** + * The topic of the content of the resource. + */ + protected Optional subject = Optional.empty(); + + /** + * The name given to the resource. + */ + protected Optional title = Optional.empty(); + + /** + * The version number. This value is set by the user or by the application. + */ + protected Optional version = Optional.empty(); + + /* + * Getters and setters + */ + + /** + * Get the category property. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getCategoryProperty() + */ + public Optional getCategoryProperty() { + return category; + } + + /** + * Get content status. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentStatusProperty() + */ + public Optional getContentStatusProperty() { + return contentStatus; + } + + /** + * Get content type. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getContentTypeProperty() + */ + public Optional getContentTypeProperty() { + return contentType; + } + + /** + * Get created date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatedProperty() + */ + public Optional getCreatedProperty() { + return created; + } + + /** + * Get created date formated into a String. + * + * @return A string representation of the created date. + */ + public String getCreatedPropertyString() { + return getDateValue(created); + } + + /** + * Get creator. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getCreatorProperty() + */ + public Optional getCreatorProperty() { + return creator; + } + + /** + * Get description. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getDescriptionProperty() + */ + public Optional getDescriptionProperty() { + return description; + } + + /** + * Get identifier. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getIdentifierProperty() + */ + public Optional getIdentifierProperty() { + return identifier; + } + + /** + * Get keywords. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getKeywordsProperty() + */ + public Optional getKeywordsProperty() { + return keywords; + } + + /** + * Get the language. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getLanguageProperty() + */ + public Optional getLanguageProperty() { + return language; + } + + /** + * Get the author of last modifications. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastModifiedByProperty() + */ + public Optional getLastModifiedByProperty() { + return lastModifiedBy; + } + + /** + * Get last printed date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getLastPrintedProperty() + */ + public Optional getLastPrintedProperty() { + return lastPrinted; + } + + /** + * Get last printed date formated into a String. + * + * @return A string representation of the last printed date. + */ + public String getLastPrintedPropertyString() { + return getDateValue(lastPrinted); + } + + /** + * Get modified date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getModifiedProperty() + */ + public Optional getModifiedProperty() { + return modified; + } + + /** + * Get modified date formated into a String. + * + * @return A string representation of the modified date. + */ + public String getModifiedPropertyString() { + if (modified.isPresent()) { + return getDateValue(modified); + } + return getDateValue(Optional.of(new Date())); + } + + /** + * Get revision. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getRevisionProperty() + */ + public Optional getRevisionProperty() { + return revision; + } + + /** + * Get subject. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getSubjectProperty() + */ + public Optional getSubjectProperty() { + return subject; + } + + /** + * Get title. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getTitleProperty() + */ + public Optional getTitleProperty() { + return title; + } + + /** + * Get version. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#getVersionProperty() + */ + public Optional getVersionProperty() { + return version; + } + + /** + * Set the category. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCategoryProperty(java.lang.String) + */ + public void setCategoryProperty(String category) { + this.category = setStringValue(category); + } /** * Set the category. @@ -390,13 +390,13 @@ public void setCategoryProperty(String category) { public void setCategoryProperty(Optional category) { this.category = category; } /** - * Set the content status. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentStatusProperty(java.lang.String) - */ - public void setContentStatusProperty(String contentStatus) { - this.contentStatus = setStringValue(contentStatus); - } + * Set the content status. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentStatusProperty(java.lang.String) + */ + public void setContentStatusProperty(String contentStatus) { + this.contentStatus = setStringValue(contentStatus); + } /** * Set the content status. @@ -406,13 +406,13 @@ public void setContentStatusProperty(String contentStatus) { public void setContentStatusProperty(Optional contentStatus) { this.contentStatus = contentStatus; } /** - * Set the content type. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentTypeProperty(java.lang.String) - */ - public void setContentTypeProperty(String contentType) { - this.contentType = setStringValue(contentType); - } + * Set the content type. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setContentTypeProperty(java.lang.String) + */ + public void setContentTypeProperty(String contentType) { + this.contentType = setStringValue(contentType); + } /** * Set the content type. @@ -421,37 +421,37 @@ public void setContentTypeProperty(String contentType) { */ public void setContentTypeProperty(Optional contentType) { this.contentType = contentType; } - /** - * Set the created date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) - */ - public void setCreatedProperty(String created) { - try { - this.created = setDateValue(created); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); - } - } - - /** - * Set the created date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) - */ - public void setCreatedProperty(Optional created) { - if (created.isPresent()) - this.created = created; - } - - /** - * Set the creator. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatorProperty(java.lang.String) - */ - public void setCreatorProperty(String creator) { - this.creator = setStringValue(creator); - } + /** + * Set the created date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) + */ + public void setCreatedProperty(String created) { + try { + this.created = setDateValue(created); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); + } + } + + /** + * Set the created date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional) + */ + public void setCreatedProperty(Optional created) { + if (created.isPresent()) + this.created = created; + } + + /** + * Set the creator. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatorProperty(java.lang.String) + */ + public void setCreatorProperty(String creator) { + this.creator = setStringValue(creator); + } /** * Set the creator. @@ -460,14 +460,14 @@ public void setCreatorProperty(String creator) { */ public void setCreatorProperty(Optional creator) { this.creator = creator; } - /** - * Set the description. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setDescriptionProperty(java.lang.String) - */ - public void setDescriptionProperty(String description) { - this.description = setStringValue(description); - } + /** + * Set the description. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setDescriptionProperty(java.lang.String) + */ + public void setDescriptionProperty(String description) { + this.description = setStringValue(description); + } /** * Set the description. @@ -477,13 +477,13 @@ public void setDescriptionProperty(String description) { public void setDescriptionProperty(Optional description) { this.description = description; } /** - * Set identifier. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setIdentifierProperty(java.lang.String) - */ - public void setIdentifierProperty(String identifier) { - this.identifier = setStringValue(identifier); - } + * Set identifier. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setIdentifierProperty(java.lang.String) + */ + public void setIdentifierProperty(String identifier) { + this.identifier = setStringValue(identifier); + } /** * Set identifier. @@ -493,13 +493,13 @@ public void setIdentifierProperty(String identifier) { public void setIdentifierProperty(Optional identifier) { this.identifier = identifier; } /** - * Set keywords. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setKeywordsProperty(java.lang.String) - */ - public void setKeywordsProperty(String keywords) { - this.keywords = setStringValue(keywords); - } + * Set keywords. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setKeywordsProperty(java.lang.String) + */ + public void setKeywordsProperty(String keywords) { + this.keywords = setStringValue(keywords); + } /** * Set keywords. @@ -509,13 +509,13 @@ public void setKeywordsProperty(String keywords) { public void setKeywordsProperty(Optional keywords) { this.keywords = keywords; } /** - * Set language. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLanguageProperty(java.lang.String) - */ - public void setLanguageProperty(String language) { - this.language = setStringValue(language); - } + * Set language. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLanguageProperty(java.lang.String) + */ + public void setLanguageProperty(String language) { + this.language = setStringValue(language); + } /** * Set language. @@ -525,13 +525,13 @@ public void setLanguageProperty(String language) { public void setLanguageProperty(Optional language) { this.language = language; } /** - * Set last modifications author. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastModifiedByProperty(java.lang.String) - */ - public void setLastModifiedByProperty(String lastModifiedBy) { - this.lastModifiedBy = setStringValue(lastModifiedBy); - } + * Set last modifications author. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastModifiedByProperty(java.lang.String) + */ + public void setLastModifiedByProperty(String lastModifiedBy) { + this.lastModifiedBy = setStringValue(lastModifiedBy); + } /** * Set last modifications author. @@ -542,60 +542,60 @@ public void setLastModifiedByProperty(Optional lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } - /** - * Set last printed date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) - */ - public void setLastPrintedProperty(String lastPrinted) { - try { - this.lastPrinted = setDateValue(lastPrinted); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("lastPrinted : " - + e.getLocalizedMessage(), e); - } - } - - /** - * Set last printed date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) - */ - public void setLastPrintedProperty(Optional lastPrinted) { - if (lastPrinted.isPresent()) - this.lastPrinted = lastPrinted; - } - - /** - * Set last modification date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) - */ - public void setModifiedProperty(String modified) { - try { - this.modified = setDateValue(modified); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("modified : " - + e.getLocalizedMessage(), e); - } - } - - /** - * Set last modification date. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) - */ - public void setModifiedProperty(Optional modified) { - if (modified.isPresent()) - this.modified = modified; - } - - /** - * Set revision. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setRevisionProperty(java.util.Optional) - */ - public void setRevisionProperty(Optional revision) { this.revision = revision; } + /** + * Set last printed date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) + */ + public void setLastPrintedProperty(String lastPrinted) { + try { + this.lastPrinted = setDateValue(lastPrinted); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("lastPrinted : " + + e.getLocalizedMessage(), e); + } + } + + /** + * Set last printed date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional) + */ + public void setLastPrintedProperty(Optional lastPrinted) { + if (lastPrinted.isPresent()) + this.lastPrinted = lastPrinted; + } + + /** + * Set last modification date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) + */ + public void setModifiedProperty(String modified) { + try { + this.modified = setDateValue(modified); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("modified : " + + e.getLocalizedMessage(), e); + } + } + + /** + * Set last modification date. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional) + */ + public void setModifiedProperty(Optional modified) { + if (modified.isPresent()) + this.modified = modified; + } + + /** + * Set revision. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setRevisionProperty(java.util.Optional) + */ + public void setRevisionProperty(Optional revision) { this.revision = revision; } /** * Set revision. @@ -605,14 +605,14 @@ public void setModifiedProperty(Optional modified) { public void setRevisionProperty(String revision) { this.revision = setStringValue(revision); } - /** - * Set subject. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setSubjectProperty(java.lang.String) - */ - public void setSubjectProperty(String subject) { - this.subject = setStringValue(subject); - } + /** + * Set subject. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setSubjectProperty(java.lang.String) + */ + public void setSubjectProperty(String subject) { + this.subject = setStringValue(subject); + } /** * Set subject. @@ -622,13 +622,13 @@ public void setSubjectProperty(String subject) { public void setSubjectProperty(Optional subject) { this.subject = subject; } /** - * Set title. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setTitleProperty(java.lang.String) - */ - public void setTitleProperty(String title) { - this.title = setStringValue(title); - } + * Set title. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setTitleProperty(java.lang.String) + */ + public void setTitleProperty(String title) { + this.title = setStringValue(title); + } /** * Set title. @@ -637,14 +637,14 @@ public void setTitleProperty(String title) { */ public void setTitleProperty(Optional title) { this.title = title; } - /** - * Set version. - * - * @see org.apache.poi.openxml4j.opc.PackageProperties#setVersionProperty(java.lang.String) - */ - public void setVersionProperty(String version) { - this.version = setStringValue(version); - } + /** + * Set version. + * + * @see org.apache.poi.openxml4j.opc.PackageProperties#setVersionProperty(java.lang.String) + */ + public void setVersionProperty(String version) { + this.version = setStringValue(version); + } /** * Set version. @@ -653,110 +653,110 @@ public void setVersionProperty(String version) { */ public void setVersionProperty(Optional version) { this.version = version; } - /** - * Convert a string value into a Optional - */ - private Optional setStringValue(String s) { - if (s == null || s.isEmpty()) { - return Optional.empty(); - } - return Optional.of(s); - } - - /** - * Convert a string value represented a date into a Optional. - * - * @throws InvalidFormatException - * Throws if the date format isnot valid. - */ - private Optional setDateValue(String dateStr) throws InvalidFormatException { - if (dateStr == null || dateStr.isEmpty()) { - return Optional.empty(); - } - - Matcher m = TIME_ZONE_PAT.matcher(dateStr); - if (m.find()) { - String dateTzStr = dateStr.substring(0, m.start())+ - m.group(1)+m.group(2); - for (String fStr : TZ_DATE_FORMATS) { - SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT); - df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - Date d = df.parse(dateTzStr, new ParsePosition(0)); - if (d != null) { - return Optional.of(d); - } - } - } - String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z"); - for (String fStr : DATE_FORMATS) { - SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT); - df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - Date d = df.parse(dateTzStr, new ParsePosition(0)); - if (d != null) { - return Optional.of(d); - } - } - //if you're here, no pattern matched, throw exception - StringBuilder sb = new StringBuilder(); - int i = 0; - for (String fStr : TZ_DATE_FORMATS) { - if (i++ > 0) { - sb.append(", "); - } - sb.append(fStr); - } - for (String fStr : DATE_FORMATS) { - sb.append(", ").append(fStr); - } - throw new InvalidFormatException("Date " + dateStr + " not well formatted, " - + "expected format in: "+ sb); - } - - /** - * Convert a Optional into a String. - * - * @param d - * The Date to convert. - * @return The formated date or null. - * @see java.text.SimpleDateFormat - */ - private String getDateValue(Optional d) { - if (d == null || !d.isPresent()) { - return ""; - } - SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT); - df.setTimeZone(LocaleUtil.TIMEZONE_UTC); - return df.format(d.get()); - } - - @Override - protected InputStream getInputStreamImpl() { - throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); - } - - @Override - protected OutputStream getOutputStreamImpl() { - throw new InvalidOperationException( - "Can't use output stream to set properties !"); - } - - @Override - public boolean save(OutputStream zos) { - throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); - } - - @Override - public boolean load(InputStream ios) { - throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); - } - - @Override - public void close() { - // Do nothing - } - - @Override - public void flush() { - // Do nothing - } + /** + * Convert a string value into a Optional + */ + private Optional setStringValue(String s) { + if (s == null || s.isEmpty()) { + return Optional.empty(); + } + return Optional.of(s); + } + + /** + * Convert a string value represented a date into a Optional. + * + * @throws InvalidFormatException + * Throws if the date format isnot valid. + */ + private Optional setDateValue(String dateStr) throws InvalidFormatException { + if (dateStr == null || dateStr.isEmpty()) { + return Optional.empty(); + } + + Matcher m = TIME_ZONE_PAT.matcher(dateStr); + if (m.find()) { + String dateTzStr = dateStr.substring(0, m.start())+ + m.group(1)+m.group(2); + for (String fStr : TZ_DATE_FORMATS) { + SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT); + df.setTimeZone(LocaleUtil.TIMEZONE_UTC); + Date d = df.parse(dateTzStr, new ParsePosition(0)); + if (d != null) { + return Optional.of(d); + } + } + } + String dateTzStr = dateStr.endsWith("Z") ? dateStr : (dateStr + "Z"); + for (String fStr : DATE_FORMATS) { + SimpleDateFormat df = new SimpleDateFormat(fStr, Locale.ROOT); + df.setTimeZone(LocaleUtil.TIMEZONE_UTC); + Date d = df.parse(dateTzStr, new ParsePosition(0)); + if (d != null) { + return Optional.of(d); + } + } + //if you're here, no pattern matched, throw exception + StringBuilder sb = new StringBuilder(); + int i = 0; + for (String fStr : TZ_DATE_FORMATS) { + if (i++ > 0) { + sb.append(", "); + } + sb.append(fStr); + } + for (String fStr : DATE_FORMATS) { + sb.append(", ").append(fStr); + } + throw new InvalidFormatException("Date " + dateStr + " not well formatted, " + + "expected format in: "+ sb); + } + + /** + * Convert a Optional into a String. + * + * @param d + * The Date to convert. + * @return The formated date or null. + * @see java.text.SimpleDateFormat + */ + private String getDateValue(Optional d) { + if (d == null || !d.isPresent()) { + return ""; + } + SimpleDateFormat df = new SimpleDateFormat(DEFAULT_DATEFORMAT, Locale.ROOT); + df.setTimeZone(LocaleUtil.TIMEZONE_UTC); + return df.format(d.get()); + } + + @Override + protected InputStream getInputStreamImpl() { + throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); + } + + @Override + protected OutputStream getOutputStreamImpl() { + throw new InvalidOperationException( + "Can't use output stream to set properties !"); + } + + @Override + public boolean save(OutputStream zos) { + throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); + } + + @Override + public boolean load(InputStream ios) { + throw new InvalidOperationException("Operation not authorized. This part may only be manipulated using the getters and setters on PackagePropertiesPart"); + } + + @Override + public void close() { + // Do nothing + } + + @Override + public void flush() { + // Do nothing + } } From f91527da42eb9a4cdfc0a84c340b8a41c9b9683d Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 9 Jun 2018 00:24:33 +0100 Subject: [PATCH 5/6] add @since annotations to new methods --- .../apache/poi/openxml4j/opc/PackageProperties.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java index 5d00ce8d5e0..8cb108db370 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java @@ -54,6 +54,7 @@ public interface PackageProperties { /** * Set the category of the content of this package. + * @since 4.0.0 */ void setCategoryProperty(Optional category); @@ -70,6 +71,7 @@ public interface PackageProperties { /** * Get the status of the content. + * @since 4.0.0 */ void setContentStatusProperty(Optional contentStatus); @@ -89,6 +91,7 @@ public interface PackageProperties { /** * Set the type of content represented, generally defined by a specific use * and intended audience. + * @since 4.0.0 */ void setContentTypeProperty(Optional contentType); @@ -124,6 +127,7 @@ public interface PackageProperties { /** * Set the entity primarily responsible for making the content of the * resource. + * @since 4.0.0 */ void setCreatorProperty(Optional creator); @@ -139,6 +143,7 @@ public interface PackageProperties { /** * Set the explanation of the content of the resource. + * @since 4.0.0 */ void setDescriptionProperty(Optional description); @@ -155,6 +160,7 @@ public interface PackageProperties { /** * Set an unambiguous reference to the resource within a given context. + * @since 4.0.0 */ void setIdentifierProperty(Optional identifier); @@ -177,6 +183,7 @@ public interface PackageProperties { * Set a delimited set of keywords to support searching and indexing. This * is typically a list of terms that are not available elsewhere in the * properties + * @since 4.0.0 */ void setKeywordsProperty(Optional keywords); @@ -193,6 +200,7 @@ public interface PackageProperties { /** * Set the language of the intellectual content of the resource. + * @since 4.0.0 */ void setLanguageProperty(Optional language); @@ -208,6 +216,7 @@ public interface PackageProperties { /** * Set the user who performed the last modification. + * @since 4.0.0 */ void setLastModifiedByProperty(Optional lastModifiedBy); @@ -256,6 +265,7 @@ public interface PackageProperties { /** * Set the revision number. + * @since 4.0.0 */ void setRevisionProperty(Optional revision); @@ -272,6 +282,7 @@ public interface PackageProperties { /** * Set the topic of the content of the resource. + * @since 4.0.0 */ void setSubjectProperty(Optional subject); @@ -288,6 +299,7 @@ public interface PackageProperties { /** * Set the name given to the resource. + * @since 4.0.0 */ void setTitleProperty(Optional title); @@ -304,6 +316,7 @@ public interface PackageProperties { /** * Set the version number. + * @since 4.0.0 */ void setVersionProperty(Optional version); } From 9bd179c39aa492acb9806c47e76f9ca76b08a010 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 9 Jun 2018 00:26:41 +0100 Subject: [PATCH 6/6] fix indents --- .../poi/openxml4j/opc/PackageProperties.java | 306 +++++++++--------- 1 file changed, 153 insertions(+), 153 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java index 8cb108db370..6d832090cd3 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageProperties.java @@ -28,46 +28,46 @@ Licensed to the Apache Software Foundation (ASF) under one or more * @see org.apache.poi.openxml4j.opc.OPCPackage */ public interface PackageProperties { - - /** - * Dublin Core Terms URI. - */ - String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/"; - - /** - * Dublin Core namespace URI. - */ - String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/"; - - /* Getters and setters */ - - /** - * Set the category of the content of this package. - * @return property value - */ - Optional getCategoryProperty(); - - /** - * Set the category of the content of this package. - */ - void setCategoryProperty(String category); + + /** + * Dublin Core Terms URI. + */ + String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/"; + + /** + * Dublin Core namespace URI. + */ + String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/"; + + /* Getters and setters */ + + /** + * Set the category of the content of this package. + * @return property value + */ + Optional getCategoryProperty(); /** * Set the category of the content of this package. - * @since 4.0.0 + */ + void setCategoryProperty(String category); + + /** + * Set the category of the content of this package. + * @since 4.0.0 */ void setCategoryProperty(Optional category); /** - * Set the status of the content. + * Set the status of the content. * @return property value - */ - Optional getContentStatusProperty(); + */ + Optional getContentStatusProperty(); - /** - * Get the status of the content. - */ - void setContentStatusProperty(String contentStatus); + /** + * Get the status of the content. + */ + void setContentStatusProperty(String contentStatus); /** * Get the status of the content. @@ -76,17 +76,17 @@ public interface PackageProperties { void setContentStatusProperty(Optional contentStatus); /** - * Get the type of content represented, generally defined by a specific use - * and intended audience. + * Get the type of content represented, generally defined by a specific use + * and intended audience. * @return property value - */ - Optional getContentTypeProperty(); + */ + Optional getContentTypeProperty(); - /** - * Set the type of content represented, generally defined by a specific use - * and intended audience. - */ - void setContentTypeProperty(String contentType); + /** + * Set the type of content represented, generally defined by a specific use + * and intended audience. + */ + void setContentTypeProperty(String contentType); /** * Set the type of content represented, generally defined by a specific use @@ -95,34 +95,34 @@ public interface PackageProperties { */ void setContentTypeProperty(Optional contentType); - /** - * Get the date of creation of the resource. + /** + * Get the date of creation of the resource. * @return property value - */ - Optional getCreatedProperty(); - - /** - * Set the date of creation of the resource. - */ - void setCreatedProperty(String created); - - /** - * Set the date of creation of the resource. - */ - void setCreatedProperty(Optional created); - - /** - * Get the entity primarily responsible for making the content of the - * resource. + */ + Optional getCreatedProperty(); + + /** + * Set the date of creation of the resource. + */ + void setCreatedProperty(String created); + + /** + * Set the date of creation of the resource. + */ + void setCreatedProperty(Optional created); + + /** + * Get the entity primarily responsible for making the content of the + * resource. * @return property value - */ - Optional getCreatorProperty(); + */ + Optional getCreatorProperty(); - /** - * Set the entity primarily responsible for making the content of the - * resource. - */ - void setCreatorProperty(String creator); + /** + * Set the entity primarily responsible for making the content of the + * resource. + */ + void setCreatorProperty(String creator); /** * Set the entity primarily responsible for making the content of the @@ -132,14 +132,14 @@ public interface PackageProperties { void setCreatorProperty(Optional creator); /** - * Get the explanation of the content of the resource. - */ - Optional getDescriptionProperty(); + * Get the explanation of the content of the resource. + */ + Optional getDescriptionProperty(); - /** - * Set the explanation of the content of the resource. - */ - void setDescriptionProperty(String description); + /** + * Set the explanation of the content of the resource. + */ + void setDescriptionProperty(String description); /** * Set the explanation of the content of the resource. @@ -147,16 +147,16 @@ public interface PackageProperties { */ void setDescriptionProperty(Optional description); - /** - * Get an unambiguous reference to the resource within a given context. + /** + * Get an unambiguous reference to the resource within a given context. * @return property value - */ - Optional getIdentifierProperty(); + */ + Optional getIdentifierProperty(); - /** - * Set an unambiguous reference to the resource within a given context. - */ - void setIdentifierProperty(String identifier); + /** + * Set an unambiguous reference to the resource within a given context. + */ + void setIdentifierProperty(String identifier); /** * Set an unambiguous reference to the resource within a given context. @@ -165,19 +165,19 @@ public interface PackageProperties { void setIdentifierProperty(Optional identifier); /** - * Get a delimited set of keywords to support searching and indexing. This - * is typically a list of terms that are not available elsewhere in the - * properties + * Get a delimited set of keywords to support searching and indexing. This + * is typically a list of terms that are not available elsewhere in the + * properties * @return property value - */ - Optional getKeywordsProperty(); + */ + Optional getKeywordsProperty(); - /** - * Set a delimited set of keywords to support searching and indexing. This - * is typically a list of terms that are not available elsewhere in the - * properties - */ - void setKeywordsProperty(String keywords); + /** + * Set a delimited set of keywords to support searching and indexing. This + * is typically a list of terms that are not available elsewhere in the + * properties + */ + void setKeywordsProperty(String keywords); /** * Set a delimited set of keywords to support searching and indexing. This @@ -187,16 +187,16 @@ public interface PackageProperties { */ void setKeywordsProperty(Optional keywords); - /** - * Get the language of the intellectual content of the resource. + /** + * Get the language of the intellectual content of the resource. * @return property value - */ - Optional getLanguageProperty(); + */ + Optional getLanguageProperty(); - /** - * Set the language of the intellectual content of the resource. - */ - void setLanguageProperty(String language); + /** + * Set the language of the intellectual content of the resource. + */ + void setLanguageProperty(String language); /** * Set the language of the intellectual content of the resource. @@ -205,14 +205,14 @@ public interface PackageProperties { void setLanguageProperty(Optional language); /** - * Get the user who performed the last modification. - */ - Optional getLastModifiedByProperty(); + * Get the user who performed the last modification. + */ + Optional getLastModifiedByProperty(); - /** - * Set the user who performed the last modification. - */ - void setLastModifiedByProperty(String lastModifiedBy); + /** + * Set the user who performed the last modification. + */ + void setLastModifiedByProperty(String lastModifiedBy); /** * Set the user who performed the last modification. @@ -221,47 +221,47 @@ public interface PackageProperties { void setLastModifiedByProperty(Optional lastModifiedBy); /** - * Get the date and time of the last printing. + * Get the date and time of the last printing. * @return property value */ - Optional getLastPrintedProperty(); + Optional getLastPrintedProperty(); + + /** + * Set the date and time of the last printing. + */ + void setLastPrintedProperty(String lastPrinted); - /** - * Set the date and time of the last printing. - */ - void setLastPrintedProperty(String lastPrinted); - - /** - * Set the date and time of the last printing. - */ - void setLastPrintedProperty(Optional lastPrinted); + /** + * Set the date and time of the last printing. + */ + void setLastPrintedProperty(Optional lastPrinted); - /** - * Get the date on which the resource was changed. + /** + * Get the date on which the resource was changed. * @return property value - */ - Optional getModifiedProperty(); + */ + Optional getModifiedProperty(); - /** - * Set the date on which the resource was changed. - */ - void setModifiedProperty(String modified); - - /** - * Set the date on which the resource was changed. - */ - void setModifiedProperty(Optional modified); + /** + * Set the date on which the resource was changed. + */ + void setModifiedProperty(String modified); + + /** + * Set the date on which the resource was changed. + */ + void setModifiedProperty(Optional modified); /** - * Get the revision number. + * Get the revision number. * @return property value - */ - Optional getRevisionProperty(); + */ + Optional getRevisionProperty(); - /** - * Set the revision number. - */ - void setRevisionProperty(String revision); + /** + * Set the revision number. + */ + void setRevisionProperty(String revision); /** * Set the revision number. @@ -270,15 +270,15 @@ public interface PackageProperties { void setRevisionProperty(Optional revision); /** - * Get the topic of the content of the resource. + * Get the topic of the content of the resource. * @return property value - */ - Optional getSubjectProperty(); + */ + Optional getSubjectProperty(); - /** - * Set the topic of the content of the resource. - */ - void setSubjectProperty(String subject); + /** + * Set the topic of the content of the resource. + */ + void setSubjectProperty(String subject); /** * Set the topic of the content of the resource. @@ -287,10 +287,10 @@ public interface PackageProperties { void setSubjectProperty(Optional subject); /** - * Get the name given to the resource. + * Get the name given to the resource. * @return property value - */ - Optional getTitleProperty(); + */ + Optional getTitleProperty(); /** * Set the name given to the resource. @@ -298,16 +298,16 @@ public interface PackageProperties { void setTitleProperty(String title); /** - * Set the name given to the resource. + * Set the name given to the resource. * @since 4.0.0 - */ - void setTitleProperty(Optional title); + */ + void setTitleProperty(Optional title); /** - * Get the version number. + * Get the version number. * @return property value - */ - Optional getVersionProperty(); + */ + Optional getVersionProperty(); /** * Set the version number.