KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > filter > FilterManager


1 /**
2  * Copyright (c) 2003, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.filter;
32
33 import java.io.IOException JavaDoc;
34
35 import java.util.Collection JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.Map JavaDoc;
38
39 import org.pdfbox.cos.COSName;
40
41 /**
42  * This will contain manage all the different types of filters that are available.
43  *
44  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
45  * @version $Revision: 1.13 $
46  */

47 public class FilterManager
48 {
49     private Map JavaDoc filters = new HashMap JavaDoc();
50
51     /**
52      * Constructor.
53      */

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     /**
82      * This will get all of the filters that are available in the system.
83      *
84      * @return All available filters in the system.
85      */

86     public Collection JavaDoc getFilters()
87     {
88         return filters.values();
89     }
90
91     /**
92      * This will add an available filter.
93      *
94      * @param filterName The name of the filter.
95      * @param filter The filter to use.
96      */

97     public void addFilter( COSName filterName, Filter filter )
98     {
99         filters.put( filterName, filter );
100     }
101
102     /**
103      * This will get a filter by name.
104      *
105      * @param filterName The name of the filter to retrieve.
106      *
107      * @return The filter that matches the name.
108      *
109      * @throws IOException If the filter could not be found.
110      */

111     public Filter getFilter( COSName filterName ) throws IOException JavaDoc
112     {
113         Filter filter = (Filter)filters.get( filterName );
114         if( filter == null )
115         {
116             throw new IOException JavaDoc( "Unknown stream filter:" + filterName );
117         }
118
119         return filter;
120     }
121     
122     /**
123      * This will get a filter by name.
124      *
125      * @param filterName The name of the filter to retrieve.
126      *
127      * @return The filter that matches the name.
128      *
129      * @throws IOException If the filter could not be found.
130      */

131     public Filter getFilter( String JavaDoc filterName ) throws IOException JavaDoc
132     {
133         return getFilter( COSName.getPDFName( filterName ) );
134     }
135 }
Popular Tags