You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jb...@apache.org on 2005/02/17 20:33:35 UTC
svn commit: r154179 - in geronimo/trunk/modules/activation/src:
java/org/apache/geronimo/activation/handlers/ resources/META-INF/
test/org/apache/geronimo/activation/handlers/
Author: jboynes
Date: Thu Feb 17 11:33:33 2005
New Revision: 154179
URL: http://svn.apache.org/viewcvs?view=rev&rev=154179
Log:
add image handlers
Added:
geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/AbstractImageHandler.java
geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageGifHandler.java
geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageJpegHandler.java
geronimo/trunk/modules/activation/src/test/org/apache/geronimo/activation/handlers/MailcapTest.java
Modified:
geronimo/trunk/modules/activation/src/resources/META-INF/mailcap
Added: geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/AbstractImageHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/AbstractImageHandler.java?view=auto&rev=154179
==============================================================================
--- geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/AbstractImageHandler.java (added)
+++ geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/AbstractImageHandler.java Thu Feb 17 11:33:33 2005
@@ -0,0 +1,87 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.activation.handlers;
+
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.activation.UnsupportedDataTypeException;
+import javax.imageio.IIOImage;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractImageHandler implements DataContentHandler {
+ private final DataFlavor flavour;
+
+ public AbstractImageHandler(DataFlavor flavour) {
+ this.flavour = flavour;
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[]{flavour};
+ }
+
+ public Object getTransferData(DataFlavor dataFlavor, DataSource dataSource) throws UnsupportedFlavorException, IOException {
+ return flavour.equals(dataFlavor) ? getContent(dataSource) : null;
+ }
+
+ public Object getContent(DataSource ds) throws IOException {
+ Iterator i = ImageIO.getImageReadersByMIMEType(ds.getContentType());
+ if (!i.hasNext()) {
+ throw new UnsupportedDataTypeException();
+ }
+ ImageReader reader = (ImageReader) i.next();
+ return reader.read(0);
+ }
+
+ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
+ Iterator i = ImageIO.getImageWritersByMIMEType(mimeType);
+ if (!i.hasNext()) {
+ throw new UnsupportedDataTypeException();
+ }
+ ImageWriter writer = (ImageWriter) i.next();
+ writer.setOutput(os);
+
+ if (obj instanceof RenderedImage) {
+ writer.write((RenderedImage) obj);
+ } else if (obj instanceof BufferedImage) {
+ BufferedImage buffered = (BufferedImage) obj;
+ writer.write(new IIOImage(buffered.getRaster(), null, null));
+ } else if (obj instanceof Image) {
+ Image image = (Image) obj;
+ BufferedImage buffered = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
+ Graphics2D graphics = buffered.createGraphics();
+ graphics.drawImage(image, 0, 0, null, null);
+ writer.write(new IIOImage(buffered.getRaster(), null, null));
+ } else {
+ throw new UnsupportedDataTypeException();
+ }
+ os.flush();
+ }
+}
Added: geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageGifHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageGifHandler.java?view=auto&rev=154179
==============================================================================
--- geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageGifHandler.java (added)
+++ geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageGifHandler.java Thu Feb 17 11:33:33 2005
@@ -0,0 +1,29 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.activation.handlers;
+
+import java.awt.Image;
+import javax.activation.ActivationDataFlavor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImageGifHandler extends AbstractImageHandler {
+ public ImageGifHandler() {
+ super(new ActivationDataFlavor(Image.class, "image/gif", "GIF Image"));
+ }
+}
Added: geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageJpegHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageJpegHandler.java?view=auto&rev=154179
==============================================================================
--- geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageJpegHandler.java (added)
+++ geronimo/trunk/modules/activation/src/java/org/apache/geronimo/activation/handlers/ImageJpegHandler.java Thu Feb 17 11:33:33 2005
@@ -0,0 +1,29 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.activation.handlers;
+
+import java.awt.Image;
+import javax.activation.ActivationDataFlavor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImageJpegHandler extends AbstractImageHandler {
+ public ImageJpegHandler() {
+ super(new ActivationDataFlavor(Image.class, "image/jpeg", "JPEG Image"));
+ }
+}
Modified: geronimo/trunk/modules/activation/src/resources/META-INF/mailcap
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/activation/src/resources/META-INF/mailcap?view=diff&r1=154178&r2=154179
==============================================================================
--- geronimo/trunk/modules/activation/src/resources/META-INF/mailcap (original)
+++ geronimo/trunk/modules/activation/src/resources/META-INF/mailcap Thu Feb 17 11:33:33 2005
@@ -13,9 +13,13 @@
## See the License for the specific language governing permissions and
## limitations under the License.
##
-## $Rev: 47137 $ $Date: 2004-09-24 00:04:29 -0700 (Fri, 24 Sep 2004) $
+## $Rev$ $Date$
##
text/plain;; x-java-content-handler=org.apache.geronimo.activation.handlers.TextPlainHandler
-text/html;; x-java-content-handler=org.apache.geronimo.activation.handlers.TextHtmlHandler
-text/xml;; x-java-content-handler=org.apache.geronimo.activation.handlers.TextXmlHandler
+text/html;; x-java-content-handler=org.apache.geronimo.activation.handlers.TextHtmlHandler
+text/xml;; x-java-content-handler=org.apache.geronimo.activation.handlers.TextXmlHandler
+
+image/gif;; x-java-content-handler=org.apache.geronimo.activation.handlers.ImageGifHandler
+image/jpeg;; x-java-content-handler=org.apache.geronimo.activation.handlers.ImageJpegHandler
+
\ No newline at end of file
Added: geronimo/trunk/modules/activation/src/test/org/apache/geronimo/activation/handlers/MailcapTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/activation/src/test/org/apache/geronimo/activation/handlers/MailcapTest.java?view=auto&rev=154179
==============================================================================
--- geronimo/trunk/modules/activation/src/test/org/apache/geronimo/activation/handlers/MailcapTest.java (added)
+++ geronimo/trunk/modules/activation/src/test/org/apache/geronimo/activation/handlers/MailcapTest.java Thu Feb 17 11:33:33 2005
@@ -0,0 +1,42 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.activation.handlers;
+
+import java.io.InputStream;
+import javax.activation.CommandMap;
+import javax.activation.MailcapCommandMap;
+import javax.activation.CommandInfo;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MailcapTest extends TestCase {
+ private CommandMap map;
+
+ public void testTextPlainHandler() {
+ CommandInfo info = map.getCommand("text/plain", "content-handler");
+ assertEquals(TextPlainHandler.class.getName(), info.getCommandClass());
+ }
+
+ protected void setUp() throws Exception {
+ InputStream is = TextPlainHandler.class.getClassLoader().getResourceAsStream("META-INF/mailcap");
+ map = new MailcapCommandMap(is);
+ is.close();
+ }
+}