/** * Copyright (c) 2003, www.pdfbox.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of pdfbox; nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * http://www.pdfbox.org * */ package org.pdfbox.cos; import org.pdfbox.exceptions.COSVisitorException; import java.io.IOException; import org.apache.log4j.Logger; /** * This class represents a PDF object. * * @author Ben Litchfield (ben@csh.rit.edu) * @version $Revision: 1.35 $ */ public class COSObject extends COSBase { private static Logger log = Logger.getLogger(COSObject.class); private COSBase baseObject; private COSInteger objectNumber; private COSInteger generationNumber; /** * Constructor. * * @param object The object that this encapsulates. * * @throws IOException If there is an error with the object passed in. */ public COSObject( COSBase object ) throws IOException { setObject( object ); } /** * 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. * * @param key The key to the value that we are searching for. * * @return The pdf object that matches the key. */ public COSBase getDictionaryObject( COSName key ) { COSBase retval =null; if( baseObject instanceof COSDictionary ) { retval = ((COSDictionary)baseObject).getDictionaryObject( key ); } return retval; } /** * This will get the dictionary object in this object that has the name key. * * @param key The key to the value that we are searching for. * * @return The pdf object that matches the key. */ public COSBase getItem( COSName key ) { COSBase retval =null; if( baseObject instanceof COSDictionary ) { retval = ((COSDictionary)baseObject).getItem( key ); } return retval; } /** * This will get the object that this object encapsulates. * * @return The encapsulated object. */ public COSBase getObject() { return baseObject; } /** * This will set the object that this object encapsulates. * * @param object The new object to encapsulate. * * @throws IOException If there is an error setting the updated object. */ public void setObject( COSBase object ) throws IOException { baseObject = object; /*if( baseObject == null ) { baseObject = object; } else { //This is for when an object appears twice in the //pdf file we really want to replace it such that //object references still work correctly. //see owcp-as-received.pdf for an example if( baseObject instanceof COSDictionary ) { COSDictionary dic = (COSDictionary)baseObject; COSDictionary dicObject = (COSDictionary)object; dic.clear(); dic.addAll( dicObject ); } else if( baseObject instanceof COSArray ) { COSArray array = (COSArray)baseObject; COSArray arrObject = (COSArray)object; array.clear(); for( int i=0; i