]> _ Git - cubeextranet.git/blob
9ff99fce52217aeeafec67646b9e98d2b23c3e3b
[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.COSArray;
22 import org.apache.pdfbox.cos.COSBase;
23 import org.apache.pdfbox.cos.COSName;
24 import org.apache.pdfbox.cos.COSString;
25
26 import org.apache.pdfbox.pdmodel.common.PDDestinationOrAction;
27
28 /**
29  * This represents a destination in a PDF document.
30  *
31  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
32  * @version $Revision: 1.6 $
33  */
34 public abstract class PDDestination implements PDDestinationOrAction
35 {
36
37     /**
38      * This will create a new destination depending on the type of COSBase
39      * that is passed in.
40      *
41      * @param base The base level object.
42      *
43      * @return A new destination.
44      *
45      * @throws IOException If the base cannot be converted to a Destination.
46      */
47     public static PDDestination create( COSBase base ) throws IOException
48     {
49         PDDestination retval = null;
50         if( base == null )
51         {
52             //this is ok, just return null.
53         }
54         else if( base instanceof COSArray && ((COSArray)base).size() > 0 )
55         {
56             COSArray array = (COSArray)base;
57             COSName type = (COSName)array.getObject( 1 );
58             String typeString = type.getName();
59             if( typeString.equals( PDPageFitDestination.TYPE ) ||
60                 typeString.equals( PDPageFitDestination.TYPE_BOUNDED ))
61             {
62                 retval = new PDPageFitDestination( array );
63             }
64             else if( typeString.equals( PDPageFitHeightDestination.TYPE ) ||
65                      typeString.equals( PDPageFitHeightDestination.TYPE_BOUNDED ))
66             {
67                 retval = new PDPageFitHeightDestination( array );
68             }
69             else if( typeString.equals( PDPageFitRectangleDestination.TYPE ) )
70             {
71                 retval = new PDPageFitRectangleDestination( array );
72             }
73             else if( typeString.equals( PDPageFitWidthDestination.TYPE ) ||
74                      typeString.equals( PDPageFitWidthDestination.TYPE_BOUNDED ))
75             {
76                 retval = new PDPageFitWidthDestination( array );
77             }
78             else if( typeString.equals( PDPageXYZDestination.TYPE ) )
79             {
80                 retval = new PDPageXYZDestination( array );
81             }
82             else
83             {
84                 throw new IOException( "Unknown destination type:" + type );
85             }
86         }
87         else if( base instanceof COSString )
88         {
89             retval = new PDNamedDestination( (COSString)base );
90         }
91         else if( base instanceof COSName )
92         {
93             retval = new PDNamedDestination( (COSName)base );
94         }
95         else
96         {
97             throw new IOException( "Error: can't convert to Destination " + base );
98         }
99         return retval;
100     }
101
102     /**
103      * Return a string representation of this class.
104      *
105      * @return A human readable string.
106      */
107     public String toString()
108     {
109         return super.toString();
110     }
111 }