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.util.ArrayList;
033: import java.util.List;
034:
035: import org.pdfbox.cos.COSArray;
036: import org.pdfbox.cos.COSBase;
037: import org.pdfbox.cos.COSDictionary;
038:
039: import org.pdfbox.pdmodel.common.COSArrayList;
040: import org.pdfbox.pdmodel.common.COSObjectable;
041:
042: /**
043: * This represents an FDF page that is part of the FDF document.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.3 $
047: */
048: public class FDFPage implements COSObjectable {
049: private COSDictionary page;
050:
051: /**
052: * Default constructor.
053: */
054: public FDFPage() {
055: page = new COSDictionary();
056: }
057:
058: /**
059: * Constructor.
060: *
061: * @param p The FDF page.
062: */
063: public FDFPage(COSDictionary p) {
064: page = p;
065: }
066:
067: /**
068: * Convert this standard java object to a COS object.
069: *
070: * @return The cos object that matches this Java object.
071: */
072: public COSBase getCOSObject() {
073: return page;
074: }
075:
076: /**
077: * Convert this standard java object to a COS object.
078: *
079: * @return The cos object that matches this Java object.
080: */
081: public COSDictionary getCOSDictionary() {
082: return page;
083: }
084:
085: /**
086: * This will get a list of FDFTemplage objects that describe the named pages
087: * that serve as templates.
088: *
089: * @return A list of templates.
090: */
091: public List getTemplates() {
092: List retval = null;
093: COSArray array = (COSArray) page
094: .getDictionaryObject("Templates");
095: if (array != null) {
096: List objects = new ArrayList();
097: for (int i = 0; i < array.size(); i++) {
098: objects.add(new FDFTemplate((COSDictionary) array
099: .getObject(i)));
100: }
101: retval = new COSArrayList(objects, array);
102: }
103: return retval;
104: }
105:
106: /**
107: * A list of FDFTemplate objects.
108: *
109: * @param templates A list of templates for this Page.
110: */
111: public void setTemplates(List templates) {
112: page.setItem("Templates", COSArrayList
113: .converterToCOSArray(templates));
114: }
115:
116: /**
117: * This will get the FDF page info object.
118: *
119: * @return The Page info.
120: */
121: public FDFPageInfo getPageInfo() {
122: FDFPageInfo retval = null;
123: COSDictionary dict = (COSDictionary) page
124: .getDictionaryObject("Info");
125: if (dict != null) {
126: retval = new FDFPageInfo(dict);
127: }
128: return retval;
129: }
130:
131: /**
132: * This will set the page info.
133: *
134: * @param info The new page info dictionary.
135: */
136: public void setPageInfo(FDFPageInfo info) {
137: page.setItem("Info", info);
138: }
139: }
|