Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.common.filespecification » [javadoc | source]

    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   import java.io.InputStream;
   21   import java.util.Calendar;
   22   
   23   import org.apache.pdfbox.cos.COSDictionary;
   24   import org.apache.pdfbox.cos.COSStream;
   25   import org.apache.pdfbox.pdmodel.PDDocument;
   26   import org.apache.pdfbox.pdmodel.common.PDStream;
   27   
   28   /**
   29    * This represents an embedded file in a file specification.
   30    *
   31    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   32    * @version $Revision: 1.2 $
   33    */
   34   public class PDEmbeddedFile extends PDStream
   35   {
   36   
   37       /**
   38        * Constructor.
   39        *
   40        * @param document {@inheritDoc}
   41        */
   42       public PDEmbeddedFile( PDDocument document )
   43       {
   44           super( document );
   45           getStream().setName( "Type", "EmbeddedFile" );
   46   
   47       }
   48   
   49       /**
   50        * Constructor.
   51        *
   52        * @param str The stream parameter.
   53        */
   54       public PDEmbeddedFile( COSStream str )
   55       {
   56           super( str );
   57       }
   58   
   59       /**
   60        * Constructor.
   61        *
   62        * @param doc {@inheritDoc}
   63        * @param str {@inheritDoc}
   64        *
   65        * @throws IOException {@inheritDoc}
   66        */
   67       public PDEmbeddedFile( PDDocument doc, InputStream str  ) throws IOException
   68       {
   69           super( doc, str );
   70           getStream().setName( "Type", "EmbeddedFile" );
   71       }
   72   
   73       /**
   74        * Constructor.
   75        *
   76        * @param doc {@inheritDoc}
   77        * @param str {@inheritDoc}
   78        * @param filtered {@inheritDoc}
   79        *
   80        * @throws IOException {@inheritDoc}
   81        */
   82       public PDEmbeddedFile( PDDocument doc, InputStream str, boolean filtered ) throws IOException
   83       {
   84           super( doc, str, filtered );
   85           getStream().setName( "Type", "EmbeddedFile" );
   86       }
   87   
   88       /**
   89        * Set the subtype for this embedded file.  This should be a mime type value.  Optional.
   90        *
   91        * @param mimeType The mimeType for the file.
   92        */
   93       public void setSubtype( String mimeType )
   94       {
   95           getStream().setName( "Subtype", mimeType );
   96       }
   97   
   98       /**
   99        * Get the subtype(mimetype) for the embedded file.
  100        *
  101        * @return The type of embedded file.
  102        */
  103       public String getSubtype()
  104       {
  105           return getStream().getNameAsString( "Subtype" );
  106       }
  107   
  108       /**
  109        * Get the size of the embedded file.
  110        *
  111        * @return The size of the embedded file.
  112        */
  113       public int getSize()
  114       {
  115           return getStream().getEmbeddedInt( "Params", "Size" );
  116       }
  117   
  118       /**
  119        * Set the size of the embedded file.
  120        *
  121        * @param size The size of the embedded file.
  122        */
  123       public void setSize( int size )
  124       {
  125           getStream().setEmbeddedInt( "Params", "Size", size );
  126       }
  127   
  128       /**
  129        * Get the creation date of the embedded file.
  130        *
  131        * @return The Creation date.
  132        * @throws IOException If there is an error while constructing the date.
  133        */
  134       public Calendar getCreationDate() throws IOException
  135       {
  136           return getStream().getEmbeddedDate( "Params", "CreationDate" );
  137       }
  138   
  139       /**
  140        * Set the creation date.
  141        *
  142        * @param creation The new creation date.
  143        */
  144       public void setCreationDate( Calendar creation )
  145       {
  146           getStream().setEmbeddedDate( "Params", "CreationDate", creation );
  147       }
  148   
  149       /**
  150        * Get the mod date of the embedded file.
  151        *
  152        * @return The mod date.
  153        * @throws IOException If there is an error while constructing the date.
  154        */
  155       public Calendar getModDate() throws IOException
  156       {
  157           return getStream().getEmbeddedDate( "Params", "ModDate" );
  158       }
  159   
  160       /**
  161        * Set the mod date.
  162        *
  163        * @param mod The new creation mod.
  164        */
  165       public void setModDate( Calendar mod )
  166       {
  167           getStream().setEmbeddedDate( "Params", "ModDate", mod );
  168       }
  169   
  170       /**
  171        * Get the check sum of the embedded file.
  172        *
  173        * @return The check sum of the file.
  174        */
  175       public String getCheckSum()
  176       {
  177           return getStream().getEmbeddedString( "Params", "CheckSum" );
  178       }
  179   
  180       /**
  181        * Set the check sum.
  182        *
  183        * @param checksum The checksum of the file.
  184        */
  185       public void setCheckSum( String checksum )
  186       {
  187           getStream().setEmbeddedString( "Params", "CheckSum", checksum );
  188       }
  189   
  190       /**
  191        * Get the mac subtype.
  192        *
  193        * @return The mac subtype.
  194        */
  195       public String getMacSubtype()
  196       {
  197           String retval = null;
  198           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  199           if( params != null )
  200           {
  201               retval = params.getEmbeddedString( "Mac", "Subtype" );
  202           }
  203           return retval;
  204       }
  205   
  206       /**
  207        * Set the mac subtype.
  208        *
  209        * @param macSubtype The mac subtype.
  210        */
  211       public void setMacSubtype( String macSubtype )
  212       {
  213           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  214           if( params == null && macSubtype != null )
  215           {
  216               params = new COSDictionary();
  217               getStream().setItem( "Params", params );
  218           }
  219           if( params != null )
  220           {
  221               params.setEmbeddedString( "Mac", "Subtype", macSubtype );
  222           }
  223       }
  224   
  225       /**
  226        * Get the mac Creator.
  227        *
  228        * @return The mac Creator.
  229        */
  230       public String getMacCreator()
  231       {
  232           String retval = null;
  233           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  234           if( params != null )
  235           {
  236               retval = params.getEmbeddedString( "Mac", "Creator" );
  237           }
  238           return retval;
  239       }
  240   
  241       /**
  242        * Set the mac Creator.
  243        *
  244        * @param macCreator The mac Creator.
  245        */
  246       public void setMacCreator( String macCreator )
  247       {
  248           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  249           if( params == null && macCreator != null )
  250           {
  251               params = new COSDictionary();
  252               getStream().setItem( "Params", params );
  253           }
  254           if( params != null )
  255           {
  256               params.setEmbeddedString( "Mac", "Creator", macCreator );
  257           }
  258       }
  259   
  260       /**
  261        * Get the mac ResFork.
  262        *
  263        * @return The mac ResFork.
  264        */
  265       public String getMacResFork()
  266       {
  267           String retval = null;
  268           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  269           if( params != null )
  270           {
  271               retval = params.getEmbeddedString( "Mac", "ResFork" );
  272           }
  273           return retval;
  274       }
  275   
  276       /**
  277        * Set the mac ResFork.
  278        *
  279        * @param macResFork The mac ResFork.
  280        */
  281       public void setMacResFork( String macResFork )
  282       {
  283           COSDictionary params = (COSDictionary)getStream().getDictionaryObject( "Params" );
  284           if( params == null && macResFork != null )
  285           {
  286               params = new COSDictionary();
  287               getStream().setItem( "Params", params );
  288           }
  289           if( params != null )
  290           {
  291               params.setEmbeddedString( "Mac", "ResFork", macResFork);
  292           }
  293       }
  294   
  295   
  296   
  297   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.common.filespecification » [javadoc | source]