KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > interactive > documentnavigation > destination > PDDestination


1 /**
2  * Copyright (c) 2004-2005, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.interactive.documentnavigation.destination;
32
33 import java.io.IOException JavaDoc;
34
35 import org.pdfbox.cos.COSArray;
36 import org.pdfbox.cos.COSBase;
37 import org.pdfbox.cos.COSName;
38 import org.pdfbox.cos.COSString;
39
40 import org.pdfbox.pdmodel.common.PDDestinationOrAction;
41
42 /**
43  * This represents a destination in a PDF document.
44  *
45  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
46  * @version $Revision: 1.6 $
47  */

48 public abstract class PDDestination implements PDDestinationOrAction
49 {
50     
51     /**
52      * This will create a new destination depending on the type of COSBase
53      * that is passed in.
54      *
55      * @param base The base level object.
56      *
57      * @return A new destination.
58      *
59      * @throws IOException If the base cannot be converted to a Destination.
60      */

61     public static PDDestination create( COSBase base ) throws IOException JavaDoc
62     {
63         PDDestination retval = null;
64         if( base == null )
65         {
66             //this is ok, just return null.
67
}
68         else if( base instanceof COSArray && ((COSArray)base).size() > 0 )
69         {
70             COSArray array = (COSArray)base;
71             COSName type = (COSName)array.getObject( 1 );
72             String JavaDoc typeString = type.getName();
73             if( typeString.equals( PDPageFitDestination.TYPE ) ||
74                 typeString.equals( PDPageFitDestination.TYPE_BOUNDED ))
75             {
76                 retval = new PDPageFitDestination( array );
77             }
78             else if( typeString.equals( PDPageFitHeightDestination.TYPE ) ||
79                      typeString.equals( PDPageFitHeightDestination.TYPE_BOUNDED ))
80             {
81                 retval = new PDPageFitHeightDestination( array );
82             }
83             else if( typeString.equals( PDPageFitRectangleDestination.TYPE ) )
84             {
85                 retval = new PDPageFitRectangleDestination( array );
86             }
87             else if( typeString.equals( PDPageFitWidthDestination.TYPE ) ||
88                      typeString.equals( PDPageFitWidthDestination.TYPE_BOUNDED ))
89             {
90                 retval = new PDPageFitWidthDestination( array );
91             }
92             else if( typeString.equals( PDPageXYZDestination.TYPE ) )
93             {
94                 retval = new PDPageXYZDestination( array );
95             }
96             else
97             {
98                 throw new IOException JavaDoc( "Unknown destination type:" + type );
99             }
100         }
101         else if( base instanceof COSString )
102         {
103             retval = new PDNamedDestination( (COSString)base );
104         }
105         else if( base instanceof COSName )
106         {
107             retval = new PDNamedDestination( (COSName)base );
108         }
109         else
110         {
111             throw new IOException JavaDoc( "Error: can't convert to Destination " + base );
112         }
113         return retval;
114     }
115     
116     /**
117      * Return a string representation of this class.
118      *
119      * @return A human readable string.
120      */

121     public String JavaDoc toString()
122     {
123         return super.toString();
124     }
125 }
126
Popular Tags