KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
34 import java.io.Writer JavaDoc;
35
36 import org.pdfbox.cos.COSBase;
37 import org.pdfbox.cos.COSDictionary;
38
39 import org.pdfbox.pdmodel.common.COSObjectable;
40
41 import org.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
42
43 import org.w3c.dom.Element JavaDoc;
44
45 /**
46  * This represents an FDF catalog that is part of the FDF document.
47  *
48  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
49  * @version $Revision: 1.3 $
50  */

51 public class FDFCatalog implements COSObjectable
52 {
53     private COSDictionary catalog;
54
55     /**
56      * Default constructor.
57      */

58     public FDFCatalog()
59     {
60         catalog = new COSDictionary();
61     }
62
63     /**
64      * Constructor.
65      *
66      * @param cat The FDF documents catalog.
67      */

68     public FDFCatalog( COSDictionary cat )
69     {
70         catalog = cat;
71     }
72     
73     /**
74      * This will create an FDF catalog from an XFDF XML document.
75      *
76      * @param element The XML document that contains the XFDF data.
77      * @throws IOException If there is an error reading from the dom.
78      */

79     public FDFCatalog( Element JavaDoc element ) throws IOException JavaDoc
80     {
81         this();
82         FDFDictionary fdfDict = new FDFDictionary( element );
83         setFDF( fdfDict );
84     }
85     
86     /**
87      * This will write this element as an XML document.
88      *
89      * @param output The stream to write the xml to.
90      *
91      * @throws IOException If there is an error writing the XML.
92      */

93     public void writeXML( Writer JavaDoc output ) throws IOException JavaDoc
94     {
95         FDFDictionary fdf = getFDF();
96         fdf.writeXML( output );
97     }
98
99     /**
100      * Convert this standard java object to a COS object.
101      *
102      * @return The cos object that matches this Java object.
103      */

104     public COSBase getCOSObject()
105     {
106         return catalog;
107     }
108
109     /**
110      * Convert this standard java object to a COS object.
111      *
112      * @return The cos object that matches this Java object.
113      */

114     public COSDictionary getCOSDictionary()
115     {
116         return catalog;
117     }
118
119     /**
120      * This will get the version that was specified in the catalog dictionary.
121      *
122      * @return The FDF version.
123      */

124     public String JavaDoc getVersion()
125     {
126         return catalog.getNameAsString( "Version" );
127     }
128
129     /**
130      * This will set the version of the FDF document.
131      *
132      * @param version The new version for the FDF document.
133      */

134     public void setVersion( String JavaDoc version )
135     {
136         catalog.setName( "Version", version );
137     }
138
139     /**
140      * This will get the FDF dictionary.
141      *
142      * @return The FDF dictionary.
143      */

144     public FDFDictionary getFDF()
145     {
146         COSDictionary fdf = (COSDictionary)catalog.getDictionaryObject( "FDF" );
147         FDFDictionary retval = null;
148         if( fdf != null )
149         {
150             retval = new FDFDictionary( fdf );
151         }
152         else
153         {
154             retval = new FDFDictionary();
155             setFDF( retval );
156         }
157         return retval;
158     }
159
160     /**
161      * This will set the FDF document.
162      *
163      * @param fdf The new FDF dictionary.
164      */

165     public void setFDF( FDFDictionary fdf )
166     {
167         catalog.setItem( "FDF", fdf );
168     }
169
170     /**
171      * This will get the signature or null if there is none.
172      *
173      * @return The signature.
174      */

175     public PDSignature getSignature()
176     {
177         PDSignature signature = null;
178         COSDictionary sig = (COSDictionary)catalog.getDictionaryObject( "Sig" );
179         if( sig != null )
180         {
181             signature = new PDSignature( sig );
182         }
183         return signature;
184     }
185
186     /**
187      * This will set the signature that is associated with this catalog.
188      *
189      * @param sig The new signature.
190      */

191     public void setSignature( PDSignature sig )
192     {
193         catalog.setItem( "Sig", sig );
194     }
195 }
Popular Tags