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