KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > engine > image > ImageFileMediaPublisher


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.media.engine.image;
8
9 import java.awt.image.BufferedImage JavaDoc;
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Vector JavaDoc;
14
15 import javax.imageio.ImageIO JavaDoc;
16
17 import org.jboss.media.engine.MediaPluginGraph;
18 import org.jboss.media.engine.MediaPublisher;
19 import org.jboss.media.engine.MediaPublisherMBean;
20
21 /**
22  * @version <tt>$Revision: 1.1 $</tt>
23  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
24  * @jmx.mbean extends="org.jboss.media.engine.MediaPublisherMBean"
25  */

26 public class ImageFileMediaPublisher
27    extends MediaPublisher
28    implements MediaPublisherMBean, ImageFileMediaPublisherMBean
29 {
30    MediaPluginGraph m_graph;
31
32    public ImageFileMediaPublisher()
33    {
34       // DO NOTHING
35
}
36
37    /* (non-Javadoc)
38     * @see org.jboss.media.engine.MediaPublisher#publish()
39     */

40    public void publish() throws Exception JavaDoc
41    {
42       log.info("Reading file " + getFileName());
43       BufferedImage JavaDoc image = null;
44       try
45       {
46          File JavaDoc imgFile = new File JavaDoc(getFileName());
47          image = (BufferedImage JavaDoc) ImageIO.read(imgFile);
48       }
49       catch (IOException JavaDoc 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 JavaDoc outputFile = new File JavaDoc(getContext());
61       String JavaDoc suffix = getContext().substring(getContext().length()-3,getContext().length());
62       log.info("Suffix is ." + suffix);
63       ImageIO.write(image, suffix, outputFile);
64
65    }
66
67    /**
68     * @param image
69     * @return
70     */

71    private void processImage(BufferedImage JavaDoc image)
72    {
73       Vector JavaDoc plugins = m_graph.getPluginVector();
74       for (Iterator JavaDoc iter = plugins.iterator(); iter.hasNext();)
75       {
76          ImagePluginSupport element = (ImagePluginSupport) iter.next();
77
78          element.process(image);
79
80       }
81
82    }
83
84    /* (non-Javadoc)
85     * @see org.jboss.media.engine.MediaPublisher#stop()
86     */

87    public void stop()
88    {
89
90    }
91
92    /* (non-Javadoc)
93     * @see org.jboss.media.engine.MediaPublisher#addPluginGraph(org.jboss.media.engine.MediaPluginGraph)
94     */

95    public void addPluginGraph(MediaPluginGraph pg)
96    {
97       m_graph = pg;
98    }
99
100 }
101
Popular Tags