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: /**
033: * The flags of a signature field.
034: * <p>
035: * The flags are bits of an integer.<br>
036: * The following bits are defined (more may exist).
037: * </p>
038: * <ul>
039: * <li>0: default
040: * <li>1: SignatureExists
041: * <li>2: AppendOnly
042: * </ul>
043: */
044: public class AcroFormSigFlags extends AbstractBitFlags {
045: static public int Bit_SignatureExists = 1; // Bit position 1
046:
047: static public int Bit_AppendOnly = 1 << 1; // Bit position 2
048:
049: private PDAcroForm acroForm;
050:
051: public AcroFormSigFlags(PDAcroForm form) {
052: acroForm = form;
053: }
054:
055: /**
056: * excerpt from PDF 1.7 spec (p. 674):
057: * <p>
058: * If set, the document contains signatures that may be invalidated if the
059: * file is saved (written) in a way that alters its previous contents, as
060: * opposed to an incremental update. Merely updating the file by appending
061: * new information to the end of the previous version is safe (see Section
062: * G.6, “Updating Example”). Viewer applications can use this flag to
063: * present a user requesting a full save with an additional alert box
064: * warning that signatures will be invalidated and requiring explicit
065: * confirmation before continuing with the operation.
066: * <p>
067: *
068: * @param appendOnly
069: */
070: public void setAppendOnly(boolean appendOnly) {
071: set(Bit_AppendOnly, appendOnly);
072: }
073:
074: /**
075: * @see de.intarsys.pdf.pd.AcroFormSigFlags#setAppendOnly(boolean)
076: *
077: * @return appendOnly flag
078: */
079: public boolean isAppendOnly() {
080: return isSetAnd(Bit_AppendOnly);
081: }
082:
083: /**
084: * excerpt from PDF 1.7 spec (p. 674):
085: * <p>
086: * If set, the document contains at least one signature field. This flag
087: * allows a viewer application to enable user interface items (such as menu
088: * items or pushbuttons) related to signature processing without having to
089: * scan the entire document for the presence of signature fields.
090: * </p>
091: *
092: * @param signatureExists
093: */
094: public void setSignatureExists(boolean signatureExists) {
095: set(Bit_SignatureExists, signatureExists);
096: }
097:
098: /**
099: * @see de.intarsys.pdf.pd.AcroFormSigFlags#setSignatureExists(boolean)
100: *
101: * @return signatureExists flag
102: */
103: public boolean isSignatureExists() {
104: return isSetAnd(Bit_SignatureExists);
105: }
106:
107: protected PDAcroForm getAcroForm() {
108: return acroForm;
109: }
110:
111: protected void setValue(int newValue) {
112: if (newValue != 0) { // default
113: getAcroForm().setFieldInt(PDAcroForm.DK_SigFlags, newValue);
114: } else {
115: getAcroForm().cosRemoveField(PDAcroForm.DK_SigFlags);
116: }
117: }
118:
119: protected int getValue() {
120: return getAcroForm().getFieldInt(PDAcroForm.DK_SigFlags, 0);
121: }
122: }
|