Author: lehmi Date: Sat Feb 28 15:52:32 2015 New Revision: 1662951 URL: http://svn.apache.org/r1662951 Log: PDFBOX-2685: introduced new interface COSUpdateInfo as COSObject need to have the same functionality the COSDictionary
Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java (with props) pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSUpdateInfo.java - copied, changed from r1662310, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java Removed: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1662951&r1=1662950&r2=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Sat Feb 28 15:52:32 2015 @@ -29,10 +29,10 @@ import org.apache.pdfbox.util.DateConver /** * This class represents a dictionary where name/value pairs reside. * - * @author <a href="b...@benlitchfield.com">Ben Litchfield</a> - * @version $Revision: 1.32 $ + * @author Ben Litchfield + * */ -public class COSDictionary extends COSBase +public class COSDictionary extends COSBase implements COSUpdateInfo { private static final String PATH_SEPARATOR = "/"; private boolean needToBeUpdated; @@ -1320,26 +1320,17 @@ public class COSDictionary extends COSBa return visitor.visitFromDictionary(this); } - /** - * Get the update state for the COSWriter. - * - * @return the update state. - */ + @Override public boolean isNeedToBeUpdated() { return needToBeUpdated; } - /** - * Set the update state of the dictionary for the COSWriter. - * - * @param flag the update state. - */ + @Override public void setNeedToBeUpdated(boolean flag) { needToBeUpdated = flag; } - /** * This will add all of the dictionarys keys/values to this dictionary. Only called when adding keys to a trailer Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java?rev=1662951&r1=1662950&r2=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java Sat Feb 28 15:52:32 2015 @@ -21,14 +21,15 @@ import java.io.IOException; /** * This class represents a PDF object. * - * @author <a href="mailto:b...@benlitchfield.com">Ben Litchfield</a> - * @version $Revision: 1.37 $ + * @author Ben Litchfield + * */ -public class COSObject extends COSBase +public class COSObject extends COSBase implements COSUpdateInfo { private COSBase baseObject; private COSInteger objectNumber; private COSInteger generationNumber; + private boolean needToBeUpdated; /** * Constructor. @@ -155,4 +156,27 @@ public class COSObject extends COSBase { return getObject() != null ? getObject().accept( visitor ) : COSNull.NULL.accept( visitor ); } + + /** + * Get the update state for the COSWriter. + * + * @return the update state. + */ + @Override + public boolean isNeedToBeUpdated() + { + return needToBeUpdated; + } + + /** + * Set the update state of the dictionary for the COSWriter. + * + * @param flag the update state. + */ + @Override + public void setNeedToBeUpdated(boolean flag) + { + needToBeUpdated = flag; + } + } Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java?rev=1662951&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java Sat Feb 28 15:52:32 2015 @@ -0,0 +1,35 @@ +/* + * 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 COSUpdateInfo +{ + /** + * Get the update state for the COSWriter. + * + * @return the update state. + */ + public abstract boolean isNeedToBeUpdated(); + + /** + * Set the update state of the dictionary for the COSWriter. + * + * @param flag the update state. + */ + public abstract void setNeedToBeUpdated(boolean flag); + +} \ No newline at end of file Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSUpdateInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java?rev=1662951&r1=1662950&r2=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java Sat Feb 28 15:52:32 2015 @@ -25,6 +25,7 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSObject; +import org.apache.pdfbox.cos.COSUpdateInfo; import org.apache.pdfbox.pdfwriter.COSWriter; import org.apache.pdfbox.cos.COSObjectKey; @@ -209,9 +210,9 @@ public class VisualSignatureParser exten endObjectKey = readString(); } COSObject pdfObject = document.getObjectFromPool(key); - if (pb instanceof COSDictionary) + if (pb instanceof COSUpdateInfo) { - ((COSDictionary) pb).setNeedToBeUpdated(true); + ((COSUpdateInfo) pb).setNeedToBeUpdated(true); } pdfObject.setObject(pb); Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1662951&r1=1662950&r2=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Sat Feb 28 15:52:32 2015 @@ -55,6 +55,7 @@ import org.apache.pdfbox.cos.COSNumber; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.cos.COSString; +import org.apache.pdfbox.cos.COSUpdateInfo; import org.apache.pdfbox.cos.ICOSVisitor; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdfparser.PDFXRefStream; @@ -484,17 +485,12 @@ public class COSWriter implements ICOSVi { cosBase = keyObject.get(cosObjectKey); } - - if (actual != null && objectKeys.containsKey(actual) - && object instanceof COSDictionary - && cosBase instanceof COSDictionary - && !((COSDictionary) object).isNeedToBeUpdated() - && !((COSDictionary) cosBase).isNeedToBeUpdated()) + if (actual != null && objectKeys.containsKey(actual) + && object instanceof COSUpdateInfo && !((COSUpdateInfo)object).isNeedToBeUpdated() + && cosBase instanceof COSUpdateInfo && !((COSUpdateInfo)cosBase).isNeedToBeUpdated() ) { return; - } - objectsToWrite.add( object ); objectsToWriteSet.add( object ); if( actual != null ) Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1662951&r1=1662950&r2=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sat Feb 28 15:52:32 2015 @@ -38,6 +38,7 @@ import org.apache.pdfbox.cos.COSInteger; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.cos.COSUpdateInfo; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; import org.apache.pdfbox.pdfparser.BaseParser; @@ -264,7 +265,7 @@ public class PDDocument implements Close && ((PDSignatureField) field).getCOSObject().equals(signatureField.getCOSObject())) { checkFields = true; - ((COSDictionary) signatureField.getCOSObject()).setNeedToBeUpdated(true); + signatureField.getDictionary().setNeedToBeUpdated(true); break; } } @@ -371,7 +372,7 @@ public class PDDocument implements Close { annotations.add(signatureField.getWidget()); } - ((COSDictionary) page.getCOSObject()).setNeedToBeUpdated(true); + ((COSUpdateInfo)page.getCOSObject()).setNeedToBeUpdated(true); } /** @@ -386,7 +387,7 @@ public class PDDocument implements Close SignatureOptions options) throws IOException { PDDocumentCatalog catalog = getDocumentCatalog(); - ((COSDictionary) catalog.getCOSObject()).setNeedToBeUpdated(true); + ((COSUpdateInfo) catalog.getCOSObject()).setNeedToBeUpdated(true); PDAcroForm acroForm = catalog.getAcroForm(); if (acroForm == null) @@ -394,11 +395,6 @@ public class PDDocument implements Close acroForm = new PDAcroForm(this); catalog.setAcroForm(acroForm); } - else - { - ((COSDictionary) acroForm.getCOSObject()).setNeedToBeUpdated(true); - } - COSDictionary acroFormDict = acroForm.getDictionary(); acroFormDict.setDirect(true); acroFormDict.setNeedToBeUpdated(true); @@ -412,9 +408,7 @@ public class PDDocument implements Close for (PDSignatureField sigField : sigFields) { - PDSignature sigObject = sigField.getSignature(); - ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true); - + sigField.getDictionary().setNeedToBeUpdated(true); // Check if the field already exists boolean checkFields = false; for (PDFieldTreeNode fieldNode : field) @@ -423,7 +417,7 @@ public class PDDocument implements Close && fieldNode.getCOSObject().equals(sigField.getCOSObject())) { checkFields = true; - ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true); + sigField.getDictionary().setNeedToBeUpdated(true); break; } } @@ -436,10 +430,10 @@ public class PDDocument implements Close // Check if we need to add a signature if (sigField.getSignature() != null) { - ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true); + sigField.getDictionary().setNeedToBeUpdated(true); if (options == null) { - + // TODO ?? } addSignature(sigField.getSignature(), signatureInterface, options); } Copied: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSUpdateInfo.java (from r1662310, pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java) URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSUpdateInfo.java?p2=pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSUpdateInfo.java&p1=pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java&r1=1662310&r2=1662951&rev=1662951&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java (original) +++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSUpdateInfo.java Sat Feb 28 15:52:32 2015 @@ -19,28 +19,45 @@ package org.apache.pdfbox.cos; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import java.io.IOException; import org.junit.Test; /** - * Test class for {@link COSDictionary}. + * Test class for {@link COSUpdateInfo}. */ -public class TestCOSDictionary +public class TestCOSUpdateInfo { - /** The COSDictionary abstraction of the object being tested. */ - protected COSDictionary testCOSDictionary = new COSDictionary();; - /** * Tests isNeedToBeUpdate() and setNeedToBeUpdate() - tests the getter/setter methods. */ @Test public void testIsSetNeedToBeUpdate() { + // COSDictionary + COSUpdateInfo testCOSDictionary = new COSDictionary(); testCOSDictionary.setNeedToBeUpdated(true); assertTrue(testCOSDictionary.isNeedToBeUpdated()); testCOSDictionary.setNeedToBeUpdated(false); assertFalse(testCOSDictionary.isNeedToBeUpdated()); + + // COSObject + COSUpdateInfo testCOSObject; + try + { + testCOSObject = new COSObject(null); + testCOSObject.setNeedToBeUpdated(true); + assertTrue(testCOSObject.isNeedToBeUpdated()); + testCOSObject.setNeedToBeUpdated(false); + assertFalse(testCOSObject.isNeedToBeUpdated()); + } + catch (IOException e) + { + fail(e.getMessage()); + } } }