Home » pdfbox-1.1.0-src » org.apache.pdfbox.filter » [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.filter;
   18   
   19   import java.io.IOException;
   20   
   21   import java.util.Collection;
   22   import java.util.HashMap;
   23   import java.util.Map;
   24   
   25   import org.apache.pdfbox.cos.COSName;
   26   
   27   /**
   28    * This will contain manage all the different types of filters that are available.
   29    *
   30    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   31    * @version $Revision: 1.13 $
   32    */
   33   public class FilterManager
   34   {
   35       private Map<COSName, Filter> filters = new HashMap<COSName, Filter>();
   36   
   37       /**
   38        * Constructor.
   39        */
   40       public FilterManager()
   41       {
   42           Filter flateFilter = new FlateFilter();
   43           Filter dctFilter = new DCTFilter();
   44           Filter ccittFaxFilter = new CCITTFaxDecodeFilter();
   45           Filter lzwFilter = new LZWFilter();
   46           Filter asciiHexFilter = new ASCIIHexFilter();
   47           Filter ascii85Filter = new ASCII85Filter();
   48           Filter runLengthFilter = new RunLengthDecodeFilter();
   49   
   50           addFilter( COSName.FLATE_DECODE, flateFilter );
   51           addFilter( COSName.FLATE_DECODE_ABBREVIATION, flateFilter );
   52           addFilter( COSName.DCT_DECODE, dctFilter );
   53           addFilter( COSName.DCT_DECODE_ABBREVIATION, dctFilter );
   54           addFilter( COSName.CCITTFAX_DECODE, ccittFaxFilter );
   55           addFilter( COSName.CCITTFAX_DECODE_ABBREVIATION, ccittFaxFilter );
   56           addFilter( COSName.LZW_DECODE, lzwFilter );
   57           addFilter( COSName.LZW_DECODE_ABBREVIATION, lzwFilter );
   58           addFilter( COSName.ASCII_HEX_DECODE, asciiHexFilter );
   59           addFilter( COSName.ASCII_HEX_DECODE_ABBREVIATION, asciiHexFilter );
   60           addFilter( COSName.ASCII85_DECODE, ascii85Filter );
   61           addFilter( COSName.ASCII85_DECODE_ABBREVIATION, ascii85Filter );
   62           addFilter( COSName.RUN_LENGTH_DECODE, runLengthFilter );
   63           addFilter( COSName.RUN_LENGTH_DECODE_ABBREVIATION, runLengthFilter );
   64   
   65       }
   66   
   67       /**
   68        * This will get all of the filters that are available in the system.
   69        *
   70        * @return All available filters in the system.
   71        */
   72       public Collection<Filter> getFilters()
   73       {
   74           return filters.values();
   75       }
   76   
   77       /**
   78        * This will add an available filter.
   79        *
   80        * @param filterName The name of the filter.
   81        * @param filter The filter to use.
   82        */
   83       public void addFilter( COSName filterName, Filter filter )
   84       {
   85           filters.put( filterName, filter );
   86       }
   87   
   88       /**
   89        * This will get a filter by name.
   90        *
   91        * @param filterName The name of the filter to retrieve.
   92        *
   93        * @return The filter that matches the name.
   94        *
   95        * @throws IOException If the filter could not be found.
   96        */
   97       public Filter getFilter( COSName filterName ) throws IOException
   98       {
   99           Filter filter = (Filter)filters.get( filterName );
  100           if( filter == null )
  101           {
  102               throw new IOException( "Unknown stream filter:" + filterName );
  103           }
  104   
  105           return filter;
  106       }
  107   
  108       /**
  109        * This will get a filter by name.
  110        *
  111        * @param filterName The name of the filter to retrieve.
  112        *
  113        * @return The filter that matches the name.
  114        *
  115        * @throws IOException If the filter could not be found.
  116        */
  117       public Filter getFilter( String filterName ) throws IOException
  118       {
  119           return getFilter( COSName.getPDFName( filterName ) );
  120       }
  121   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.filter » [javadoc | source]