1 7 package org.jboss.media.engine.image; 8 9 import java.awt.image.BufferedImage ; 10 import java.io.File ; 11 import java.io.IOException ; 12 import java.util.Iterator ; 13 import java.util.Vector ; 14 15 import javax.imageio.ImageIO ; 16 17 import org.jboss.media.engine.MediaPluginGraph; 18 import org.jboss.media.engine.MediaPublisher; 19 import org.jboss.media.engine.MediaPublisherMBean; 20 21 26 public class ImageFileMediaPublisher 27 extends MediaPublisher 28 implements MediaPublisherMBean, ImageFileMediaPublisherMBean 29 { 30 MediaPluginGraph m_graph; 31 32 public ImageFileMediaPublisher() 33 { 34 } 36 37 40 public void publish() throws Exception 41 { 42 log.info("Reading file " + getFileName()); 43 BufferedImage image = null; 44 try 45 { 46 File imgFile = new File (getFileName()); 47 image = (BufferedImage ) ImageIO.read(imgFile); 48 } 49 catch (IOException e) 50 { 51 log.error("Could not read file " + getFileName()); 52 return; 53 } 54 55 log.info("processing image..."); 56 processImage(image); 57 log.info("Finished processing image"); 58 59 log.info("Sending the output to file " + getContext()); 60 File outputFile = new File (getContext()); 61 String suffix = getContext().substring(getContext().length()-3,getContext().length()); 62 log.info("Suffix is ." + suffix); 63 ImageIO.write(image, suffix, outputFile); 64 65 } 66 67 71 private void processImage(BufferedImage image) 72 { 73 Vector plugins = m_graph.getPluginVector(); 74 for (Iterator iter = plugins.iterator(); iter.hasNext();) 75 { 76 ImagePluginSupport element = (ImagePluginSupport) iter.next(); 77 78 element.process(image); 79 80 } 81 82 } 83 84 87 public void stop() 88 { 89 90 } 91 92 95 public void addPluginGraph(MediaPluginGraph pg) 96 { 97 m_graph = pg; 98 } 99 100 } 101 | Popular Tags |