]> _ Git - cubeextranet.git/blob
c6b1633a3efdd6165fa269fe899186e60a9550c5
[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.interactive.documentnavigation.destination;
18
19 import java.io.IOException;
20
21 import org.apache.pdfbox.cos.COSBase;
22 import org.apache.pdfbox.cos.COSName;
23 import org.apache.pdfbox.cos.COSString;
24
25 /**
26  * This represents a destination to a page by referencing it with a name.
27  *
28  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
29  * @version $Revision: 1.3 $
30  */
31 public class PDNamedDestination extends PDDestination
32 {
33     private COSBase namedDestination;
34
35     /**
36      * Constructor.
37      *
38      * @param dest The named destination.
39      */
40     public PDNamedDestination( COSString dest )
41     {
42         namedDestination = dest;
43     }
44
45     /**
46      * Constructor.
47      *
48      * @param dest The named destination.
49      */
50     public PDNamedDestination( COSName dest )
51     {
52         namedDestination = dest;
53     }
54
55     /**
56      * Default constructor.
57      */
58     public PDNamedDestination()
59     {
60         //default, so do nothing
61     }
62
63     /**
64      * Default constructor.
65      *
66      * @param dest The named destination.
67      */
68     public PDNamedDestination( String dest )
69     {
70         namedDestination = new COSString( dest );
71     }
72
73     /**
74      * Convert this standard java object to a COS object.
75      *
76      * @return The cos object that matches this Java object.
77      */
78     public COSBase getCOSObject()
79     {
80         return namedDestination;
81     }
82
83     /**
84      * This will get the name of the destination.
85      *
86      * @return The name of the destination.
87      */
88     public String getNamedDestination()
89     {
90         String retval = null;
91         if( namedDestination instanceof COSString )
92         {
93             retval = ((COSString)namedDestination).getString();
94         }
95         else if( namedDestination instanceof COSName )
96         {
97             retval = ((COSName)namedDestination).getName();
98         }
99
100         return retval;
101     }
102
103     /**
104      * Set the named destination.
105      *
106      * @param dest The new named destination.
107      *
108      * @throws IOException If there is an error setting the named destination.
109      */
110     public void setNamedDestination( String dest ) throws IOException
111     {
112         if( namedDestination instanceof COSString )
113         {
114             COSString string = ((COSString)namedDestination);
115             string.reset();
116             string.append( dest.getBytes("ISO-8859-1") );
117         }
118         else if( dest == null )
119         {
120             namedDestination = null;
121         }
122         else
123         {
124             namedDestination = new COSString( dest );
125         }
126     }
127
128 }