001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - 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: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.pd;
031:
032: import java.net.URL;
033: import java.util.ArrayList;
034: import java.util.Iterator;
035: import java.util.List;
036:
037: import de.intarsys.pdf.cos.COSArray;
038: import de.intarsys.pdf.cos.COSDictionary;
039: import de.intarsys.pdf.cos.COSInteger;
040: import de.intarsys.pdf.cos.COSName;
041: import de.intarsys.pdf.cos.COSObject;
042:
043: /**
044: * The SubmitForm action.
045: * <p>
046: * When executed the action submit the documents AcroForm acording to the
047: * defined flags.
048: *
049: */
050: public class PDActionSubmitForm extends PDAction {
051: /**
052: * The meta class implementation
053: */
054: static public class MetaClass extends PDAction.MetaClass {
055: protected MetaClass(Class instanceClass) {
056: super (instanceClass);
057: }
058: }
059:
060: /** The meta class instance */
061: static public final MetaClass META = new MetaClass(MetaClass.class
062: .getDeclaringClass());
063:
064: static public final COSName CN_ActionType_SubmitForm = COSName
065: .constant("SubmitForm");
066:
067: static public final COSName DK_F = COSName.constant("F");
068:
069: static public final COSName DK_Fields = COSName.constant("Fields");
070:
071: static public final COSName DK_Flags = COSName.constant("Flags");
072:
073: private SubmitFormFlags flags;
074:
075: protected PDActionSubmitForm(COSObject object) {
076: super (object);
077: }
078:
079: public COSName cosGetExpectedActionType() {
080: return CN_ActionType_SubmitForm;
081: }
082:
083: public void setCanonicalFormat(boolean flag) {
084: getFlags().setCanonicalFormat(flag);
085: }
086:
087: public boolean isCanonicalFormat() {
088: return getFlags().isCanonicalFormat();
089: }
090:
091: public void setEmbedForm(boolean flag) {
092: getFlags().setEmbedForm(flag);
093: }
094:
095: public boolean isEmbedForm() {
096: return getFlags().isEmbedForm();
097: }
098:
099: public void setExclFKey(boolean flag) {
100: getFlags().setExclFKey(flag);
101: }
102:
103: public boolean isExclFKey() {
104: return getFlags().isExclFKey();
105: }
106:
107: public void setExclNonUserAnnots(boolean flag) {
108: getFlags().setExclNonUserAnnots(flag);
109: }
110:
111: public boolean isExclNonUserAnnots() {
112: return getFlags().isExclNonUserAnnots();
113: }
114:
115: public void setExportFormat(boolean flag) {
116: getFlags().setExportFormat(flag);
117: }
118:
119: public boolean isExportFormat() {
120: return getFlags().isExportFormat();
121: }
122:
123: public void setGetMethod(boolean flag) {
124: getFlags().setGetMethod(flag);
125: }
126:
127: public boolean isGetMethod() {
128: return getFlags().isGetMethod();
129: }
130:
131: public void setInclude(boolean flag) {
132: getFlags().setInclude(flag);
133: }
134:
135: public boolean isInclude() {
136: return getFlags().isInclude();
137: }
138:
139: public void setIncludeAnnotations(boolean flag) {
140: getFlags().setIncludeAnnotations(flag);
141: }
142:
143: public boolean isIncludeAnnotations() {
144: return getFlags().isIncludeAnnotations();
145: }
146:
147: public void setIncludeAppendSaves(boolean flag) {
148: getFlags().setIncludeAppendSaves(flag);
149: }
150:
151: public boolean isIncludeAppendSaves() {
152: return getFlags().isIncludeAppendSaves();
153: }
154:
155: public void setIncludeNoValueFields(boolean flag) {
156: getFlags().setIncludeNoValueFields(flag);
157: }
158:
159: public boolean isIncludeNoValueFields() {
160: return getFlags().isIncludeNoValueFields();
161: }
162:
163: public void setNotDEFINED(boolean flag) {
164: getFlags().setNotDEFINED(flag);
165: }
166:
167: public boolean isNotDEFINED() {
168: return getFlags().isNotDEFINED();
169: }
170:
171: public void setSubmitCoordinates(boolean flag) {
172: getFlags().setSubmitCoordinates(flag);
173: }
174:
175: public boolean isSubmitCoordinates() {
176: return getFlags().isSubmitCoordinates();
177: }
178:
179: public void setSubmitPDF(boolean flag) {
180: getFlags().setSubmitPDF(flag);
181: }
182:
183: public boolean isSubmitPDF() {
184: return getFlags().isSubmitPDF();
185: }
186:
187: public void setUrl(URL url) {
188: if (url != null) {
189: setUrlSpecification(PDFileSpecificationURL.createNew(url));
190: } else {
191: setUrlSpecification(null);
192: }
193: }
194:
195: public URL getUrl() {
196: PDFileSpecification fs = getUrlSpecification();
197: if (fs != null) {
198: return ((PDFileSpecificationURL) fs).getURL();
199: }
200: return null;
201: }
202:
203: public void setXFDF(boolean flag) {
204: getFlags().setXFDF(flag);
205: }
206:
207: public boolean isXFDF() {
208: return getFlags().isXFDF();
209: }
210:
211: static public PDActionSubmitForm createNew(URL url) {
212: PDActionSubmitForm result = (PDActionSubmitForm) PDActionSubmitForm.META
213: .createNew();
214: result.setUrl(url);
215: return result;
216: }
217:
218: protected SubmitFormFlags getFlags() {
219: if (flags == null) {
220: flags = new SubmitFormFlags(this );
221: }
222: return flags;
223: }
224:
225: /**
226: * A list of field names (plain Java String) to be resetted or null.
227: *
228: * @return A list of field names (plain Java String) to be resetted or null.
229: */
230: public List getFields() {
231: COSArray array = cosGetField(DK_Fields).asArray();
232: if (array != null) {
233: List result = new ArrayList();
234: for (Iterator i = array.iterator(); i.hasNext();) {
235: COSObject entry = (COSObject) i.next();
236: if (entry instanceof COSDictionary) {
237: PDAcroFormField field = (PDAcroFormField) PDAcroFormField.META
238: .createFromCos(entry);
239: result.add(field.getQualifiedName());
240: } else {
241: result.add(entry.stringValue());
242: }
243: }
244: return result;
245: }
246: return null;
247: }
248:
249: protected int basicGetFlags() {
250: // inheritance doesn't make any sense, so we ignore it right now
251: return getFieldInt(DK_Flags, 0);
252: }
253:
254: protected PDFileSpecification getUrlSpecification() {
255: COSObject cosObject = cosGetField(DK_F);
256: if (cosObject.isNull()) {
257: return null;
258: }
259: return (PDFileSpecificationURL) PDFileSpecificationURL.META
260: .createFromCos(cosObject);
261: }
262:
263: protected void setFields(List newFields) {
264: // TODO 1 @wad cosSet type: array: PDFormField
265: }
266:
267: protected void basicSetFlags(int newFlags) {
268: if (newFlags != 0) { // default
269: cosSetField(DK_Flags, COSInteger.create(newFlags));
270: } else {
271: cosRemoveField(DK_Flags);
272: }
273: }
274:
275: protected void setUrlSpecification(PDFileSpecification newUrl) {
276: setFieldObject(DK_F, newUrl);
277: }
278: }
|