Author: julien(a)jboss.com
Date: 2008-03-18 18:44:34 -0400 (Tue, 18 Mar 2008)
New Revision: 10319
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java
Log:
added factory method with media type name on media type class
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-18
22:27:37 UTC (rev 10318)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media/MediaType.java 2008-03-18
22:44:34 UTC (rev 10319)
@@ -56,6 +56,22 @@
/** . */
private volatile String value;
+ public static MediaType create(String mediaTypeName)
+ {
+ int slashIndex = mediaTypeName.indexOf('/');
+ if (slashIndex == -1)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String typeName = mediaTypeName.substring(0, slashIndex);
+ String subtypeName = mediaTypeName.substring(slashIndex + 1);
+
+ //
+ return create(typeName, subtypeName);
+ }
+
public static MediaType create(String typeName, String subtypeName)
{
TypeDef type = TypeDef.create(typeName);
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java 2008-03-18
22:27:37 UTC (rev 10318)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/MediaType.java 2008-03-18
22:44:34 UTC (rev 10319)
@@ -33,6 +33,8 @@
import java.util.Set;
/**
+ * This class is going to be removed any time soon in favoir of
org.jboss.portal.common.net.media.MediaType
+ *
* This is a immutable wrapper to the activation MimeTpye.
* <p>This class contains some extensions to the activation MimeType, such as the
typesafe enum
* pattern, and allows for a mime type to specify allowed sub types.</p>
@@ -42,6 +44,7 @@
* @see javax.activation.MimeType
* see also
ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/
*/
+@Deprecated
public final class MediaType
{
private static Map allowedTypes = new HashMap();
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java 2008-03-18
22:27:37 UTC (rev 10318)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/net/media/MediaTypeTestCase.java 2008-03-18
22:44:34 UTC (rev 10319)
@@ -45,6 +45,11 @@
assertEquals(SubtypeDef.HTML, textHTML2.getSubtype());
//
+ MediaType textHTML3 = MediaType.create("text/html");
+ assertEquals(TypeDef.TEXT, textHTML3.getType());
+ assertEquals(SubtypeDef.HTML, textHTML3.getSubtype());
+
+ //
assertEquals(MediaType.TEXT_HTML, textHTML);
assertEquals(MediaType.TEXT_HTML, textHTML2);
}
@@ -93,5 +98,40 @@
catch (Exception e)
{
}
+ try
+ {
+ MediaType.create(null);
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("text");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("text/");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("/text");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ MediaType.create("foo/html");
+ }
+ catch (Exception e)
+ {
+ }
}
}