1 31 package org.pdfbox.filter; 32 33 import java.io.IOException ; 34 35 import java.util.Collection ; 36 import java.util.HashMap ; 37 import java.util.Map ; 38 39 import org.pdfbox.cos.COSName; 40 41 47 public class FilterManager 48 { 49 private Map filters = new HashMap (); 50 51 54 public FilterManager() 55 { 56 Filter flateFilter = new FlateFilter(); 57 Filter dctFilter = new DCTFilter(); 58 Filter ccittFaxFilter = new CCITTFaxDecodeFilter(); 59 Filter lzwFilter = new LZWFilter(); 60 Filter asciiHexFilter = new ASCIIHexFilter(); 61 Filter ascii85Filter = new ASCII85Filter(); 62 Filter runLengthFilter = new RunLengthDecodeFilter(); 63 64 addFilter( COSName.FLATE_DECODE, flateFilter ); 65 addFilter( COSName.FLATE_DECODE_ABBREVIATION, flateFilter ); 66 addFilter( COSName.DCT_DECODE, dctFilter ); 67 addFilter( COSName.DCT_DECODE_ABBREVIATION, dctFilter ); 68 addFilter( COSName.CCITTFAX_DECODE, ccittFaxFilter ); 69 addFilter( COSName.CCITTFAX_DECODE_ABBREVIATION, ccittFaxFilter ); 70 addFilter( COSName.LZW_DECODE, lzwFilter ); 71 addFilter( COSName.LZW_DECODE_ABBREVIATION, lzwFilter ); 72 addFilter( COSName.ASCII_HEX_DECODE, asciiHexFilter ); 73 addFilter( COSName.ASCII_HEX_DECODE_ABBREVIATION, asciiHexFilter ); 74 addFilter( COSName.ASCII85_DECODE, ascii85Filter ); 75 addFilter( COSName.ASCII85_DECODE_ABBREVIATION, ascii85Filter ); 76 addFilter( COSName.RUN_LENGTH_DECODE, runLengthFilter ); 77 addFilter( COSName.RUN_LENGTH_DECODE_ABBREVIATION, runLengthFilter ); 78 79 } 80 81 86 public Collection getFilters() 87 { 88 return filters.values(); 89 } 90 91 97 public void addFilter( COSName filterName, Filter filter ) 98 { 99 filters.put( filterName, filter ); 100 } 101 102 111 public Filter getFilter( COSName filterName ) throws IOException 112 { 113 Filter filter = (Filter)filters.get( filterName ); 114 if( filter == null ) 115 { 116 throw new IOException ( "Unknown stream filter:" + filterName ); 117 } 118 119 return filter; 120 } 121 122 131 public Filter getFilter( String filterName ) throws IOException 132 { 133 return getFilter( COSName.getPDFName( filterName ) ); 134 } 135 } | Popular Tags |