1 51 package org.apache.fop.image.analyser; 52 53 import java.io.InputStream ; 55 import java.io.BufferedInputStream ; 56 import java.io.IOException ; 57 import java.util.List ; 58 59 import org.apache.fop.image.FopImageException; 61 62 66 public class ImageReaderFactory { 67 protected static List formats = null; 68 69 static { 70 71 formats = new java.util.Vector (); 72 try { 73 registerImageReader("org.apache.fop.image.analyser.JPEGReader"); 74 registerImageReader("org.apache.fop.image.analyser.BMPReader"); 75 registerImageReader("org.apache.fop.image.analyser.GIFReader"); 76 registerImageReader("org.apache.fop.image.analyser.PNGReader"); 77 registerImageReader("org.apache.fop.image.analyser.TIFFReader"); 78 registerImageReader("org.apache.fop.image.analyser.EPSReader"); 79 registerImageReader("org.apache.fop.image.analyser.SVGReader"); 80 } catch (ClassNotFoundException cnfe) { 81 throw new RuntimeException ("One of the default ImageReader implementations is not available: "+cnfe.getMessage()); 82 } 83 } 84 85 91 public static void registerImageReader(String classname) throws ClassNotFoundException { 92 Class clazz = Class.forName(classname); 93 registerImageReader(clazz); 94 } 95 96 97 102 public static void registerImageReader(Class clazz) { 103 if (!ImageReader.class.isAssignableFrom(clazz)) throw new RuntimeException ("This class does not implement the ImageReader interface: "+clazz.getName()); 104 formats.add(clazz); 105 } 106 107 116 public static ImageReader Make(String uri, 117 InputStream in) throws FopImageException { 118 119 ImageReader reader; 120 BufferedInputStream bis = new BufferedInputStream (in); 121 try { 122 for (int i = 0; i< formats.size(); i++) { 123 Class clazz = (Class )formats.get(i); 124 try { 125 reader = (ImageReader)clazz.newInstance(); 126 } catch (Exception e) { 127 throw new FopImageException("ImageReader implementation cannot be instantiated: "+e.getMessage()); 128 } 129 if (reader.verifySignature(uri, bis)) { 130 return reader; 131 } 132 } 133 } catch (IOException ex) { 134 throw new FopImageException(ex.getMessage()); 135 } 136 return null; 137 } 138 139 } 140 141 | Popular Tags |