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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination;
\r
19 import java.io.IOException;
\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
26 * This represents a destination to a page by referencing it with a name.
\r
28 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
\r
29 * @version $Revision: 1.3 $
\r
31 public class PDNamedDestination extends PDDestination
\r
33 private COSBase namedDestination;
\r
38 * @param dest The named destination.
\r
40 public PDNamedDestination( COSString dest )
\r
42 namedDestination = dest;
\r
48 * @param dest The named destination.
\r
50 public PDNamedDestination( COSName dest )
\r
52 namedDestination = dest;
\r
56 * Default constructor.
\r
58 public PDNamedDestination()
\r
60 //default, so do nothing
\r
64 * Default constructor.
\r
66 * @param dest The named destination.
\r
68 public PDNamedDestination( String dest )
\r
70 namedDestination = new COSString( dest );
\r
74 * Convert this standard java object to a COS object.
\r
76 * @return The cos object that matches this Java object.
\r
78 public COSBase getCOSObject()
\r
80 return namedDestination;
\r
84 * This will get the name of the destination.
\r
86 * @return The name of the destination.
\r
88 public String getNamedDestination()
\r
90 String retval = null;
\r
91 if( namedDestination instanceof COSString )
\r
93 retval = ((COSString)namedDestination).getString();
\r
95 else if( namedDestination instanceof COSName )
\r
97 retval = ((COSName)namedDestination).getName();
\r
104 * Set the named destination.
\r
106 * @param dest The new named destination.
\r
108 * @throws IOException If there is an error setting the named destination.
\r
110 public void setNamedDestination( String dest ) throws IOException
\r
112 if( namedDestination instanceof COSString )
\r
114 COSString string = ((COSString)namedDestination);
\r
116 string.append( dest.getBytes("ISO-8859-1") );
\r
118 else if( dest == null )
\r
120 namedDestination = null;
\r
124 namedDestination = new COSString( dest );
\r