1 16 package org.apache.cocoon.components.transcoder; 17 18 import org.apache.batik.transcoder.Transcoder; 19 import org.apache.batik.transcoder.image.JPEGTranscoder; 20 import org.apache.batik.transcoder.image.PNGTranscoder; 21 import org.apache.batik.transcoder.image.TIFFTranscoder; 22 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 35 public class ExtendableTranscoderFactory implements TranscoderFactory { 36 37 protected final static Map transcoders = new HashMap (); 38 39 protected final static TranscoderFactory singleton = new ExtendableTranscoderFactory(); 40 41 private ExtendableTranscoderFactory() { 42 addTranscoder("image/jpeg", JPEGTranscoder.class); 44 addTranscoder("image/jpg", JPEGTranscoder.class); 45 addTranscoder("image/png", PNGTranscoder.class); 46 addTranscoder("image/tiff", TIFFTranscoder.class); 47 } 48 49 52 public final static TranscoderFactory getTranscoderFactoryImplementation() { 53 return singleton; 54 } 55 56 61 public Transcoder createTranscoder(String mimeType) { 62 Class transcoderClass = (Class ) transcoders.get(mimeType); 63 if (transcoderClass == null) { 64 return null; 65 } else { 66 try { 67 return (Transcoder) transcoderClass.newInstance(); 68 } catch (Exception ex) { 69 return null; 70 } 71 } 72 } 73 74 80 public void addTranscoder(String mimeType, Class transcoderClass) { 81 transcoders.put(mimeType, transcoderClass); 82 } 83 84 88 public void removeTranscoder(String mimeType) { 89 transcoders.remove(mimeType); 90 } 91 } 92 | Popular Tags |