KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > common > filespecification > PDComplexFileSpecification


1 /**
2  * Copyright (c) 2004-2005, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.common.filespecification;
32
33 import org.pdfbox.cos.COSBase;
34 import org.pdfbox.cos.COSDictionary;
35 import org.pdfbox.cos.COSStream;
36
37 /**
38  * This represents a file specification.
39  *
40  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
41  * @version $Revision: 1.4 $
42  */

43 public class PDComplexFileSpecification extends PDFileSpecification
44 {
45     private COSDictionary fs;
46
47     /**
48      * Default Constructor.
49      */

50     public PDComplexFileSpecification()
51     {
52         fs = new COSDictionary();
53         fs.setName( "Type", "Filespec" );
54     }
55
56     /**
57      * Constructor.
58      *
59      * @param dict The dictionary that fulfils this file specification.
60      */

61     public PDComplexFileSpecification( COSDictionary dict )
62     {
63         fs = dict;
64     }
65
66     /**
67      * Convert this standard java object to a COS object.
68      *
69      * @return The cos object that matches this Java object.
70      */

71     public COSBase getCOSObject()
72     {
73         return fs;
74     }
75
76     /**
77      * Convert this standard java object to a COS object.
78      *
79      * @return The cos object that matches this Java object.
80      */

81     public COSDictionary getCOSDictionary()
82     {
83         return fs;
84     }
85
86     /**
87      * This will get the file name.
88      *
89      * @return The file name.
90      */

91     public String JavaDoc getFile()
92     {
93         return fs.getString( "F" );
94     }
95
96     /**
97      * This will set the file name.
98      *
99      * @param file The name of the file.
100      */

101     public void setFile( String JavaDoc file )
102     {
103         fs.setString( "F", file );
104     }
105     
106     /**
107      * This will get the name representing a Dos file.
108      *
109      * @return The file name.
110      */

111     public String JavaDoc getFileDos()
112     {
113         return fs.getString( "DOS" );
114     }
115
116     /**
117      * This will set name representing a dos file.
118      *
119      * @param file The name of the file.
120      */

121     public void setFileDos( String JavaDoc file )
122     {
123         fs.setString( "DOS", file );
124     }
125     
126     /**
127      * This will get the name representing a Mac file.
128      *
129      * @return The file name.
130      */

131     public String JavaDoc getFileMac()
132     {
133         return fs.getString( "Mac" );
134     }
135
136     /**
137      * This will set name representing a Mac file.
138      *
139      * @param file The name of the file.
140      */

141     public void setFileMac( String JavaDoc file )
142     {
143         fs.setString( "Mac", file );
144     }
145     
146     /**
147      * This will get the name representing a Unix file.
148      *
149      * @return The file name.
150      */

151     public String JavaDoc getFileUnix()
152     {
153         return fs.getString( "Unix" );
154     }
155
156     /**
157      * This will set name representing a Unix file.
158      *
159      * @param file The name of the file.
160      */

161     public void setFileUnix( String JavaDoc file )
162     {
163         fs.setString( "Unix", file );
164     }
165     
166     /**
167      * Tell if the underlying file is volatile and should not be cached by the
168      * reader application. Default: false
169      *
170      * @param fileIsVolatile The new value for the volatility of the file.
171      */

172     public void setVolatile( boolean fileIsVolatile )
173     {
174         fs.setBoolean( "V", fileIsVolatile );
175     }
176     
177     /**
178      * Get if the file is volatile. Default: false
179      *
180      * @return True if the file is volatile attribute is set.
181      */

182     public boolean isVolatile()
183     {
184         return fs.getBoolean( "V", false );
185     }
186     
187     /**
188      * Get the embedded file.
189      *
190      * @return The embedded file for this file spec.
191      */

192     public PDEmbeddedFile getEmbeddedFile()
193     {
194         PDEmbeddedFile file = null;
195         COSStream stream = (COSStream)fs.getObjectFromPath( "EF/F" );
196         if( stream != null )
197         {
198             file = new PDEmbeddedFile( stream );
199         }
200         return file;
201     }
202     
203     /**
204      * Set the embedded file for this spec.
205      *
206      * @param file The file to be embedded.
207      */

208     public void setEmbeddedFile( PDEmbeddedFile file )
209     {
210         COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "EF" );
211         if( ef == null && file != null )
212         {
213             ef = new COSDictionary();
214             fs.setItem( "EF", ef );
215         }
216         if( ef != null )
217         {
218             ef.setItem( "F", file );
219         }
220     }
221     
222     /**
223      * Get the embedded dos file.
224      *
225      * @return The embedded file for this file spec.
226      */

227     public PDEmbeddedFile getEmbeddedFileDos()
228     {
229         PDEmbeddedFile file = null;
230         COSStream stream = (COSStream)fs.getObjectFromPath( "EF/DOS" );
231         if( stream != null )
232         {
233             file = new PDEmbeddedFile( stream );
234         }
235         return file;
236     }
237     
238     /**
239      * Set the embedded dos file for this spec.
240      *
241      * @param file The dos file to be embedded.
242      */

243     public void setEmbeddedFileDos( PDEmbeddedFile file )
244     {
245         COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "DOS" );
246         if( ef == null && file != null )
247         {
248             ef = new COSDictionary();
249             fs.setItem( "EF", ef );
250         }
251         if( ef != null )
252         {
253             ef.setItem( "DOS", file );
254         }
255     }
256     
257     /**
258      * Get the embedded Mac file.
259      *
260      * @return The embedded file for this file spec.
261      */

262     public PDEmbeddedFile getEmbeddedFileMac()
263     {
264         PDEmbeddedFile file = null;
265         COSStream stream = (COSStream)fs.getObjectFromPath( "EF/Mac" );
266         if( stream != null )
267         {
268             file = new PDEmbeddedFile( stream );
269         }
270         return file;
271     }
272     
273     /**
274      * Set the embedded Mac file for this spec.
275      *
276      * @param file The Mac file to be embedded.
277      */

278     public void setEmbeddedFileMac( PDEmbeddedFile file )
279     {
280         COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Mac" );
281         if( ef == null && file != null )
282         {
283             ef = new COSDictionary();
284             fs.setItem( "EF", ef );
285         }
286         if( ef != null )
287         {
288             ef.setItem( "Mac", file );
289         }
290     }
291     
292     /**
293      * Get the embedded Unix file.
294      *
295      * @return The embedded file for this file spec.
296      */

297     public PDEmbeddedFile getEmbeddedFileUnix()
298     {
299         PDEmbeddedFile file = null;
300         COSStream stream = (COSStream)fs.getObjectFromPath( "EF/Unix" );
301         if( stream != null )
302         {
303             file = new PDEmbeddedFile( stream );
304         }
305         return file;
306     }
307     
308     /**
309      * Set the embedded Unix file for this spec.
310      *
311      * @param file The Unix file to be embedded.
312      */

313     public void setEmbeddedFileUnix( PDEmbeddedFile file )
314     {
315         COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Unix" );
316         if( ef == null && file != null )
317         {
318             ef = new COSDictionary();
319             fs.setItem( "EF", ef );
320         }
321         if( ef != null )
322         {
323             ef.setItem( "Unix", file );
324         }
325     }
326 }
Popular Tags