pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1860826 - in /pdfbox/trunk: ./ 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:25:43 GMT
Author: lehmi
Date: Sat Jun  8 11:25:43 2019
New Revision: 1860826

URL: http://svn.apache.org/viewvc?rev=1860826&view=rev
Log:
DFBOX-4562: replace call of COSDocument.getCatalog, remove no longer needed method

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

Propchange: pdfbox/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jun  8 11:25:43 2019
@@ -1,3 +1,3 @@
-/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712,1799081-1799082,1814046,1814285,1814459,1824914,1825811,1825820,1825912,1844477,1844516,1844519,1844567,1850577,1857953,1858696,1858698
+/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712,1799081-1799082,1814046,1814285,1814459,1824914,1825811,1825820,1825912,1844477,1844516,1844519,1844567,1850577,1857953,1858696,1858698,1860825
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1860826&r1=1860825&r2=1860826&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sat Jun  8 11:25:43
2019
@@ -28,6 +28,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
@@ -360,23 +361,6 @@ public class COSDocument extends COSBase
     }
     
     /**
-     * This will get the document catalog.
-     *
-     * @return The catalog that is the root of the document; never null.
-     *
-     * @throws IOException If no catalog can be found.
-     */
-    public COSObject getCatalog() throws IOException
-    {
-        COSObject catalog = getObjectByType( COSName.CATALOG );
-        if( catalog == null )
-        {
-            throw new IOException( "Catalog cannot be found" );
-        }
-        return catalog;
-    }
-
-    /**
      * This will get a list of all available objects.
      *
      * @return A list of all objects, never null.

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java?rev=1860826&r1=1860825&r2=1860826&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
Sat Jun  8 11:25:43 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