2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
19 import java.io.IOException;
21 import org.apache.pdfbox.cos.COSBase;
22 import org.apache.pdfbox.cos.COSDictionary;
23 import org.apache.pdfbox.cos.COSName;
24 import org.apache.pdfbox.pdmodel.common.COSObjectable;
25 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
26 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
29 * An object reference.
31 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
32 * @version $Revision: $
34 public class PDObjectReference implements COSObjectable
37 public static final String TYPE = "OBJR";
39 private COSDictionary dictionary;
41 protected COSDictionary getCOSDictionary()
43 return this.dictionary;
47 * Default Constructor.
50 public PDObjectReference()
52 this.dictionary = new COSDictionary();
53 this.dictionary.setName(COSName.TYPE, TYPE);
57 * Constructor for an existing object reference.
59 * @param dictionary The existing dictionary.
61 public PDObjectReference(COSDictionary dictionary)
63 this.dictionary = dictionary;
69 public COSBase getCOSObject()
71 return this.dictionary;
75 * Gets a higher-level object for the referenced object.
76 * Currently this method may return a {@link PDAnnotation},
77 * a {@link PDXObject} or <code>null</code>.
79 * @return a higher-level object for the referenced object
81 public COSObjectable getReferencedObject()
83 COSBase obj = this.getCOSDictionary().getDictionaryObject(COSName.OBJ);
86 return PDAnnotation.createAnnotation(obj);
93 return PDXObject.createXObject(obj);
95 catch (IOException e1)
98 // TODO what else can be the target of the object reference?
105 * Sets the referenced annotation.
107 * @param annotation the referenced annotation
109 public void setReferencedObject(PDAnnotation annotation)
111 this.getCOSDictionary().setItem(COSName.OBJ, annotation);
115 * Sets the referenced XObject.
117 * @param xobject the referenced XObject
119 public void setReferencedObject(PDXObject xobject)
121 this.getCOSDictionary().setItem(COSName.OBJ, xobject);