1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.common.filespecification; 18 19 import org.apache.pdfbox.cos.COSBase; 20 import org.apache.pdfbox.cos.COSDictionary; 21 import org.apache.pdfbox.cos.COSStream; 22 23 /** 24 * This represents a file specification. 25 * 26 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 27 * @version $Revision: 1.4 $ 28 */ 29 public class PDComplexFileSpecification extends PDFileSpecification 30 { 31 private COSDictionary fs; 32 33 /** 34 * Default Constructor. 35 */ 36 public PDComplexFileSpecification() 37 { 38 fs = new COSDictionary(); 39 fs.setName( "Type", "Filespec" ); 40 } 41 42 /** 43 * Constructor. 44 * 45 * @param dict The dictionary that fulfils this file specification. 46 */ 47 public PDComplexFileSpecification( COSDictionary dict ) 48 { 49 fs = dict; 50 } 51 52 /** 53 * Convert this standard java object to a COS object. 54 * 55 * @return The cos object that matches this Java object. 56 */ 57 public COSBase getCOSObject() 58 { 59 return fs; 60 } 61 62 /** 63 * Convert this standard java object to a COS object. 64 * 65 * @return The cos object that matches this Java object. 66 */ 67 public COSDictionary getCOSDictionary() 68 { 69 return fs; 70 } 71 72 /** 73 * This will get the file name. 74 * 75 * @return The file name. 76 */ 77 public String getFile() 78 { 79 return fs.getString( "F" ); 80 } 81 82 /** 83 * This will set the file name. 84 * 85 * @param file The name of the file. 86 */ 87 public void setFile( String file ) 88 { 89 fs.setString( "F", file ); 90 } 91 92 /** 93 * This will get the name representing a Dos file. 94 * 95 * @return The file name. 96 */ 97 public String getFileDos() 98 { 99 return fs.getString( "DOS" ); 100 } 101 102 /** 103 * This will set name representing a dos file. 104 * 105 * @param file The name of the file. 106 */ 107 public void setFileDos( String file ) 108 { 109 fs.setString( "DOS", file ); 110 } 111 112 /** 113 * This will get the name representing a Mac file. 114 * 115 * @return The file name. 116 */ 117 public String getFileMac() 118 { 119 return fs.getString( "Mac" ); 120 } 121 122 /** 123 * This will set name representing a Mac file. 124 * 125 * @param file The name of the file. 126 */ 127 public void setFileMac( String file ) 128 { 129 fs.setString( "Mac", file ); 130 } 131 132 /** 133 * This will get the name representing a Unix file. 134 * 135 * @return The file name. 136 */ 137 public String getFileUnix() 138 { 139 return fs.getString( "Unix" ); 140 } 141 142 /** 143 * This will set name representing a Unix file. 144 * 145 * @param file The name of the file. 146 */ 147 public void setFileUnix( String file ) 148 { 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 { 160 fs.setBoolean( "V", fileIsVolatile ); 161 } 162 163 /** 164 * Get if the file is volatile. Default: false 165 * 166 * @return True if the file is volatile attribute is set. 167 */ 168 public boolean isVolatile() 169 { 170 return fs.getBoolean( "V", false ); 171 } 172 173 /** 174 * Get the embedded file. 175 * 176 * @return The embedded file for this file spec. 177 */ 178 public PDEmbeddedFile getEmbeddedFile() 179 { 180 PDEmbeddedFile file = null; 181 COSStream stream = (COSStream)fs.getObjectFromPath( "EF/F" ); 182 if( stream != null ) 183 { 184 file = new PDEmbeddedFile( stream ); 185 } 186 return file; 187 } 188 189 /** 190 * Set the embedded file for this spec. 191 * 192 * @param file The file to be embedded. 193 */ 194 public void setEmbeddedFile( PDEmbeddedFile file ) 195 { 196 COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "EF" ); 197 if( ef == null && file != null ) 198 { 199 ef = new COSDictionary(); 200 fs.setItem( "EF", ef ); 201 } 202 if( ef != null ) 203 { 204 ef.setItem( "F", file ); 205 } 206 } 207 208 /** 209 * Get the embedded dos file. 210 * 211 * @return The embedded file for this file spec. 212 */ 213 public PDEmbeddedFile getEmbeddedFileDos() 214 { 215 PDEmbeddedFile file = null; 216 COSStream stream = (COSStream)fs.getObjectFromPath( "EF/DOS" ); 217 if( stream != null ) 218 { 219 file = new PDEmbeddedFile( stream ); 220 } 221 return file; 222 } 223 224 /** 225 * Set the embedded dos file for this spec. 226 * 227 * @param file The dos file to be embedded. 228 */ 229 public void setEmbeddedFileDos( PDEmbeddedFile file ) 230 { 231 COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "DOS" ); 232 if( ef == null && file != null ) 233 { 234 ef = new COSDictionary(); 235 fs.setItem( "EF", ef ); 236 } 237 if( ef != null ) 238 { 239 ef.setItem( "DOS", file ); 240 } 241 } 242 243 /** 244 * Get the embedded Mac file. 245 * 246 * @return The embedded file for this file spec. 247 */ 248 public PDEmbeddedFile getEmbeddedFileMac() 249 { 250 PDEmbeddedFile file = null; 251 COSStream stream = (COSStream)fs.getObjectFromPath( "EF/Mac" ); 252 if( stream != null ) 253 { 254 file = new PDEmbeddedFile( stream ); 255 } 256 return file; 257 } 258 259 /** 260 * Set the embedded Mac file for this spec. 261 * 262 * @param file The Mac file to be embedded. 263 */ 264 public void setEmbeddedFileMac( PDEmbeddedFile file ) 265 { 266 COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Mac" ); 267 if( ef == null && file != null ) 268 { 269 ef = new COSDictionary(); 270 fs.setItem( "EF", ef ); 271 } 272 if( ef != null ) 273 { 274 ef.setItem( "Mac", file ); 275 } 276 } 277 278 /** 279 * Get the embedded Unix file. 280 * 281 * @return The embedded file for this file spec. 282 */ 283 public PDEmbeddedFile getEmbeddedFileUnix() 284 { 285 PDEmbeddedFile file = null; 286 COSStream stream = (COSStream)fs.getObjectFromPath( "EF/Unix" ); 287 if( stream != null ) 288 { 289 file = new PDEmbeddedFile( stream ); 290 } 291 return file; 292 } 293 294 /** 295 * Set the embedded Unix file for this spec. 296 * 297 * @param file The Unix file to be embedded. 298 */ 299 public void setEmbeddedFileUnix( PDEmbeddedFile file ) 300 { 301 COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Unix" ); 302 if( ef == null && file != null ) 303 { 304 ef = new COSDictionary(); 305 fs.setItem( "EF", ef ); 306 } 307 if( ef != null ) 308 { 309 ef.setItem( "Unix", file ); 310 } 311 } 312 }