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 2016/01/28 21:44:58 UTC

svn commit: r1727436 - in /webservices/axiom/branches/1.2.x: ./ axiom-api/src/main/java/org/apache/axiom/mime/ axiom-api/src/test/java/org/apache/axiom/mime/

Author: veithen
Date: Thu Jan 28 20:44:57 2016
New Revision: 1727436

URL: http://svn.apache.org/viewvc?rev=1727436&view=rev
Log:
Merge r1727435 to the 1.2 branch.

Modified:
    webservices/axiom/branches/1.2.x/   (props changed)
    webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java
    webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
    webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java

Propchange: webservices/axiom/branches/1.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 28 20:44:57 2016
@@ -12,4 +12,4 @@
 /webservices/axiom/branches/attrs-aspects:1685218-1686663
 /webservices/axiom/branches/namespaceURIInterning:1293148-1293587
 /webservices/axiom/branches/osgi-redesign:1180368-1180596
-/webservices/axiom/trunk:1726096,1726101,1726474-1726475,1726489,1727220,1727422
+/webservices/axiom/trunk:1726096,1726101,1726474-1726475,1726489,1727220,1727422,1727435

Modified: webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java?rev=1727436&r1=1727435&r2=1727436&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java (original)
+++ webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/ContentTypeTokenizer.java Thu Jan 28 20:44:57 2016
@@ -123,4 +123,10 @@ final class ContentTypeTokenizer {
             throw new ParseException("Unexpected end of string; expected '" + c + "'", index);
         }
     }
+    
+    void requireEndOfString() throws ParseException {
+        if (index != s.length()) {
+            throw new ParseException("Unexpected character '" + s.charAt(index) + "'; expected end of string", index);
+        }
+    }
 }

Modified: webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java?rev=1727436&r1=1727435&r2=1727436&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java (original)
+++ webservices/axiom/branches/1.2.x/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java Thu Jan 28 20:44:57 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.mime;
 
+import java.text.ParseException;
+
 /**
  * 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.
@@ -71,6 +73,22 @@ public final class MediaType {
     }
 
     /**
+     * Constructor that parses a media type.
+     * 
+     * @param type
+     *            the media type to parse
+     * @throws ParseException
+     *             if the value is invalid and could not be parsed
+     */
+    public MediaType(String type) throws ParseException {
+        ContentTypeTokenizer tokenizer = new ContentTypeTokenizer(type);
+        primaryType = tokenizer.requireToken();
+        tokenizer.require('/');
+        subType = tokenizer.requireToken();
+        tokenizer.requireEndOfString();
+    }
+
+    /**
      * Get the primary type.
      * 
      * @return the primary type

Modified: webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java?rev=1727436&r1=1727435&r2=1727436&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java (original)
+++ webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java Thu Jan 28 20:44:57 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.mime;
 
+import java.text.ParseException;
+
 import junit.framework.TestCase;
 
 public class MediaTypeTest extends TestCase {
@@ -66,4 +68,28 @@ public class MediaTypeTest extends TestC
         MediaType mt = new MediaType("application", "octet-stream");
         assertEquals("application/octet-stream", mt.toString());
     }
+
+    public void testParse() throws Exception {
+        MediaType mt = new MediaType("application/octet-stream");
+        assertEquals("application", mt.getPrimaryType());
+        assertEquals("octet-stream", mt.getSubType());
+    }
+
+    public void testParseInvalid1() {
+        try {
+            new MediaType("text/");
+            fail("Expected ParseException");
+        } catch (ParseException ex) {
+            // Expected
+        }
+    }
+
+    public void testParseInvalid2() {
+        try {
+            new MediaType("text/xml;");
+            fail("Expected ParseException");
+        } catch (ParseException ex) {
+            // Expected
+        }
+    }
 }