KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2004-2006, 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 java.io.IOException JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.util.Calendar JavaDoc;
36
37 import org.pdfbox.cos.COSDictionary;
38 import org.pdfbox.cos.COSStream;
39 import org.pdfbox.pdmodel.PDDocument;
40 import org.pdfbox.pdmodel.common.PDStream;
41
42 /**
43  * This represents an embedded file in a file specification.
44  *
45  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
46  * @version $Revision: 1.2 $
47  */

48 public class PDEmbeddedFile extends PDStream
49 {
50
51     /**
52      * Constructor.
53      *
54      * @param document {@inheritDoc}
55      */

56     public PDEmbeddedFile( PDDocument document )
57     {
58         super( document );
59         getStream().setName( "Type", "EmbeddedFile" );
60         
61     }
62     
63     /**
64      * Constructor.
65      *
66      * @param str The stream parameter.
67      */

68     public PDEmbeddedFile( COSStream str )
69     {
70         super( str );
71     }
72     
73     /**
74      * Constructor.
75      *
76      * @param doc {@inheritDoc}
77      * @param str {@inheritDoc}
78      *
79      * @throws IOException {@inheritDoc}
80      */

81     public PDEmbeddedFile( PDDocument doc, InputStream JavaDoc str ) throws IOException JavaDoc
82     {
83         super( doc, str );
84         getStream().setName( "Type", "EmbeddedFile" );
85     }
86     
87     /**
88      * Constructor.
89      *
90      * @param doc {@inheritDoc}
91      * @param str {@inheritDoc}
92      * @param filtered {@inheritDoc}
93      *
94      * @throws IOException {@inheritDoc}
95      */

96     public PDEmbeddedFile( PDDocument doc, InputStream JavaDoc str, boolean filtered ) throws IOException JavaDoc
97     {
98         super( doc, str, filtered );
99         getStream().setName( "Type", "EmbeddedFile" );
100     }
101     
102     /**
103      * Set the subtype for this embedded file. This should be a mime type value. Optional.
104      *
105      * @param mimeType The mimeType for the file.
106      */

107     public void setSubtype( String JavaDoc mimeType )
108     {
109         getStream().setName( "Subtype", mimeType );
110     }
111     
112     /**
113      * Get the subtype(mimetype) for the embedded file.
114      *
115      * @return The type of embedded file.
116      */

117     public String JavaDoc getSubtype()
118     {
119         return getStream().getNameAsString( "Subtype" );
120     }
121     
122     /**
123      * Get the size of the embedded file.
124      *
125      * @return The size of the embedded file.
126      */

127     public int getSize()
128     {
129         return getStream().getEmbeddedInt( "Params", "Size" );
130     }
131     
132     /**
133      * Set the size of the embedded file.
134      *
135      * @param size The size of the embedded file.
136      */

137     public void setSize( int size )
138     {
139         getStream().setEmbeddedInt( "Params", "Size", size );
140     }
141     
142     /**
143      * Get the creation date of the embedded file.
144      *
145      * @return The Creation date.
146      * @throws IOException If there is an error while constructing the date.
147      */

148     public Calendar JavaDoc getCreationDate() throws IOException JavaDoc
149     {
150         return getStream().getEmbeddedDate( "Params", "CreationDate" );
151     }
152     
153     /**
154      * Set the creation date.
155      *
156      * @param creation The new creation date.
157      */

158     public void setCreationDate( Calendar JavaDoc creation )
159     {
160         getStream().setEmbeddedDate( "Params", "CreationDate", creation );
161     }
162     
163     /**
164      * Get the mod date of the embedded file.
165      *
166      * @return The mod date.
167      * @throws IOException If there is an error while constructing the date.
168      */

169     public Calendar JavaDoc getModDate() throws IOException JavaDoc
170     {
171         return getStream().getEmbeddedDate( "Params", "ModDate" );
172     }
173     
174     /**
175      * Set the mod date.
176      *
177      * @param mod The new creation mod.
178      */

179     public void setModDate( Calendar JavaDoc mod )
180     {
181         getStream().setEmbeddedDate( "Params", "ModDate", mod );
182     }
183     
184     /**
185      * Get the check sum of the embedded file.
186      *
187      * @return The check sum of the file.
188      */

189     public String JavaDoc getCheckSum()
190     {
191         return getStream().getEmbeddedString( "Params", "CheckSum" );
192     }
193     
194     /**
195      * Set the check sum.
196      *
197      * @param checksum The checksum of the file.
198      */

199     public void setCheckSum( String JavaDoc checksum )
200     {
201         getStream().setEmbeddedString( "Params", "CheckSum", checksum );
202     }
203     
204     /**
205      * Get the mac subtype.
206      *
207      * @return The mac subtype.
208      */

209     public String JavaDoc getMacSubtype()
210     {
211         String JavaDoc retval = null;
212         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
213         if( params != null )
214         {
215             retval = params.getEmbeddedString( "Mac", "Subtype" );
216         }
217         return retval;
218     }
219     
220     /**
221      * Set the mac subtype.
222      *
223      * @param macSubtype The mac subtype.
224      */

225     public void setMacSubtype( String JavaDoc macSubtype )
226     {
227         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
228         if( params == null && macSubtype != null )
229         {
230             params = new COSDictionary();
231             getStream().setItem( "Params", params );
232         }
233         if( params != null )
234         {
235             params.setEmbeddedString( "Mac", "Subtype", macSubtype );
236         }
237     }
238     
239     /**
240      * Get the mac Creator.
241      *
242      * @return The mac Creator.
243      */

244     public String JavaDoc getMacCreator()
245     {
246         String JavaDoc retval = null;
247         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
248         if( params != null )
249         {
250             retval = params.getEmbeddedString( "Mac", "Creator" );
251         }
252         return retval;
253     }
254     
255     /**
256      * Set the mac Creator.
257      *
258      * @param macCreator The mac Creator.
259      */

260     public void setMacCreator( String JavaDoc macCreator )
261     {
262         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
263         if( params == null && macCreator != null )
264         {
265             params = new COSDictionary();
266             getStream().setItem( "Params", params );
267         }
268         if( params != null )
269         {
270             params.setEmbeddedString( "Mac", "Creator", macCreator );
271         }
272     }
273     
274     /**
275      * Get the mac ResFork.
276      *
277      * @return The mac ResFork.
278      */

279     public String JavaDoc getMacResFork()
280     {
281         String JavaDoc retval = null;
282         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
283         if( params != null )
284         {
285             retval = params.getEmbeddedString( "Mac", "ResFork" );
286         }
287         return retval;
288     }
289     
290     /**
291      * Set the mac ResFork.
292      *
293      * @param macResFork The mac ResFork.
294      */

295     public void setMacResFork( String JavaDoc macResFork )
296     {
297         COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
298         if( params == null && macResFork != null )
299         {
300             params = new COSDictionary();
301             getStream().setItem( "Params", params );
302         }
303         if( params != null )
304         {
305             params.setEmbeddedString( "Mac", "ResFork", macResFork);
306         }
307     }
308     
309     
310     
311 }
Popular Tags