From 837590024f3261354d4919589bf51426ad050433 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 13 Dec 2021 13:12:32 +0000 Subject: [PATCH] [bug-65741] rework previous change git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895881 13f79535-47bb-0310-9956-ffa450edef68 --- .../opc/internal/PackagePropertiesPart.java | 81 +++++++++---------- .../java/org/apache/poi/hsmf/MAPIMessage.java | 2 +- .../usermodel/TestHSSFRichTextString.java | 4 +- .../ss/usermodel/BaseTestDataValidation.java | 4 +- test-data/spreadsheet/extendedtextstrings.txt | 4 +- test-data/spreadsheet/richtextdata.txt | 4 +- 6 files changed, 45 insertions(+), 54 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index e390d504e8..16e0bd13b7 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -236,7 +236,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP } /** - * Get created date formated into a String. + * Get created date formatted into a String. * * @return A string representation of the created date. */ @@ -308,7 +308,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP } /** - * Get last printed date formated into a String. + * Get last printed date formatted into a String. * * @return A string representation of the last printed date. */ @@ -326,7 +326,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP } /** - * Get modified date formated into a String. + * Get modified date formatted into a String. * * @return A string representation of the modified date. */ @@ -379,7 +379,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setCategoryProperty(String category) { - this.category = setStringValue(category); + this.category = parseStringValue(category); } /** @@ -395,7 +395,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setContentStatusProperty(String contentStatus) { - this.contentStatus = setStringValue(contentStatus); + this.contentStatus = parseStringValue(contentStatus); } /** @@ -411,7 +411,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setContentTypeProperty(String contentType) { - this.contentType = setStringValue(contentType); + this.contentType = parseStringValue(contentType); } /** @@ -428,12 +428,10 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setCreatedProperty(String created) { - if (created != null) { - try { - this.created = setDateValue(created); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); - } + try { + this.created = parseDateValue(created); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("Date for created could not be parsed: " + created, e); } } @@ -443,8 +441,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setCreatedProperty(Optional created) { - if (created.isPresent()) - this.created = created; + this.created = created; } /** @@ -453,7 +450,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setCreatorProperty(String creator) { - this.creator = setStringValue(creator); + this.creator = parseStringValue(creator); } /** @@ -469,7 +466,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setDescriptionProperty(String description) { - this.description = setStringValue(description); + this.description = parseStringValue(description); } /** @@ -485,7 +482,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setIdentifierProperty(String identifier) { - this.identifier = setStringValue(identifier); + this.identifier = parseStringValue(identifier); } /** @@ -501,7 +498,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setKeywordsProperty(String keywords) { - this.keywords = setStringValue(keywords); + this.keywords = parseStringValue(keywords); } /** @@ -517,7 +514,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setLanguageProperty(String language) { - this.language = setStringValue(language); + this.language = parseStringValue(language); } /** @@ -533,7 +530,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setLastModifiedByProperty(String lastModifiedBy) { - this.lastModifiedBy = setStringValue(lastModifiedBy); + this.lastModifiedBy = parseStringValue(lastModifiedBy); } /** @@ -552,13 +549,11 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setLastPrintedProperty(String lastPrinted) { - if (lastPrinted != null) { - try { - this.lastPrinted = setDateValue(lastPrinted); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("lastPrinted : " - + e.getLocalizedMessage(), e); - } + try { + this.lastPrinted = parseDateValue(lastPrinted); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("lastPrinted : " + + e.getLocalizedMessage(), e); } } @@ -568,8 +563,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setLastPrintedProperty(Optional lastPrinted) { - if (lastPrinted.isPresent()) - this.lastPrinted = lastPrinted; + this.lastPrinted = lastPrinted; } /** @@ -579,13 +573,11 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setModifiedProperty(String modified) { - if (modified != null) { - try { - this.modified = setDateValue(modified); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException("modified : " - + e.getLocalizedMessage(), e); - } + try { + this.modified = parseDateValue(modified); + } catch (InvalidFormatException e) { + throw new IllegalArgumentException("modified : " + + e.getLocalizedMessage(), e); } } @@ -595,8 +587,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setModifiedProperty(Optional modified) { - if (modified.isPresent()) - this.modified = modified; + this.modified = modified; } /** @@ -612,7 +603,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setRevisionProperty(String revision) { - this.revision = setStringValue(revision); + this.revision = parseStringValue(revision); } /** * Set subject. @@ -620,7 +611,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setSubjectProperty(String subject) { - this.subject = setStringValue(subject); + this.subject = parseStringValue(subject); } /** @@ -636,7 +627,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setTitleProperty(String title) { - this.title = setStringValue(title); + this.title = parseStringValue(title); } /** @@ -652,7 +643,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP */ @Override public void setVersionProperty(String version) { - this.version = setStringValue(version); + this.version = parseStringValue(version); } /** @@ -665,7 +656,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP /** * Convert a string value into a {@code Optional} */ - private Optional setStringValue(String s) { + private Optional parseStringValue(String s) { if (s == null || s.isEmpty()) { return Optional.empty(); } @@ -678,7 +669,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP * @throws InvalidFormatException * Throws if the date format is not valid. */ - private Optional setDateValue(String dateStr) throws InvalidFormatException { + private Optional parseDateValue(String dateStr) throws InvalidFormatException { if (dateStr == null || dateStr.isEmpty()) { return Optional.empty(); } @@ -720,7 +711,7 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP * * @param d * The Date to convert. - * @return The formated date or null. + * @return The formatted date or null. * @see java.text.SimpleDateFormat */ private static String getDateValue(Optional d) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java index 6e36712276..f13d397705 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java @@ -269,7 +269,7 @@ public class MAPIMessage extends POIReadOnlyDocument { /** * Gets the display value of the "FROM" line of the outlook message - * This is not the actual address that was sent from but the formated display of the user name. + * This is not the actual address that was sent from but the formatted display of the user name. * @throws ChunkNotFoundException If the from-chunk does not exist and * returnNullOnMissingChunk is set */ diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java index 44ae5b4fcf..c8f4b2ed7d 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java @@ -75,7 +75,7 @@ final class TestHSSFRichTextString { /** - * Test case proposed in Bug 40520: formated twice => will format whole String + * Test case proposed in Bug 40520: formatted twice => will format whole String */ @Test void test40520_1() { @@ -109,7 +109,7 @@ final class TestHSSFRichTextString { } /** - * Test case proposed in Bug 40520: formated twice => will format whole String + * Test case proposed in Bug 40520: formatted twice => will format whole String */ @Test void test40520_3() { diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataValidation.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataValidation.java index 540563ef49..dc6302a5e5 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataValidation.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataValidation.java @@ -421,7 +421,7 @@ public abstract class BaseTestDataValidation { CellStyle cellStyle_time = wb.createCellStyle(); cellStyle_time.setDataFormat(fmtTime); - wf.createDVTypeRow("Date ( cells are already formated as date - m/d/yyyy)"); + wf.createDVTypeRow("Date ( cells are already formatted as date - m/d/yyyy)"); wf.createHeaderRow(); ValidationAdder va = wf.createValidationAdder(cellStyle_date, ValidationType.DATE); @@ -435,7 +435,7 @@ public abstract class BaseTestDataValidation { va.addValidation(OperatorType.LESS_OR_EQUAL, "2004/03/04", null, ErrorStyle.STOP, "Less than or equal to 3/4/2004", "-", false, true, false); // "Time" validation type - wf.createDVTypeRow("Time ( cells are already formated as time - h:mm)"); + wf.createDVTypeRow("Time ( cells are already formatted as time - h:mm)"); wf.createHeaderRow(); va = wf.createValidationAdder(cellStyle_time, ValidationType.TIME); diff --git a/test-data/spreadsheet/extendedtextstrings.txt b/test-data/spreadsheet/extendedtextstrings.txt index 93c080bb9f..e190897bf4 100644 --- a/test-data/spreadsheet/extendedtextstrings.txt +++ b/test-data/spreadsheet/extendedtextstrings.txt @@ -21,9 +21,9 @@ 41 74 20 41 74 20 -00 00 # Formatting run 1, first formated char at 0 +00 00 # Formatting run 1, first formatted char at 0 00 00 # Formatting run 1, Index to font record -02 00 # Formatting run 2, first formated char at 2 +02 00 # Formatting run 2, first formatted char at 2 00 00 # Formatting run 2, Index to font record FF FF FF # extended data diff --git a/test-data/spreadsheet/richtextdata.txt b/test-data/spreadsheet/richtextdata.txt index 0741d7ad74..2ff6e2c8e9 100644 --- a/test-data/spreadsheet/richtextdata.txt +++ b/test-data/spreadsheet/richtextdata.txt @@ -17,7 +17,7 @@ 41 74 20 41 74 20 -00 00 # Formatting run 1, first formated char at 0 +00 00 # Formatting run 1, first formatted char at 0 00 00 # Formatting run 1, Index to font record -02 00 # Formatting run 2, first formated char at 2 +02 00 # Formatting run 2, first formatted char at 2 00 00 # Formatting run 2, Index to font record -- 2.39.5