001: /**
002: * Copyright (c) 2003, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.filter;
031:
032: import java.io.IOException;
033:
034: import java.util.Collection;
035: import java.util.HashMap;
036: import java.util.Map;
037:
038: import org.pdfbox.cos.COSName;
039:
040: /**
041: * This will contain manage all the different types of filters that are available.
042: *
043: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
044: * @version $Revision: 1.13 $
045: */
046: public class FilterManager {
047: private Map filters = new HashMap();
048:
049: /**
050: * Constructor.
051: */
052: public FilterManager() {
053: Filter flateFilter = new FlateFilter();
054: Filter dctFilter = new DCTFilter();
055: Filter ccittFaxFilter = new CCITTFaxDecodeFilter();
056: Filter lzwFilter = new LZWFilter();
057: Filter asciiHexFilter = new ASCIIHexFilter();
058: Filter ascii85Filter = new ASCII85Filter();
059: Filter runLengthFilter = new RunLengthDecodeFilter();
060:
061: addFilter(COSName.FLATE_DECODE, flateFilter);
062: addFilter(COSName.FLATE_DECODE_ABBREVIATION, flateFilter);
063: addFilter(COSName.DCT_DECODE, dctFilter);
064: addFilter(COSName.DCT_DECODE_ABBREVIATION, dctFilter);
065: addFilter(COSName.CCITTFAX_DECODE, ccittFaxFilter);
066: addFilter(COSName.CCITTFAX_DECODE_ABBREVIATION, ccittFaxFilter);
067: addFilter(COSName.LZW_DECODE, lzwFilter);
068: addFilter(COSName.LZW_DECODE_ABBREVIATION, lzwFilter);
069: addFilter(COSName.ASCII_HEX_DECODE, asciiHexFilter);
070: addFilter(COSName.ASCII_HEX_DECODE_ABBREVIATION, asciiHexFilter);
071: addFilter(COSName.ASCII85_DECODE, ascii85Filter);
072: addFilter(COSName.ASCII85_DECODE_ABBREVIATION, ascii85Filter);
073: addFilter(COSName.RUN_LENGTH_DECODE, runLengthFilter);
074: addFilter(COSName.RUN_LENGTH_DECODE_ABBREVIATION,
075: runLengthFilter);
076:
077: }
078:
079: /**
080: * This will get all of the filters that are available in the system.
081: *
082: * @return All available filters in the system.
083: */
084: public Collection getFilters() {
085: return filters.values();
086: }
087:
088: /**
089: * This will add an available filter.
090: *
091: * @param filterName The name of the filter.
092: * @param filter The filter to use.
093: */
094: public void addFilter(COSName filterName, Filter filter) {
095: filters.put(filterName, filter);
096: }
097:
098: /**
099: * This will get a filter by name.
100: *
101: * @param filterName The name of the filter to retrieve.
102: *
103: * @return The filter that matches the name.
104: *
105: * @throws IOException If the filter could not be found.
106: */
107: public Filter getFilter(COSName filterName) throws IOException {
108: Filter filter = (Filter) filters.get(filterName);
109: if (filter == null) {
110: throw new IOException("Unknown stream filter:" + filterName);
111: }
112:
113: return filter;
114: }
115:
116: /**
117: * This will get a filter by name.
118: *
119: * @param filterName The name of the filter to retrieve.
120: *
121: * @return The filter that matches the name.
122: *
123: * @throws IOException If the filter could not be found.
124: */
125: public Filter getFilter(String filterName) throws IOException {
126: return getFilter(COSName.getPDFName(filterName));
127: }
128: }
|