001: /**
002: * Copyright (c) 2004-2005, 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.common.filespecification;
031:
032: import org.pdfbox.cos.COSBase;
033: import org.pdfbox.cos.COSDictionary;
034: import org.pdfbox.cos.COSStream;
035:
036: /**
037: * This represents a file specification.
038: *
039: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
040: * @version $Revision: 1.4 $
041: */
042: public class PDComplexFileSpecification extends PDFileSpecification {
043: private COSDictionary fs;
044:
045: /**
046: * Default Constructor.
047: */
048: public PDComplexFileSpecification() {
049: fs = new COSDictionary();
050: fs.setName("Type", "Filespec");
051: }
052:
053: /**
054: * Constructor.
055: *
056: * @param dict The dictionary that fulfils this file specification.
057: */
058: public PDComplexFileSpecification(COSDictionary dict) {
059: fs = dict;
060: }
061:
062: /**
063: * Convert this standard java object to a COS object.
064: *
065: * @return The cos object that matches this Java object.
066: */
067: public COSBase getCOSObject() {
068: return fs;
069: }
070:
071: /**
072: * Convert this standard java object to a COS object.
073: *
074: * @return The cos object that matches this Java object.
075: */
076: public COSDictionary getCOSDictionary() {
077: return fs;
078: }
079:
080: /**
081: * This will get the file name.
082: *
083: * @return The file name.
084: */
085: public String getFile() {
086: return fs.getString("F");
087: }
088:
089: /**
090: * This will set the file name.
091: *
092: * @param file The name of the file.
093: */
094: public void setFile(String file) {
095: fs.setString("F", file);
096: }
097:
098: /**
099: * This will get the name representing a Dos file.
100: *
101: * @return The file name.
102: */
103: public String getFileDos() {
104: return fs.getString("DOS");
105: }
106:
107: /**
108: * This will set name representing a dos file.
109: *
110: * @param file The name of the file.
111: */
112: public void setFileDos(String file) {
113: fs.setString("DOS", file);
114: }
115:
116: /**
117: * This will get the name representing a Mac file.
118: *
119: * @return The file name.
120: */
121: public String getFileMac() {
122: return fs.getString("Mac");
123: }
124:
125: /**
126: * This will set name representing a Mac file.
127: *
128: * @param file The name of the file.
129: */
130: public void setFileMac(String file) {
131: fs.setString("Mac", file);
132: }
133:
134: /**
135: * This will get the name representing a Unix file.
136: *
137: * @return The file name.
138: */
139: public String getFileUnix() {
140: return fs.getString("Unix");
141: }
142:
143: /**
144: * This will set name representing a Unix file.
145: *
146: * @param file The name of the file.
147: */
148: public void setFileUnix(String file) {
149: fs.setString("Unix", file);
150: }
151:
152: /**
153: * Tell if the underlying file is volatile and should not be cached by the
154: * reader application. Default: false
155: *
156: * @param fileIsVolatile The new value for the volatility of the file.
157: */
158: public void setVolatile(boolean fileIsVolatile) {
159: fs.setBoolean("V", fileIsVolatile);
160: }
161:
162: /**
163: * Get if the file is volatile. Default: false
164: *
165: * @return True if the file is volatile attribute is set.
166: */
167: public boolean isVolatile() {
168: return fs.getBoolean("V", false);
169: }
170:
171: /**
172: * Get the embedded file.
173: *
174: * @return The embedded file for this file spec.
175: */
176: public PDEmbeddedFile getEmbeddedFile() {
177: PDEmbeddedFile file = null;
178: COSStream stream = (COSStream) fs.getObjectFromPath("EF/F");
179: if (stream != null) {
180: file = new PDEmbeddedFile(stream);
181: }
182: return file;
183: }
184:
185: /**
186: * Set the embedded file for this spec.
187: *
188: * @param file The file to be embedded.
189: */
190: public void setEmbeddedFile(PDEmbeddedFile file) {
191: COSDictionary ef = (COSDictionary) fs.getDictionaryObject("EF");
192: if (ef == null && file != null) {
193: ef = new COSDictionary();
194: fs.setItem("EF", ef);
195: }
196: if (ef != null) {
197: ef.setItem("F", file);
198: }
199: }
200:
201: /**
202: * Get the embedded dos file.
203: *
204: * @return The embedded file for this file spec.
205: */
206: public PDEmbeddedFile getEmbeddedFileDos() {
207: PDEmbeddedFile file = null;
208: COSStream stream = (COSStream) fs.getObjectFromPath("EF/DOS");
209: if (stream != null) {
210: file = new PDEmbeddedFile(stream);
211: }
212: return file;
213: }
214:
215: /**
216: * Set the embedded dos file for this spec.
217: *
218: * @param file The dos file to be embedded.
219: */
220: public void setEmbeddedFileDos(PDEmbeddedFile file) {
221: COSDictionary ef = (COSDictionary) fs
222: .getDictionaryObject("DOS");
223: if (ef == null && file != null) {
224: ef = new COSDictionary();
225: fs.setItem("EF", ef);
226: }
227: if (ef != null) {
228: ef.setItem("DOS", file);
229: }
230: }
231:
232: /**
233: * Get the embedded Mac file.
234: *
235: * @return The embedded file for this file spec.
236: */
237: public PDEmbeddedFile getEmbeddedFileMac() {
238: PDEmbeddedFile file = null;
239: COSStream stream = (COSStream) fs.getObjectFromPath("EF/Mac");
240: if (stream != null) {
241: file = new PDEmbeddedFile(stream);
242: }
243: return file;
244: }
245:
246: /**
247: * Set the embedded Mac file for this spec.
248: *
249: * @param file The Mac file to be embedded.
250: */
251: public void setEmbeddedFileMac(PDEmbeddedFile file) {
252: COSDictionary ef = (COSDictionary) fs
253: .getDictionaryObject("Mac");
254: if (ef == null && file != null) {
255: ef = new COSDictionary();
256: fs.setItem("EF", ef);
257: }
258: if (ef != null) {
259: ef.setItem("Mac", file);
260: }
261: }
262:
263: /**
264: * Get the embedded Unix file.
265: *
266: * @return The embedded file for this file spec.
267: */
268: public PDEmbeddedFile getEmbeddedFileUnix() {
269: PDEmbeddedFile file = null;
270: COSStream stream = (COSStream) fs.getObjectFromPath("EF/Unix");
271: if (stream != null) {
272: file = new PDEmbeddedFile(stream);
273: }
274: return file;
275: }
276:
277: /**
278: * Set the embedded Unix file for this spec.
279: *
280: * @param file The Unix file to be embedded.
281: */
282: public void setEmbeddedFileUnix(PDEmbeddedFile file) {
283: COSDictionary ef = (COSDictionary) fs
284: .getDictionaryObject("Unix");
285: if (ef == null && file != null) {
286: ef = new COSDictionary();
287: fs.setItem("EF", ef);
288: }
289: if (ef != null) {
290: ef.setItem("Unix", file);
291: }
292: }
293: }
|