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 java.io.IOException; 20 21 import org.apache.pdfbox.cos.COSBase; 22 import org.apache.pdfbox.cos.COSDictionary; 23 import org.apache.pdfbox.cos.COSString; 24 25 import org.apache.pdfbox.pdmodel.common.COSObjectable; 26 27 /** 28 * This represents a file specification. 29 * 30 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 31 * @version $Revision: 1.4 $ 32 */ 33 public abstract class PDFileSpecification implements COSObjectable 34 { 35 36 /** 37 * A file specfication can either be a COSString or a COSDictionary. This 38 * will create the file specification either way. 39 * 40 * @param base The cos object that describes the fs. 41 * 42 * @return The file specification for the COSBase object. 43 * 44 * @throws IOException If there is an error creating the file spec. 45 */ 46 public static PDFileSpecification createFS( COSBase base ) throws IOException 47 { 48 PDFileSpecification retval = null; 49 if( base == null ) 50 { 51 //then simply return null 52 } 53 else if( base instanceof COSString ) 54 { 55 retval = new PDSimpleFileSpecification( (COSString)base ); 56 } 57 else if( base instanceof COSDictionary ) 58 { 59 retval = new PDComplexFileSpecification( (COSDictionary)base ); 60 } 61 else 62 { 63 throw new IOException( "Error: Unknown file specification " + base ); 64 } 65 return retval; 66 } 67 68 /** 69 * This will get the file name. 70 * 71 * @return The file name. 72 */ 73 public abstract String getFile(); 74 75 /** 76 * This will set the file name. 77 * 78 * @param file The name of the file. 79 */ 80 public abstract void setFile( String file ); 81 }