001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.fdf;
031:
032: import java.io.IOException;
033: import java.io.Writer;
034:
035: import org.pdfbox.cos.COSBase;
036: import org.pdfbox.cos.COSDictionary;
037:
038: import org.pdfbox.pdmodel.common.COSObjectable;
039:
040: import org.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
041:
042: import org.w3c.dom.Element;
043:
044: /**
045: * This represents an FDF catalog that is part of the FDF document.
046: *
047: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
048: * @version $Revision: 1.3 $
049: */
050: public class FDFCatalog implements COSObjectable {
051: private COSDictionary catalog;
052:
053: /**
054: * Default constructor.
055: */
056: public FDFCatalog() {
057: catalog = new COSDictionary();
058: }
059:
060: /**
061: * Constructor.
062: *
063: * @param cat The FDF documents catalog.
064: */
065: public FDFCatalog(COSDictionary cat) {
066: catalog = cat;
067: }
068:
069: /**
070: * This will create an FDF catalog from an XFDF XML document.
071: *
072: * @param element The XML document that contains the XFDF data.
073: * @throws IOException If there is an error reading from the dom.
074: */
075: public FDFCatalog(Element element) throws IOException {
076: this ();
077: FDFDictionary fdfDict = new FDFDictionary(element);
078: setFDF(fdfDict);
079: }
080:
081: /**
082: * This will write this element as an XML document.
083: *
084: * @param output The stream to write the xml to.
085: *
086: * @throws IOException If there is an error writing the XML.
087: */
088: public void writeXML(Writer output) throws IOException {
089: FDFDictionary fdf = getFDF();
090: fdf.writeXML(output);
091: }
092:
093: /**
094: * Convert this standard java object to a COS object.
095: *
096: * @return The cos object that matches this Java object.
097: */
098: public COSBase getCOSObject() {
099: return catalog;
100: }
101:
102: /**
103: * Convert this standard java object to a COS object.
104: *
105: * @return The cos object that matches this Java object.
106: */
107: public COSDictionary getCOSDictionary() {
108: return catalog;
109: }
110:
111: /**
112: * This will get the version that was specified in the catalog dictionary.
113: *
114: * @return The FDF version.
115: */
116: public String getVersion() {
117: return catalog.getNameAsString("Version");
118: }
119:
120: /**
121: * This will set the version of the FDF document.
122: *
123: * @param version The new version for the FDF document.
124: */
125: public void setVersion(String version) {
126: catalog.setName("Version", version);
127: }
128:
129: /**
130: * This will get the FDF dictionary.
131: *
132: * @return The FDF dictionary.
133: */
134: public FDFDictionary getFDF() {
135: COSDictionary fdf = (COSDictionary) catalog
136: .getDictionaryObject("FDF");
137: FDFDictionary retval = null;
138: if (fdf != null) {
139: retval = new FDFDictionary(fdf);
140: } else {
141: retval = new FDFDictionary();
142: setFDF(retval);
143: }
144: return retval;
145: }
146:
147: /**
148: * This will set the FDF document.
149: *
150: * @param fdf The new FDF dictionary.
151: */
152: public void setFDF(FDFDictionary fdf) {
153: catalog.setItem("FDF", fdf);
154: }
155:
156: /**
157: * This will get the signature or null if there is none.
158: *
159: * @return The signature.
160: */
161: public PDSignature getSignature() {
162: PDSignature signature = null;
163: COSDictionary sig = (COSDictionary) catalog
164: .getDictionaryObject("Sig");
165: if (sig != null) {
166: signature = new PDSignature(sig);
167: }
168: return signature;
169: }
170:
171: /**
172: * This will set the signature that is associated with this catalog.
173: *
174: * @param sig The new signature.
175: */
176: public void setSignature(PDSignature sig) {
177: catalog.setItem("Sig", sig);
178: }
179: }
|