[FOray-commit] SF.net SVN: foray:[12527] trunk/foray/foray-pdf/src
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-02-01 17:43:13
|
Revision: 12527
http://sourceforge.net/p/foray/code/12527
Author: victormote
Date: 2022-02-01 17:43:10 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Move unwrap logic to static methods in the type/structure classes.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -28,6 +28,8 @@
package org.foray.pdf.interchange;
+import org.foray.pdf.structure.PdfDate;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfDictionary;
import org.axsl.pdf.PdfDocumentInfo;
@@ -158,47 +160,47 @@
@Override
public String getTitle() {
- return getString(TITLE_KEY);
+ return PdfTextString.unwrap(getPdfTextString(TITLE_KEY));
}
@Override
public String getAuthor() {
- return getString(AUTHOR_KEY);
+ return PdfTextString.unwrap(getPdfTextString(AUTHOR_KEY));
}
@Override
public String getSubject() {
- return getString(SUBJECT_KEY);
+ return PdfTextString.unwrap(getPdfTextString(SUBJECT_KEY));
}
@Override
public String getKeywords() {
- return getString(KEYWORDS_KEY);
+ return PdfTextString.unwrap(getPdfTextString(KEYWORDS_KEY));
}
@Override
public String getCreator() {
- return getString(CREATOR_KEY);
+ return PdfTextString.unwrap(getPdfTextString(CREATOR_KEY));
}
@Override
public String getProducer() {
- return getString(PRODUCER_KEY);
+ return PdfTextString.unwrap(getPdfTextString(PRODUCER_KEY));
}
@Override
public Date getCreationDate() {
- return getDate(CREATION_DATE_KEY);
+ return PdfDate.unwrap(getPdfDate(CREATION_DATE_KEY));
}
@Override
public Date getModDate() {
- return getDate(MOD_DATE_KEY);
+ return PdfDate.unwrap(getPdfDate(MOD_DATE_KEY));
}
@Override
public PdfDocumentTrapped getTrapped() {
- return PdfDocumentTrapped.fromName(getString(PRODUCER_KEY));
+ return PdfDocumentTrapped.fromName(PdfTextString.unwrap(getPdfTextString(PRODUCER_KEY)));
}
@Override
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -49,12 +49,10 @@
*/
public class PdfDate extends PdfObject {
- /** The number of chars used to represent the time zone hours in a Java
- * Date. */
+ /** The number of chars used to represent the time zone hours in a Java Date. */
private static final int TIMEZONE_HOURS_SIZE = 3;
- /** The number of chars used to represent the time zone minutes in a Java
- * Date. */
+ /** The number of chars used to represent the time zone minutes in a Java Date. */
private static final int TIMEZONE_MINUTES_SIZE = 2;
/** The encapsulated Date instance. */
@@ -97,4 +95,16 @@
return this.date;
}
+ /**
+ * Null-safe unwrapping of a given date.
+ * @param pdfDate The date to be unwrapped, which can be null.
+ * @return The wrapped date, or null if {@code pdfDate} is null.
+ */
+ public static Date unwrap(final PdfDate pdfDate) {
+ if (pdfDate == null) {
+ return null;
+ }
+ return pdfDate.getValue();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -212,4 +212,16 @@
return this.theSequence;
}
+ /**
+ * Null-safe unwrapping of a given string.
+ * @param pdfTextString The text string to be unwrapped, which can be null.
+ * @return The wrapped String, or null if {@code pdfTextString} is null.
+ */
+ public static String unwrap(final PdfTextString pdfTextString) {
+ if (pdfTextString == null) {
+ return null;
+ }
+ return pdfTextString.getValue().toString();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -40,7 +40,6 @@
import java.math.BigDecimal;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
/**
@@ -153,11 +152,6 @@
return retrieve(index, PdfTextString.class);
}
- public String getString(final int index) {
- final PdfTextString value = getPdfTextString(index);
- return value == null ? null : value.toString();
- }
-
/**
* Returns the {@link PdfHexString} at a given index.
* @param index The index for which the element should be returned.
@@ -178,11 +172,6 @@
return retrieve(index, PdfInteger.class);
}
- public int getInteger(final int index) {
- final PdfInteger value = getPdfInteger(index);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfReal} at a given index.
* @param index The index for which the element should be returned.
@@ -193,11 +182,6 @@
return retrieve(index, PdfReal.class);
}
- public BigDecimal getBigDecimal(final int index) {
- final PdfReal value = getPdfReal(index);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfDate} at a given index.
* @param index The index for which the element should be returned.
@@ -208,11 +192,6 @@
return retrieve(index, PdfDate.class);
}
- public Date getDate(final int index) {
- final PdfDate value = getPdfDate(index);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfDictionary} at a given index.
* @param index The index for which the element should be returned.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -162,10 +162,19 @@
return this.outputOrder == null ? getOutputOrder() : this.outputOrder;
}
+ /**
+ * Indicates whether this dictionary is empty.
+ * @return True if and only if this dictionary has no entries.
+ */
public boolean isEmpty() {
return this.entries.isEmpty();
}
+ /**
+ * Adds an entry to this dictionary.
+ * @param key The key to the entry being added.
+ * @param value The value of the entry being added.
+ */
public void put(final String key, final PdfObject value) {
this.entries.put(key, value);
}
@@ -184,16 +193,31 @@
put(key, textString);
}
+ /**
+ * Adds an integer to this dictionary.
+ * @param key The key to the entry being added.
+ * @param value The value of the entry being added.
+ */
public void put(final String key, final int value) {
final PdfInteger integer = new PdfInteger(value);
put(key, integer);
}
+ /**
+ * Adds an real number to this dictionary.
+ * @param key The key to the entry being added.
+ * @param value The value of the entry being added.
+ */
public void put(final String key, final BigDecimal value) {
final PdfReal integer = new PdfReal(value);
put(key, integer);
}
+ /**
+ * Adds a date to this dictionary.
+ * @param key The key to the entry being added.
+ * @param value The value of the entry being added.
+ */
public void put(final String key, final Date value) {
final PdfDate date = new PdfDate(value);
put(key, date);
@@ -207,6 +231,11 @@
return this.entries.size();
}
+ /**
+ * Returns an object from this dictionary, with no casting to the specific type.
+ * @param key The key for which the element should be returned.
+ * @return The value of {@code key}, or null if that key is not in this dictionary, or its value is null.
+ */
public PdfObject get(final String key) {
return this.entries.get(key);
}
@@ -221,11 +250,6 @@
return retrieve(key, PdfTextString.class);
}
- public String getString(final String key) {
- final PdfTextString value = getPdfTextString(key);
- return value == null ? null : value.toString();
- }
-
/**
* Returns the {@link PdfHexString} for a given key.
* @param key The key for which the element should be returned.
@@ -246,11 +270,6 @@
return retrieve(key, PdfInteger.class);
}
- public int getInteger(final String key) {
- final PdfInteger value = getPdfInteger(key);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfReal} for a given key.
* @param key The key for which the element should be returned.
@@ -261,11 +280,6 @@
return retrieve(key, PdfReal.class);
}
- public BigDecimal getBigDecimal(final String key) {
- final PdfReal value = getPdfReal(key);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfDate} for a given key.
* @param key The key for which the element should be returned.
@@ -276,11 +290,6 @@
return retrieve(key, PdfDate.class);
}
- public Date getDate(final String key) {
- final PdfDate value = getPdfDate(key);
- return value == null ? null : value.getValue();
- }
-
/**
* Returns the {@link PdfDictionary} for a given key.
* @param key The key for which the element should be returned.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -68,4 +68,16 @@
return Long.toString(this.value);
}
+ /**
+ * Null-safe unwrapping of a given integer.
+ * @param pdfInteger The integer to be unwrapped, which can be null.
+ * @return The wrapped int, or null if {@code pdfTextString} is null.
+ */
+ public static Integer unwrap(final PdfInteger pdfInteger) {
+ if (pdfInteger == null) {
+ return null;
+ }
+ return pdfInteger.getValue();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -67,4 +67,16 @@
return this.value;
}
+ /**
+ * Null-safe unwrapping of a given real number.
+ * @param pdfReal The real number to be unwrapped, which can be null.
+ * @return The wrapped real number, or null if {@code pdfReal} is null.
+ */
+ public static BigDecimal unwrap(final PdfReal pdfReal) {
+ if (pdfReal == null) {
+ return null;
+ }
+ return pdfReal.getValue();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java 2022-02-01 16:37:22 UTC (rev 12526)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java 2022-02-01 17:43:10 UTC (rev 12527)
@@ -274,7 +274,7 @@
final PdfDictionary trailer = out.parseTrailer();
Assert.assertEquals(3, trailer.size());
- Assert.assertEquals(7, trailer.getInteger("Size"));
+ Assert.assertEquals(7, PdfInteger.unwrap(trailer.getPdfInteger("Size")).intValue());
final PdfObjectReference rootReference = trailer.getPdfObjectReference("Root");
Assert.assertEquals(1, rootReference.getNumber());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|