pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1860827 - in /pdfbox/branches/issue45: ./ pdfbox/ pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
Date Sat, 08 Jun 2019 11:26:35 GMT
Author: lehmi
Date: Sat Jun  8 11:26:35 2019
New Revision: 1860827

URL: http://svn.apache.org/viewvc?rev=1860827&view=rev
Log:
DFBOX-4562: replace call of COSDocument.getCatalog, mark method as deprecated

Modified:
    pdfbox/branches/issue45/   (props changed)
    pdfbox/branches/issue45/pdfbox/   (props changed)
    pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/branches/issue45/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java

Propchange: pdfbox/branches/issue45/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jun  8 11:26:35 2019
@@ -1,3 +1,4 @@
+/pdfbox/branches/2.0:1860825
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516
 /pdfbox/trunk:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1743248,1745595,1745606,1745772,1745774,1745776,1745779,1746032,1746151,1749162,1749165,1749432,1766088,1766213,1767585,1768061,1770985,1770988,1772528,1778172,1782679,1786586,1786603,1787546,1789414,1790745,1794073,1794090,1794620,1794753,1794859,1794891,1800566,1812426,1814226,1826836,1859501,1859510,1859664,1859686

Propchange: pdfbox/branches/issue45/pdfbox/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jun  8 11:26:35 2019
@@ -1,3 +1,4 @@
+/pdfbox/branches/2.0/pdfbox:1860825
 /pdfbox/branches/no-awt/pdfbox:1618517-1621410
 /pdfbox/no-awt/pdfbox:1618514-1618516
 /pdfbox/trunk/pdfbox:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1743248,1745595,1745606,1745772,1745774,1745776,1745779,1746032,1746151,1749162,1749165,1749432,1757165,1758817,1767585,1770988,1772528,1778172,1782679,1786586,1786603,1787546,1789414,1790745,1794073,1794090,1794620,1794753,1794859,1794891,1812426,1814226,1826836,1859664,1859686

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1860827&r1=1860826&r2=1860827&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sat
Jun  8 11:26:35 2019
@@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.ScratchFile;
 import org.apache.pdfbox.pdfparser.PDFObjectStreamParser;
+import org.apache.pdfbox.pdmodel.PDDocument;
 
 /**
  * This is the in-memory representation of the PDF document.  You need to call
@@ -369,6 +370,8 @@ public class COSDocument extends COSBase
      * @return The catalog is the root of the document; never null.
      *
      * @throws IOException If no catalog can be found.
+     * 
+     * @deprecated use {@link PDDocument#getDocumentCatalog()} instead.
      */
     public COSObject getCatalog() throws IOException
     {

Modified: pdfbox/branches/issue45/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java?rev=1860827&r1=1860826&r2=1860827&view=diff
==============================================================================
--- pdfbox/branches/issue45/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
(original)
+++ pdfbox/branches/issue45/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
Sat Jun  8 11:26:35 2019
@@ -35,6 +35,8 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.common.PDMetadata;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -64,7 +66,7 @@ public class MetadataValidationProcess e
         {
             PDDocument document = ctx.getDocument();
 
-            InputStream is = getXpacket(document.getDocument());
+            InputStream is = getXpacket(document);
             DomXmpParser builder = new DomXmpParser();
             XMPMetadata metadata = builder.parse(is);
             is.close();
@@ -251,37 +253,38 @@ public class MetadataValidationProcess e
     /**
      * Return the xpacket from the dictionary's stream
      */
-    private static InputStream getXpacket(COSDocument cdocument) throws IOException, XpacketParsingException
+    private static InputStream getXpacket(PDDocument document)
+            throws IOException, XpacketParsingException
     {
-        COSObject catalog = cdocument.getCatalog();
-        COSBase cb = catalog.getDictionaryObject(COSName.METADATA);
-        if (cb == null)
-        {
+        PDDocumentCatalog catalog = document.getDocumentCatalog();
+        PDMetadata metadata = catalog.getMetadata();
+        if (metadata == null)
+        {
+            COSBase metaObject = catalog.getCOSObject().getDictionaryObject(COSName.METADATA);
+            if (!(metaObject instanceof COSStream))
+            {
+                // the Metadata object isn't a stream
+                ValidationError error = new ValidationError(
+                        PreflightConstants.ERROR_METADATA_FORMAT, "Metadata is not a stream");
+                throw new XpacketParsingException("Failed while retrieving xpacket", error);
+            }
             // missing Metadata Key in catalog
             ValidationError error = new ValidationError(PreflightConstants.ERROR_METADATA_FORMAT,
                     "Missing Metadata Key in catalog");
             throw new XpacketParsingException("Failed while retrieving xpacket", error);
         }
+
         // no filter key
-        COSDictionary metadataDictionnary = COSUtils.getAsDictionary(cb, cdocument);
-        if (metadataDictionnary.getItem(COSName.FILTER) != null)
+        if (metadata.getFilters() != null)
         {
             // should not be defined
-            ValidationError error = new ValidationError(PreflightConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
+            ValidationError error = new ValidationError(
+                    PreflightConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
                     "Filter specified in metadata dictionnary");
             throw new XpacketParsingException("Failed while retrieving xpacket", error);
         }
-        
-        if (!(metadataDictionnary instanceof COSStream))
-        {
-            // missing Metadata Key in catalog
-            ValidationError error = new ValidationError(PreflightConstants.ERROR_METADATA_FORMAT,
-                    "Metadata is not a stream");
-            throw new XpacketParsingException("Failed while retrieving xpacket", error);
-        }
 
-        COSStream stream = (COSStream) metadataDictionnary;
-        return stream.createInputStream();
+        return metadata.exportXMPMetadata();
     }
 
     /**



Mime
View raw message