]> _ Git - cubeextranet.git/blob
ee9c73f91263fd385a04ad3f494850eac856af2e
[cubeextranet.git] /
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
18
19 import java.io.IOException;
20
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;
27
28 /**
29  * An object reference.
30  * 
31  * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
32  * @version $Revision: $
33  */
34 public class PDObjectReference implements COSObjectable
35 {
36
37     public static final String TYPE = "OBJR";
38
39     private COSDictionary dictionary;
40
41     protected COSDictionary getCOSDictionary()
42     {
43         return this.dictionary;
44     }
45
46     /**
47      * Default Constructor.
48      *
49      */
50     public PDObjectReference()
51     {
52         this.dictionary = new COSDictionary();
53         this.dictionary.setName(COSName.TYPE, TYPE);
54     }
55
56     /**
57      * Constructor for an existing object reference.
58      *
59      * @param dictionary The existing dictionary.
60      */
61     public PDObjectReference(COSDictionary dictionary)
62     {
63         this.dictionary = dictionary;
64     }
65
66     /**
67      * {@inheritDoc}
68      */
69     public COSBase getCOSObject()
70     {
71         return this.dictionary;
72     }
73
74     /**
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>.
78      * 
79      * @return a higher-level object for the referenced object
80      */
81     public COSObjectable getReferencedObject()
82     {
83         COSBase obj = this.getCOSDictionary().getDictionaryObject(COSName.OBJ);
84         try
85         {
86             return PDAnnotation.createAnnotation(obj);
87         }
88         catch (IOException e)
89         {
90             // No Annotation
91             try
92             {
93                 return PDXObject.createXObject(obj);
94             }
95             catch (IOException e1)
96             {
97                 // No XObject
98                 // TODO what else can be the target of the object reference?
99             }
100         }
101         return null;
102     }
103
104     /**
105      * Sets the referenced annotation.
106      * 
107      * @param annotation the referenced annotation
108      */
109     public void setReferencedObject(PDAnnotation annotation)
110     {
111         this.getCOSDictionary().setItem(COSName.OBJ, annotation);
112     }
113
114     /**
115      * Sets the referenced XObject.
116      * 
117      * @param xobject the referenced XObject
118      */
119     public void setReferencedObject(PDXObject xobject)
120     {
121         this.getCOSDictionary().setItem(COSName.OBJ, xobject);
122     }
123
124 }