You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/07/30 16:36:29 UTC

svn commit: r1508468 - in /webservices/axiom/trunk: axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/ modules/axiom-api/src/main/java/org/apache/axiom/attachments/ modules/axiom-api/src/main/java/org/apache/axiom/mime/ modules/axiom-api/sr...

Author: veithen
Date: Tue Jul 30 14:36:28 2013
New Revision: 1508468

URL: http://svn.apache.org/r1508468
Log:
AXIOM-418: Added a replacement for the JavaMail ContentType class.

Added:
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java   (with props)
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java   (with props)
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java   (with props)
    webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java   (with props)
    webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java   (with props)
Modified:
    webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
    webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/om/MIMEResource.java

Modified: webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java (original)
+++ webservices/axiom/trunk/axiom-spring-ws/src/main/java/org/apache/axiom/spring/ws/soap/AxiomSoapMessageFactory.java Tue Jul 30 14:36:28 2013
@@ -20,11 +20,10 @@ package org.apache.axiom.spring.ws.soap;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.ParseException;
 import java.util.Iterator;
 
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
-
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLBuilderFactory;
@@ -72,7 +71,6 @@ public class AxiomSoapMessageFactory imp
         Iterator<String> it = transportInputStream.getHeaders(TransportConstants.HEADER_CONTENT_TYPE);
         ContentType contentType;
         if (it.hasNext()) {
-            // TODO: this depends on javamail!
             try {
                 contentType = new ContentType(it.next());
             } catch (ParseException ex) {

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java Tue Jul 30 14:36:28 2013
@@ -26,9 +26,9 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.activation.DataHandler;
-import javax.mail.internet.ContentType;
 
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMException;
 
 /**

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java Tue Jul 30 14:36:28 2013
@@ -22,13 +22,13 @@ package org.apache.axiom.attachments;
 import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
 import org.apache.axiom.ext.activation.SizeAwareDataSource;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMAttachmentAccessor;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.MTOMConstants;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
-import javax.mail.internet.ContentType;
 
 import java.io.IOException;
 import java.io.InputStream;

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java Tue Jul 30 14:36:28 2013
@@ -24,9 +24,9 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.activation.DataHandler;
-import javax.mail.internet.ContentType;
 
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.OMException;
 
 /**

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Tue Jul 30 14:36:28 2013
@@ -20,6 +20,7 @@ package org.apache.axiom.attachments;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
@@ -28,12 +29,11 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.activation.DataHandler;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
 
 import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
 import org.apache.axiom.attachments.lifecycle.impl.LifecycleManagerImpl;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.mime.Header;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.util.DetachableInputStream;

Added: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java?rev=1508468&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java (added)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java Tue Jul 30 14:36:28 2013
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.mime;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.activation.MimeType;
+
+/**
+ * Represents the (parsed) value of a <tt>Content-Type</tt> header as defined by
+ * <a href="http://tools.ietf.org/html/rfc2045">RFC 2045</a>.
+ * <p>
+ * The relevant productions from RFC 2045 and RFC 822 are:
+ * <pre>
+ * content := "Content-Type" ":" type "/" subtype *(";" parameter)
+ * parameter := attribute "=" value
+ * attribute := token
+ * value := token / quoted-string
+ * token := 1*&lt;any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>
+ * tspecials := "(" / ")" / "&lt;" / ">" / "@" / "," / ";" / ":" / "\" / &lt;"> / "/" / "[" / "]" / "?" / "="
+ * quoted-string := &lt;"> *(qtext/quoted-pair) &lt;">
+ * qtext := &lt;any CHAR excepting &lt;">, "\" & CR, and including linear-white-space>
+ * quoted-pair := "\" CHAR
+ * </pre>
+ * <p>
+ * This class is similar to {@link MimeType} and JavaMail's <code>ContentType</code> class, but the
+ * following differences exist:
+ * <ul>
+ * <li>This class is more lenient than (the reference implementation of) {@link MimeType}. It will
+ * accept content types that are not strictly valid, but that are commonly found. E.g. it will
+ * accept content types with an extra semicolon at the end.
+ * <li>This class is immutable.
+ * <li>This class makes a distinction between a media type (which is defined by a primary type and a
+ * sub type and represented by a {@link MediaType} object) and a content type, which is defined by a
+ * media type and a set of parameters.
+ * </ul>
+ * <p>
+ * Another reason for the existence of this class is to avoid a dependency on JavaMail. 
+ * <p>
+ * Note that this class doesn't override {@link Object#equals(Object)} because there is no
+ * meaningful way to compare content types with parameters.
+ */
+// TODO: this class should override toString, but we don't need it yet...
+public final class ContentType {
+    private final MediaType mediaType;
+    private final String[] parameters;
+    
+    /**
+     * Constructor.
+     * 
+     * @param mediaType
+     *            the media type
+     * @param parameters
+     *            an array specifying the parameters as name/value pairs (with even entries
+     *            representing the parameter names, and odd entries the corresponding values)
+     */
+    public ContentType(MediaType mediaType, String[] parameters) {
+        this.mediaType = mediaType;
+        this.parameters = (String[])parameters.clone();
+    }
+
+    /**
+     * Constructor that parses a <tt>Content-Type</tt> header value.
+     * 
+     * @param type
+     *            the value of the <tt>Content-Type</tt> header conforming to RFC 2045
+     * @throws ParseException
+     *             if the value is invalid and could not be parsed
+     */
+    public ContentType(String type) throws ParseException {
+        ContentTypeTokenizer tokenizer = new ContentTypeTokenizer(type);
+        String primaryType = tokenizer.requireToken();
+        tokenizer.require('/');
+        String subType = tokenizer.requireToken();
+        mediaType = new MediaType(primaryType, subType);
+        List parameters = new ArrayList();
+        while (tokenizer.expect(';')) {
+            String name = tokenizer.expectToken();
+            if (name == null) {
+                // If we get here, then there was an extra ';' at the end of the value.
+                // This is not allowed by RFC 2045, but we are lenient.
+                break;
+            }
+            parameters.add(name);
+            tokenizer.require('=');
+            parameters.add(tokenizer.requireTokenOrQuotedString());
+        }
+        this.parameters = (String[])parameters.toArray(new String[parameters.size()]);
+    }
+    
+    /**
+     * Get the media type this content type refers to.
+     * 
+     * @return the media type
+     */
+    public MediaType getMediaType() {
+        return mediaType;
+    }
+
+    /**
+     * Get the specified parameter value.
+     * 
+     * @param name
+     *            the parameter name
+     * @return the parameter value, or <code>null</code> if no parameter with the given name was
+     *         found
+     */
+    public String getParameter(String name) {
+        for (int i=0; i<parameters.length; i+=2) {
+            if (name.equalsIgnoreCase(parameters[i])) {
+                return parameters[i+1];
+            }
+        }
+        return null;
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java?rev=1508468&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java (added)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java Tue Jul 30 14:36:28 2013
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.mime;
+
+import java.text.ParseException;
+
+final class ContentTypeTokenizer {
+    // Note: normally only ' ' and '\t' can appear in unfolded header values, but we accept parsing folded values
+    private static final String whitespace = " \t\n\r";
+    
+    private static final String tspecials = "()<>@,;:\\\"/[]?=";
+    
+    private final String s;
+    private int index;
+
+    public ContentTypeTokenizer(String s) {
+        this.s = s;
+    }
+
+    private void skipWhiteSpace() {
+        for (int len = s.length(); index < len && whitespace.indexOf(s.charAt(index)) != -1; index++) {
+            // Just loop
+        }
+    }
+
+    String expectToken() throws ParseException {
+        skipWhiteSpace();
+        int begin = index;
+        for (int len = s.length(); index < len && tspecials.indexOf(s.charAt(index)) == -1; index++) {
+            // Just loop
+        }
+        int end = index;
+        skipWhiteSpace();
+        for (; end > begin && whitespace.indexOf(s.charAt(end-1)) != -1; end--) {
+            // Just loop
+        }
+        if (begin == end) {
+            if (index == s.length()) {
+                return null;
+            } else {
+                throw new ParseException("Expected token, but found '" + s.charAt(index) + "'", index);
+            }
+        } else {
+            return s.substring(begin, end);
+        }
+    }
+    
+    String requireToken() throws ParseException {
+        String token = expectToken();
+        if (token == null) {
+            throw new ParseException("Token expected", index);
+        }
+        return token;
+    }
+
+    String requireTokenOrQuotedString() throws ParseException {
+        skipWhiteSpace();
+        int len = s.length();
+        if (index < len) {
+            if (s.charAt(index) == '\"') {
+                StringBuffer sb = new StringBuffer();
+                index++;
+                for (; index < len; index++) {
+                    char c = s.charAt(index);
+                    if (c == '\\') {
+                        index++;
+                        if (index == len) {
+                            throw new ParseException("Expected more input after escape character", index);
+                        }
+                        sb.append(s.charAt(index));
+                    } else if (c == '\"') {
+                        break;
+                    } else {
+                        sb.append(c);
+                    }
+                }
+                if (index == len) {
+                    throw new ParseException("Unclosed quoted string", index);
+                }
+                // If we get here, then the current character is a quote; skip it
+                index++;
+                skipWhiteSpace();
+                return sb.toString();
+            } else {
+                return requireToken();
+            }
+        }
+        return null;
+    }
+
+    int getChar() {
+        return index == s.length() ? -1 : s.charAt(index++);
+    }
+
+    boolean expect(char c) throws ParseException {
+        if (index == s.length()) {
+            return false;
+        } else {
+            char actual = s.charAt(index);
+            if (actual == c) {
+                index++;
+                return true;
+            } else {
+                throw new ParseException("Expected '" + c + "' instead of '" + actual + "'", index);
+            }
+        }
+    }
+    
+    void require(char c) throws ParseException {
+        if (!expect(c)) {
+            throw new ParseException("Unexpected end of string; expected '" + c + "'", index);
+        }
+    }
+    
+    boolean hasMoreTokens() {
+        return index < s.length();
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java?rev=1508468&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java (added)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java Tue Jul 30 14:36:28 2013
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.mime;
+
+/**
+ * Represents a media type as defined by <a href="http://tools.ietf.org/html/rfc2045">RFC 2045</a>
+ * and <a href="http://tools.ietf.org/html/rfc2046">RFC 2046</a>. It specifies a primary type (e.g.
+ * <tt>text</tt>) and a subtype (e.g. <tt>xml</tt>). Note that in RFC 2045, "media type" refers to
+ * what is called "primary type" here, while this class uses "media type" to refer to the
+ * combination of primary and subtype.
+ * <p>
+ * This class is immutable. It overrides {@link Object#equals(Object)} and {@link Object#hashCode()}
+ * to allow comparing media types as described by RFC 2045, i.e. in a case insensitive way.
+ */
+public final class MediaType {
+    private final String primaryType;
+    private final String subType;
+    
+    /**
+     * Constructor.
+     * 
+     * @param primaryType
+     *            the primary type
+     * @param subType
+     *            the subtype
+     */
+    public MediaType(String primaryType, String subType) {
+        this.primaryType = primaryType;
+        this.subType = subType;
+    }
+
+    /**
+     * Get the primary type.
+     * 
+     * @return the primary type
+     */
+    public String getPrimaryType() {
+        return primaryType;
+    }
+
+    /**
+     * Get the subtype.
+     * 
+     * @return the subtype
+     */
+    public String getSubType() {
+        return subType;
+    }
+
+    public int hashCode() {
+        int hash = 0;
+        for (int i=0, l=primaryType.length(); i<l; i++) {
+            hash = 31*hash + Character.toLowerCase(primaryType.charAt(i));
+        }
+        hash *= 31;
+        for (int i=0, l=subType.length(); i<l; i++) {
+            hash = 31*hash + Character.toLowerCase(subType.charAt(i));
+        }
+        return hash;
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof MediaType) {
+            MediaType other = (MediaType)obj;
+            return primaryType.equalsIgnoreCase(other.primaryType) && subType.equalsIgnoreCase(other.subType);
+        } else {
+            return false;
+        }
+    }
+
+    public String toString() {
+        return primaryType + "/" + subType;
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Tue Jul 30 14:36:28 2013
@@ -20,15 +20,15 @@ package org.apache.axiom.om;
 
 import java.io.InputStream;
 import java.io.Reader;
+import java.text.ParseException;
 
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.sax.SAXSource;
 
 import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.mime.ContentType;
 import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;

Added: webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java?rev=1508468&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java (added)
+++ webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java Tue Jul 30 14:36:28 2013
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.mime;
+
+import junit.framework.TestCase;
+
+public class ContentTypeTest extends TestCase {
+    public void testImmutable() {
+        String[] parameters = { "charset", "utf-8" };
+        ContentType ct = new ContentType(new MediaType("text", "xml"), parameters);
+        parameters[1] = "ascii";
+        assertEquals("utf-8", ct.getParameter("charset"));
+    }
+    
+    public void testGetParameterIgnoresCase() {
+        ContentType ct = new ContentType(new MediaType("text", "xml"), new String[] { "charset", "utf-8" });
+        assertEquals("utf-8", ct.getParameter("CHARSET"));
+    }
+    
+    public void testParse() throws Exception {
+        ContentType ct = new ContentType("multipart/related; "
+                + "boundary=\"boundaryA3ADBAEE51A1A87B2A11443668160701\"; "
+                + "type=\"application/xop+xml\"; "
+                + "start=\"<A3...@apache.org>\"; "
+                + "start-info=\"application/soap+xml\"; "
+                + "charset=UTF-8;"
+                + "action=\"urn:myAction\"");
+        assertEquals(new MediaType("multipart", "related"), ct.getMediaType());
+        assertEquals("boundaryA3ADBAEE51A1A87B2A11443668160701", ct.getParameter("boundary"));
+        assertEquals("application/xop+xml", ct.getParameter("type"));
+        assertEquals("<A3...@apache.org>", ct.getParameter("start"));
+        assertEquals("application/soap+xml", ct.getParameter("start-info"));
+        assertEquals("UTF-8", ct.getParameter("charset"));
+        assertEquals("urn:myAction", ct.getParameter("action"));
+    }
+    
+    public void testParseWithExtraSemicolon() throws Exception {
+        ContentType ct = new ContentType("text/xml; charset=utf-8;");
+        assertEquals(new MediaType("text", "xml"), ct.getMediaType());
+        assertEquals("utf-8", ct.getParameter("charset"));
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java?rev=1508468&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java (added)
+++ webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java Tue Jul 30 14:36:28 2013
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axiom.mime;
+
+import junit.framework.TestCase;
+
+public class MediaTypeTest extends TestCase {
+    public void testBasic() {
+        MediaType mt = new MediaType("text", "xml");
+        assertEquals("text", mt.getPrimaryType());
+        assertEquals("xml", mt.getSubType());
+    }
+    
+    public void testEquals() {
+        MediaType mt1 = new MediaType("text", "xml");
+        MediaType mt2 = new MediaType("text", "xml");
+        MediaType mt3 = new MediaType("text", "plain");
+        MediaType mt4 = new MediaType("application", "xml");
+        assertTrue(mt1.equals(mt2));
+        assertFalse(mt1.equals(mt3));
+        assertFalse(mt1.equals(mt4));
+        assertFalse(mt3.equals(mt4));
+    }
+    
+    public void testEqualsIgnoresCase() {
+        MediaType mt1 = new MediaType("text", "xml");
+        MediaType mt2 = new MediaType("TEXT", "XML");
+        assertTrue(mt1.equals(mt2));
+    }
+    
+    public void testHashCode() {
+        MediaType mt1 = new MediaType("text", "xml");
+        MediaType mt2 = new MediaType("text", "xml");
+        MediaType mt3 = new MediaType("text", "plain");
+        MediaType mt4 = new MediaType("application", "xml");
+        assertTrue(mt1.hashCode() == mt2.hashCode());
+        assertFalse(mt1.hashCode() == mt3.hashCode());
+        assertFalse(mt1.hashCode() == mt4.hashCode());
+        assertFalse(mt3.hashCode() == mt4.hashCode());
+    }
+
+    public void testHashCodeIgnoresCase() {
+        MediaType mt1 = new MediaType("text", "xml");
+        MediaType mt2 = new MediaType("TEXT", "XML");
+        assertTrue(mt1.hashCode() == mt2.hashCode());
+    }
+    
+    public void testToString() {
+        MediaType mt = new MediaType("application", "octet-stream");
+        assertEquals("application/octet-stream", mt.toString());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/om/MIMEResource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/om/MIMEResource.java?rev=1508468&r1=1508467&r2=1508468&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/om/MIMEResource.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/om/MIMEResource.java Tue Jul 30 14:36:28 2013
@@ -18,8 +18,9 @@
  */
 package org.apache.axiom.om;
 
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
+import java.text.ParseException;
+
+import org.apache.axiom.mime.ContentType;
 
 public class MIMEResource {
     private final String name;