cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r917072 - /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java
Date Sat, 27 Feb 2010 23:02:23 GMT
Author: bluk
Date: Sat Feb 27 23:02:23 2010
New Revision: 917072

URL: http://svn.apache.org/viewvc?rev=917072&view=rev
Log:
Update JAX-RS MediaType

Modified:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java?rev=917072&r1=917071&r2=917072&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java (original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java Sat
Feb 27 23:02:23 2010
@@ -19,6 +19,187 @@
 
 package javax.ws.rs.core;
 
+import java.util.Collections;
+import java.util.Map;
+
+import javax.ws.rs.ext.RuntimeDelegate;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
+
 public class MediaType {
+    public static final String                     APPLICATION_ATOM_XML             =
+                                                                                        "application/atom+xml";
+
+    public static final MediaType                  APPLICATION_ATOM_XML_TYPE        =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "atom+xml");
+    public static final String                     APPLICATION_FORM_URLENCODED      =
+                                                                                        "application/x-www-form-urlencoded";
+    public static final MediaType                  APPLICATION_FORM_URLENCODED_TYPE =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "x-www-form-urlencoded");
+    public static final String                     APPLICATION_JSON                 =
+                                                                                        "application/json";
+    public static final MediaType                  APPLICATION_JSON_TYPE            =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "json");
+    public static final String                     APPLICATION_OCTET_STREAM         =
+                                                                                        "application/octet-stream";
+    public static final MediaType                  APPLICATION_OCTET_STREAM_TYPE    =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "octet-stream");
+    public static final String                     APPLICATION_SVG_XML              =
+                                                                                        "application/svg+xml";
+    public static final MediaType                  APPLICATION_SVG_XML_TYPE         =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "svg+xml");
+    public static final String                     APPLICATION_XHTML_XML            =
+                                                                                        "application/xhtml+xml";
+    public static final MediaType                  APPLICATION_XHTML_XML_TYPE       =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "xhtml+xml");
+    public static final String                     APPLICATION_XML                  =
+                                                                                        "application/xml";
+    public static final MediaType                  APPLICATION_XML_TYPE             =
+                                                                                        new
MediaType(
+                                                                                        
             "application",
+                                                                                        
             "xml");
+    public static final String                     MEDIA_TYPE_WILDCARD              = "*";
+    public static final String                     MULTIPART_FORM_DATA              =
+                                                                                        "multipart/form-data";
+    public static final MediaType                  MULTIPART_FORM_DATA_TYPE         =
+                                                                                        new
MediaType(
+                                                                                        
             "multipart",
+                                                                                        
             "form-data");
+    public static final String                     TEXT_HTML                        = "text/html";
+    public static final MediaType                  TEXT_HTML_TYPE                   =
+                                                                                        new
MediaType(
+                                                                                        
             "text",
+                                                                                        
             "html");
+    public static final String                     TEXT_PLAIN                       = "text/plain";
+    public static final MediaType                  TEXT_PLAIN_TYPE                  =
+                                                                                        new
MediaType(
+                                                                                        
             "text",
+                                                                                        
             "plain");
+    public static final String                     TEXT_XML                         = "text/xml";
+    public static final MediaType                  TEXT_XML_TYPE                    =
+                                                                                        new
MediaType(
+                                                                                        
             "text",
+                                                                                        
             "xml");
+    public static final String                     WILDCARD                         = "*/*";
+    public static final MediaType                  WILDCARD_TYPE                    =
+                                                                                        new
MediaType(
+                                                                                        
             "*",
+                                                                                        
             "*");
+
+    private final String                           type;
+    private final String                           subtype;
+    private final Map<String, String>              params;
+
+    private static final HeaderDelegate<MediaType> delegate                       
 =
+                                                                                        RuntimeDelegate
+                                                                                        
   .getInstance()
+                                                                                        
   .createHeaderDelegate(MediaType.class);
+
+    public MediaType(String type, String subtype, Map<String, String> parameters) {
+        if (type == null) {
+            this.type = MEDIA_TYPE_WILDCARD;
+        } else {
+            this.type = type;
+        }
+
+        if (subtype == null) {
+            this.subtype = MEDIA_TYPE_WILDCARD;
+        } else {
+            this.subtype = subtype;
+        }
+
+        if (parameters == null) {
+            this.params = Collections.emptyMap();
+        } else {
+            this.params = Collections.unmodifiableMap(parameters);
+        }
+    }
+
+    public MediaType(String type, String subtype) {
+        this(type, subtype, null);
+    }
+
+    public MediaType() {
+        this(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD);
+    }
+
+    public static MediaType valueOf(String type) throws java.lang.IllegalArgumentException
{
+        return delegate.fromString(type);
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public boolean isWildcardType() {
+        return MEDIA_TYPE_WILDCARD.equals(getType());
+    }
+
+    public String getSubtype() {
+        return subtype;
+    }
+
+    public boolean isWildcardSubtype() {
+        return MEDIA_TYPE_WILDCARD.equals(getSubtype());
+    }
+
+    public Map<String, String> getParameters() {
+        return params;
+    }
+
+    public boolean isCompatible(MediaType other) {
+        if (other == null) {
+            return false;
+        }
+        if (isWildcardType() || other.isWildcardType()) {
+            return true;
+        }
+        if (isWildcardSubtype() || other.isWildcardSubtype()) {
+            return getType().equalsIgnoreCase(other.getType());
+        }
+        return getType().equalsIgnoreCase(other.getType()) && getSubtype().equalsIgnoreCase(other
+            .getSubtype());
+    }
+
+    @Override
+    public boolean equals(java.lang.Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (!(obj instanceof MediaType)) {
+            return false;
+        }
+
+        MediaType other = (MediaType)obj;
+
+        return getType().equalsIgnoreCase(other.getType()) && getSubtype().equalsIgnoreCase(other
+            .getSubtype())
+            && getParameters().equals(other.getParameters());
+    }
+
+    @Override
+    public int hashCode() {
+        int result = 17;
+        result = 31 * result + getType().hashCode();
+        result = 31 * result + getSubtype().hashCode();
+        result = 31 * result + getParameters().hashCode();
+        return result;
+    }
 
+    @Override
+    public String toString() {
+        return delegate.toString(this);
+    }
 }



Mime
View raw message