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.COSArray;
\r
22 import org.apache.pdfbox.cos.COSBase;
\r
23 import org.apache.pdfbox.cos.COSName;
\r
24 import org.apache.pdfbox.cos.COSString;
\r
26 import org.apache.pdfbox.pdmodel.common.PDDestinationOrAction;
\r
29 * This represents a destination in a PDF document.
\r
31 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
\r
32 * @version $Revision: 1.6 $
\r
34 public abstract class PDDestination implements PDDestinationOrAction
\r
38 * This will create a new destination depending on the type of COSBase
\r
39 * that is passed in.
\r
41 * @param base The base level object.
\r
43 * @return A new destination.
\r
45 * @throws IOException If the base cannot be converted to a Destination.
\r
47 public static PDDestination create( COSBase base ) throws IOException
\r
49 PDDestination retval = null;
\r
52 //this is ok, just return null.
\r
54 else if( base instanceof COSArray && ((COSArray)base).size() > 0 )
\r
56 COSArray array = (COSArray)base;
\r
57 COSName type = (COSName)array.getObject( 1 );
\r
58 String typeString = type.getName();
\r
59 if( typeString.equals( PDPageFitDestination.TYPE ) ||
\r
60 typeString.equals( PDPageFitDestination.TYPE_BOUNDED ))
\r
62 retval = new PDPageFitDestination( array );
\r
64 else if( typeString.equals( PDPageFitHeightDestination.TYPE ) ||
\r
65 typeString.equals( PDPageFitHeightDestination.TYPE_BOUNDED ))
\r
67 retval = new PDPageFitHeightDestination( array );
\r
69 else if( typeString.equals( PDPageFitRectangleDestination.TYPE ) )
\r
71 retval = new PDPageFitRectangleDestination( array );
\r
73 else if( typeString.equals( PDPageFitWidthDestination.TYPE ) ||
\r
74 typeString.equals( PDPageFitWidthDestination.TYPE_BOUNDED ))
\r
76 retval = new PDPageFitWidthDestination( array );
\r
78 else if( typeString.equals( PDPageXYZDestination.TYPE ) )
\r
80 retval = new PDPageXYZDestination( array );
\r
84 throw new IOException( "Unknown destination type:" + type );
\r
87 else if( base instanceof COSString )
\r
89 retval = new PDNamedDestination( (COSString)base );
\r
91 else if( base instanceof COSName )
\r
93 retval = new PDNamedDestination( (COSName)base );
\r
97 throw new IOException( "Error: can't convert to Destination " + base );
\r
103 * Return a string representation of this class.
\r
105 * @return A human readable string.
\r
107 public String toString()
\r
109 return super.toString();
\r