]> _ Git - cubeextranet.git/blob
d421b35098831545e08cc9ff4d07e4a731c829ed
[cubeextranet.git] /
1 /*\r
2  * Licensed to the Apache Software Foundation (ASF) under one or more\r
3  * contributor license agreements.  See the NOTICE file distributed with\r
4  * this work for additional information regarding copyright ownership.\r
5  * The ASF licenses this file to You under the Apache License, Version 2.0\r
6  * (the "License"); you may not use this file except in compliance with\r
7  * the License.  You may obtain a copy of the License at\r
8  *\r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 package org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination;\r
18 \r
19 import java.io.IOException;\r
20 \r
21 import org.apache.pdfbox.cos.COSBase;\r
22 import org.apache.pdfbox.cos.COSName;\r
23 import org.apache.pdfbox.cos.COSString;\r
24 \r
25 /**\r
26  * This represents a destination to a page by referencing it with a name.\r
27  *\r
28  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>\r
29  * @version $Revision: 1.3 $\r
30  */\r
31 public class PDNamedDestination extends PDDestination\r
32 {\r
33     private COSBase namedDestination;\r
34 \r
35     /**\r
36      * Constructor.\r
37      *\r
38      * @param dest The named destination.\r
39      */\r
40     public PDNamedDestination( COSString dest )\r
41     {\r
42         namedDestination = dest;\r
43     }\r
44 \r
45     /**\r
46      * Constructor.\r
47      *\r
48      * @param dest The named destination.\r
49      */\r
50     public PDNamedDestination( COSName dest )\r
51     {\r
52         namedDestination = dest;\r
53     }\r
54 \r
55     /**\r
56      * Default constructor.\r
57      */\r
58     public PDNamedDestination()\r
59     {\r
60         //default, so do nothing\r
61     }\r
62 \r
63     /**\r
64      * Default constructor.\r
65      *\r
66      * @param dest The named destination.\r
67      */\r
68     public PDNamedDestination( String dest )\r
69     {\r
70         namedDestination = new COSString( dest );\r
71     }\r
72 \r
73     /**\r
74      * Convert this standard java object to a COS object.\r
75      *\r
76      * @return The cos object that matches this Java object.\r
77      */\r
78     public COSBase getCOSObject()\r
79     {\r
80         return namedDestination;\r
81     }\r
82 \r
83     /**\r
84      * This will get the name of the destination.\r
85      *\r
86      * @return The name of the destination.\r
87      */\r
88     public String getNamedDestination()\r
89     {\r
90         String retval = null;\r
91         if( namedDestination instanceof COSString )\r
92         {\r
93             retval = ((COSString)namedDestination).getString();\r
94         }\r
95         else if( namedDestination instanceof COSName )\r
96         {\r
97             retval = ((COSName)namedDestination).getName();\r
98         }\r
99 \r
100         return retval;\r
101     }\r
102 \r
103     /**\r
104      * Set the named destination.\r
105      *\r
106      * @param dest The new named destination.\r
107      *\r
108      * @throws IOException If there is an error setting the named destination.\r
109      */\r
110     public void setNamedDestination( String dest ) throws IOException\r
111     {\r
112         if( namedDestination instanceof COSString )\r
113         {\r
114             COSString string = ((COSString)namedDestination);\r
115             string.reset();\r
116             string.append( dest.getBytes("ISO-8859-1") );\r
117         }\r
118         else if( dest == null )\r
119         {\r
120             namedDestination = null;\r
121         }\r
122         else\r
123         {\r
124             namedDestination = new COSString( dest );\r
125         }\r
126     }\r
127 \r
128 }\r