KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 template that is part of the FDF page.
45  *
46  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
47  * @version $Revision: 1.3 $
48  */

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

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

66     public FDFTemplate( COSDictionary t )
67     {
68         template = t;
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 template;
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 template;
89     }
90
91     /**
92      * This is the template reference.
93      *
94      * @return The template reference.
95      */

96     public FDFNamedPageReference getTemplateReference()
97     {
98         FDFNamedPageReference retval = null;
99         COSDictionary dict = (COSDictionary)template.getDictionaryObject( "TRef" );
100         if( dict != null )
101         {
102             retval = new FDFNamedPageReference( dict );
103         }
104         return retval;
105     }
106
107     /**
108      * This will set the template reference.
109      *
110      * @param tRef The template reference.
111      */

112     public void setTemplateReference( FDFNamedPageReference tRef )
113     {
114         template.setItem( "TRef", tRef );
115     }
116
117     /**
118      * This will get a list of fields that are part of this template.
119      *
120      * @return A list of fields.
121      */

122     public List JavaDoc getFields()
123     {
124         List JavaDoc retval = null;
125         COSArray array = (COSArray)template.getDictionaryObject( "Fields" );
126         if( array != null )
127         {
128             List JavaDoc fields = new ArrayList JavaDoc();
129             for( int i=0; i<array.size(); i++ )
130             {
131                 fields.add( new FDFField( (COSDictionary)array.getObject( i ) ) );
132             }
133             retval = new COSArrayList( fields, array );
134         }
135         return retval;
136     }
137
138     /**
139      * This will set a list of fields for this template.
140      *
141      * @param fields The list of fields to set for this template.
142      */

143     public void setFields( List JavaDoc fields )
144     {
145         template.setItem( "Fields", COSArrayList.converterToCOSArray( fields ) );
146     }
147
148     /**
149      * A flag telling if the fields imported from the template may be renamed if there are conflicts.
150      *
151      * @return A flag telling if the fields can be renamed.
152      */

153     public boolean shouldRename()
154     {
155         return template.getBoolean( "Rename", false );
156     }
157
158     /**
159      * This will set if the fields can be renamed.
160      *
161      * @param value The flag value.
162      */

163     public void setRename( boolean value )
164     {
165         template.setBoolean( "Rename", value );
166     }
167 }
Popular Tags