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