geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r219279 - in /geronimo/trunk/specs/javamail/src: java/org/ java/org/apache/ java/org/apache/geronimo/ java/org/apache/geronimo/mail/ java/org/apache/geronimo/mail/handlers/ resources/ resources/META-INF/
Date Sat, 16 Jul 2005 02:37:00 GMT
Author: dims
Date: Fri Jul 15 19:36:59 2005
New Revision: 219279

URL: http://svn.apache.org/viewcvs?rev=219279&view=rev
Log:
adding a handlers for text and xml in the mailcap file


Added:
    geronimo/trunk/specs/javamail/src/java/org/
    geronimo/trunk/specs/javamail/src/java/org/apache/
    geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/
    geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/
    geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/
    geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java
  (with props)
    geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java
  (with props)
    geronimo/trunk/specs/javamail/src/resources/
    geronimo/trunk/specs/javamail/src/resources/META-INF/
    geronimo/trunk/specs/javamail/src/resources/META-INF/mailcap

Added: geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java?rev=219279&view=auto
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java
(added)
+++ geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java
Fri Jul 15 19:36:59 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2004,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.mail.handlers;
+
+import javax.activation.ActivationDataFlavor;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.MimeUtility;
+import javax.mail.internet.ParseException;
+import java.awt.datatransfer.DataFlavor;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+
+public class TextHandler implements DataContentHandler {
+    /**
+     * Field dataFlavor
+     */
+    ActivationDataFlavor dataFlavor;
+
+    public TextHandler(){
+        dataFlavor = new ActivationDataFlavor(java.lang.String.class, "text/plain", "Text");
+    }
+
+    /**
+     * Constructor TextHandler
+     *
+     * @param dataFlavor
+     */
+    public TextHandler(ActivationDataFlavor dataFlavor) {
+        this.dataFlavor = dataFlavor;
+    }
+
+    /**
+     * Method getDF
+     *
+     * @return dataflavor
+     */
+    protected ActivationDataFlavor getDF() {
+        return dataFlavor;
+    }
+
+    /**
+     * Method getTransferDataFlavors
+     *
+     * @return dataflavors
+     */
+    public DataFlavor[] getTransferDataFlavors() {
+        return (new DataFlavor[]{dataFlavor});
+    }
+
+    /**
+     * Method getTransferData
+     *
+     * @param dataflavor
+     * @param datasource
+     * @return
+     * @throws IOException
+     */
+    public Object getTransferData(DataFlavor dataflavor, DataSource datasource)
+            throws IOException {
+        if (getDF().equals(dataflavor)) {
+            return getContent(datasource);
+        }
+        return null;
+    }
+
+    /**
+     * Method getContent
+     *
+     * @param datasource
+     * @return
+     * @throws IOException
+     */
+    public Object getContent(DataSource datasource) throws IOException {
+        InputStreamReader reader;
+        try {
+            String s = getCharSet(datasource.getContentType());
+            reader = new InputStreamReader(datasource.getInputStream(), s);
+        } catch (Exception ex) {
+            throw new UnsupportedEncodingException(ex.toString());
+        }
+        StringWriter writer = new StringWriter();
+        int ch;
+        while ((ch = reader.read()) != -1) {
+            writer.write(ch);
+        }
+        return writer.getBuffer().toString();
+    }
+
+    /**
+     * Method writeTo
+     *
+     * @param object
+     * @param s
+     * @param outputstream
+     * @throws IOException
+     */
+    public void writeTo(Object object, String s, OutputStream outputstream)
+            throws IOException {
+        OutputStreamWriter os;
+        try {
+            String charset = getCharSet(s);
+            os = new OutputStreamWriter(outputstream, charset);
+        } catch (Exception ex) {
+            throw new UnsupportedEncodingException(ex.toString());
+        }
+        String content = (String) object;
+        os.write(content, 0, content.length());
+        os.flush();
+    }
+
+    /**
+     * get the character set from content type
+     * @param contentType
+     * @return
+     * @throws ParseException
+     */
+    protected String getCharSet(String contentType) throws ParseException {
+        ContentType type = new ContentType(contentType);
+        String charset = type.getParameter("charset");
+        if (charset == null) {
+            charset = "us-ascii";
+        }
+        return MimeUtility.javaCharset(charset);
+    }
+}

Propchange: geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/TextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java?rev=219279&view=auto
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java
(added)
+++ geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java
Fri Jul 15 19:36:59 2005
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2004,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.mail.handlers;
+
+import javax.activation.ActivationDataFlavor;
+
+public class XMLHandler extends TextHandler {
+    public XMLHandler() {
+        super(new ActivationDataFlavor(java.lang.String.class, "text/xml", "XML"));
+    }
+}

Propchange: geronimo/trunk/specs/javamail/src/java/org/apache/geronimo/mail/handlers/XMLHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/specs/javamail/src/resources/META-INF/mailcap
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/resources/META-INF/mailcap?rev=219279&view=auto
==============================================================================
--- geronimo/trunk/specs/javamail/src/resources/META-INF/mailcap (added)
+++ geronimo/trunk/specs/javamail/src/resources/META-INF/mailcap Fri Jul 15 19:36:59 2005
@@ -0,0 +1,2 @@
+text/plain;;		x-java-content-handler=org.apache.geronimo.mail.handlers.TextHandler
+text/xml;;		x-java-content-handler=org.apache.geronimo.mail.handlers.XMLHandler



Mime
View raw message