pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1861524 - in /pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox: cos/COSObject.java cos/ICOSParser.java pdfparser/BaseParser.java pdfparser/COSParser.java pdfparser/PDFObjectStreamParser.java pdfparser/PDFStreamParser.java
Date Mon, 17 Jun 2019 16:26:14 GMT
Author: lehmi
Date: Mon Jun 17 16:26:14 2019
New Revision: 1861524

URL: http://svn.apache.org/viewvc?rev=1861524&view=rev
Log:
PDFBOX-4569: introduced an interface to decouple the classes COSObject and COSParser

Added:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java 
 (with props)
Modified:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java?rev=1861524&r1=1861523&r2=1861524&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java Mon
Jun 17 16:26:14 2019
@@ -18,9 +18,6 @@ package org.apache.pdfbox.cos;
 
 import java.io.IOException;
 
-import org.apache.pdfbox.pdfparser.BaseParser;
-import org.apache.pdfbox.pdfparser.COSParser;
-
 /**
  * This class represents a PDF object.
  *
@@ -33,7 +30,7 @@ public class COSObject extends COSBase i
     private long objectNumber;
     private int generationNumber;
     private boolean needToBeUpdated;
-    private BaseParser parser;
+    private ICOSParser parser;
 
     /**
      * Constructor.
@@ -41,13 +38,25 @@ public class COSObject extends COSBase i
      * @param object The object that this encapsulates.
      *
      */
-    public COSObject(COSBase object, BaseParser parser)
+    public COSObject(COSBase object)
+    {
+        setObject(object);
+        parser = null;
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param object The object that this encapsulates.
+     * @param parser The parser to be used to load the object on demand
+     *
+     */
+    public COSObject(COSBase object, ICOSParser parser)
     // public COSObject(COSBase object)
     {
         setObject( object );
         this.parser = parser;
     }
-
     /**
      * This will get the dictionary object in this object that has the name key and
      * if it is a pdfobjref then it will dereference that and return it.
@@ -96,9 +105,9 @@ public class COSObject extends COSBase i
     {
         if (baseObject == null || baseObject instanceof COSNull)
         {
-            if (parser instanceof COSParser)
+            if (parser != null)
             {
-                boolean returnValue = ((COSParser) parser).dereferenceCOSObject(this);
+                boolean returnValue = parser.dereferenceCOSObject(this);
                 if (!returnValue)
                 {
                     // remove parser to avoid endless recursions

Added: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java?rev=1861524&view=auto
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java (added)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java Mon
Jun 17 16:26:14 2019
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.cos;
+
+public interface ICOSParser
+{
+
+    /**
+     * Dereference the COSBase object which is referenced by the given COSObject.
+     * 
+     * @param obj the COSObject which references the COSBase object to be dereferenced.
+     * 
+     * @return true if the referenced object was read successfully
+     */
+    public boolean dereferenceCOSObject(COSObject obj);
+
+}

Propchange: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1861524&r1=1861523&r2=1861524&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
Mon Jun 17 16:26:14 2019
@@ -924,7 +924,7 @@ public abstract class BaseParser
         }
         case 'R':
             seqSource.read();
-            retval = new COSObject(null, this);
+            retval = new COSObject(null);
             break;
         case (char)-1:
             return null;

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1861524&r1=1861523&r2=1861524&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Mon Jun 17 16:26:14 2019
@@ -50,6 +50,7 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSObjectKey;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.cos.ICOSParser;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType;
@@ -70,7 +71,7 @@ import org.apache.pdfbox.pdmodel.encrypt
  * This class is a much enhanced version of <code>QuickParser</code> presented
in <a
  * href="https://issues.apache.org/jira/browse/PDFBOX-1104">PDFBOX-1104</a> by Jeremy
Villalobos.
  */
-public class COSParser extends BaseParser
+public class COSParser extends BaseParser implements ICOSParser
 {
     private static final String PDF_HEADER = "%PDF-";
     private static final String FDF_HEADER = "%FDF-";

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java?rev=1861524&r1=1861523&r2=1861524&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
Mon Jun 17 16:26:14 2019
@@ -87,7 +87,7 @@ public class PDFObjectStreamParser exten
             int objectCounter = 0;
             while( (cosObject = parseDirObject()) != null )
             {
-                object = new COSObject(cosObject, null);
+                object = new COSObject(cosObject);
                 object.setGenerationNumber(0);
                 if (objectCounter >= objectNumbers.size())
                 {

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1861524&r1=1861523&r2=1861524&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
Mon Jun 17 16:26:14 2019
@@ -191,7 +191,7 @@ public class PDFStreamParser extends Bas
                 String line = readString();
                 if( line.equals( "R" ) )
                 {
-                retval = new COSObject(null, this);
+                retval = new COSObject(null);
                 }
                 else
                 {



Mime
View raw message