KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > fdf > FDFPage


1 /**
2  * Copyright (c) 2004, 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.fdf;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
35
36 import org.pdfbox.cos.COSArray;
37 import org.pdfbox.cos.COSBase;
38 import org.pdfbox.cos.COSDictionary;
39
40 import org.pdfbox.pdmodel.common.COSArrayList;
41 import org.pdfbox.pdmodel.common.COSObjectable;
42
43 /**
44  * This represents an FDF page that is part of the FDF document.
45  *
46  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
47  * @version $Revision: 1.3 $
48  */

49 public class FDFPage implements COSObjectable
50 {
51     private COSDictionary page;
52
53     /**
54      * Default constructor.
55      */

56     public FDFPage()
57     {
58         page = new COSDictionary();
59     }
60
61     /**
62      * Constructor.
63      *
64      * @param p The FDF page.
65      */

66     public FDFPage( COSDictionary p )
67     {
68         page = p;
69     }
70
71     /**
72      * Convert this standard java object to a COS object.
73      *
74      * @return The cos object that matches this Java object.
75      */

76     public COSBase getCOSObject()
77     {
78         return page;
79     }
80
81     /**
82      * Convert this standard java object to a COS object.
83      *
84      * @return The cos object that matches this Java object.
85      */

86     public COSDictionary getCOSDictionary()
87     {
88         return page;
89     }
90
91     /**
92      * This will get a list of FDFTemplage objects that describe the named pages
93      * that serve as templates.
94      *
95      * @return A list of templates.
96      */

97     public List JavaDoc getTemplates()
98     {
99         List JavaDoc retval = null;
100         COSArray array = (COSArray)page.getDictionaryObject( "Templates" );
101         if( array != null )
102         {
103             List JavaDoc objects = new ArrayList JavaDoc();
104             for( int i=0; i<array.size(); i++ )
105             {
106                 objects.add( new FDFTemplate( (COSDictionary)array.getObject( i ) ) );
107             }
108             retval = new COSArrayList( objects, array );
109         }
110         return retval;
111     }
112
113     /**
114      * A list of FDFTemplate objects.
115      *
116      * @param templates A list of templates for this Page.
117      */

118     public void setTemplates( List JavaDoc templates )
119     {
120         page.setItem( "Templates", COSArrayList.converterToCOSArray( templates ) );
121     }
122
123     /**
124      * This will get the FDF page info object.
125      *
126      * @return The Page info.
127      */

128     public FDFPageInfo getPageInfo()
129     {
130         FDFPageInfo retval = null;
131         COSDictionary dict = (COSDictionary)page.getDictionaryObject( "Info" );
132         if( dict != null )
133         {
134             retval = new FDFPageInfo( dict );
135         }
136         return retval;
137     }
138
139     /**
140      * This will set the page info.
141      *
142      * @param info The new page info dictionary.
143      */

144     public void setPageInfo( FDFPageInfo info )
145     {
146         page.setItem( "Info", info );
147     }
148 }
Popular Tags