pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1860825 - in /pdfbox/branches/2.0: 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:22:04 GMT
Author: lehmi
Date: Sat Jun  8 11:22:04 2019
New Revision: 1860825

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

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1860825&r1=1860824&r2=1860825&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sat Jun
 8 11:22:04 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/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java?rev=1860825&r1=1860824&r2=1860825&view=diff
==============================================================================
--- pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
(original)
+++ pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
Sat Jun  8 11:22:04 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