From portal-commits at lists.jboss.org Wed Mar 19 05:21:16 2008 Content-Type: multipart/mixed; boundary="===============7571560395445865988==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r10325 - modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/media. Date: Wed, 19 Mar 2008 05:21:16 -0400 Message-ID: --===============7571560395445865988== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien(a)jboss.com Date: 2008-03-19 05:21:14 -0400 (Wed, 19 Mar 2008) New Revision: 10325 Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/me= dia/ContentType.java modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/me= dia/MediaType.java modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/me= dia/MediaTypeMapImpl.java Log: minor update + javadoc update Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common= /net/media/ContentType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/ContentType.java 2008-03-19 01:19:29 UTC (rev 10324) +++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/ContentType.java 2008-03-19 09:21:14 UTC (rev 10325) @@ -28,25 +28,43 @@ import java.util.Iterator; = /** + * Represent a content type header value as defined by the section 5 of the + * RFC2045 + * * @author Julien Viet * @version $Revision: 630 $ */ public class ContentType { = - public static ContentType create(String contentTypeValue) + /** + * Creates a content type header value by parsing a content type value.= The content type value format is defined + * by the section 5.1 of the RFC2045 but does not + * take in account the prefix "Content-Type" ":" of the content product= ion rule of the grammar. + * + * @param contentTypeValue the content type value + * @return + * @throws IllegalArgumentException if the + */ + public static ContentType create(String contentTypeValue) throws Illega= lArgumentException { + if (contentTypeValue =3D=3D null) + { + throw new IllegalArgumentException("No null content type value ac= cepted"); + } + + // int slashIndex =3D contentTypeValue.indexOf('/'); - if (slashIndex =3D=3D -1) { - + throw new IllegalArgumentException("The content type " + contentT= ypeValue + " does not contain a /"); } = + // String typeName =3D contentTypeValue.substring(0, slashIndex); = + // int semiColonIndex =3D contentTypeValue.indexOf(';', slashIndex + 1); - if (semiColonIndex =3D=3D -1) { return new ContentType(MediaType.create(typeName, contentTypeValu= e.substring(slashIndex + 1))); @@ -62,6 +80,7 @@ // List parameters =3D null; = + // for (int i =3D semiColonIndex + 1;semiColonIndex !=3D -1;i =3D semiC= olonIndex + 1) { semiColonIndex =3D contentTypeValue.indexOf(';', i); @@ -152,10 +171,16 @@ return parameters; } = + /** + * Returns the value of the content type which is the concatenation of = the media type name + * followed by the parameters. + * + * @return the value + */ public String getValue() { StringBuilder builder =3D new StringBuilder(); - builder.append(mediaType.getType().getName()).append('/').append(med= iaType.getSubtype().getName()); + builder.append(mediaType.getValue()); for (Iterator i =3D parameters.iterator();;) { Parameter parameter =3D i.next(); Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common= /net/media/MediaType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/MediaType.java 2008-03-19 01:19:29 UTC (rev 10324) +++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/MediaType.java 2008-03-19 09:21:14 UTC (rev 10325) @@ -23,6 +23,8 @@ package org.jboss.portal.common.net.media; = /** + * An immutable media type class. + * * @author Julien Viet * @version $Revision: 630 $ */ @@ -41,22 +43,18 @@ /** . */ public static final MediaType APPLICATION_X_WWW_FORM_URLENCODED =3D new= MediaType(TypeDef.APPLICATION, SubtypeDef.X_WWW_FORM_URLENCODED); = - /** The type identifier. */ - private final TypeDef type; - - /** The sub type identifier. */ - private final SubtypeDef subtype; - - /** . */ - private volatile Integer hashCode; - - /** . */ - private volatile String toString; - - /** . */ - private volatile String value; - - public static MediaType create(String mediaTypeName) + /** + * Create a media type object by parsing a media type name. The media t= ype name format is defined by the + * section 5.1 of the RFC2045 but is limited + * to a subset of the grammar, the starting production rule being: + * + * media-type: type "/" subtype + * + * @param mediaTypeName the media type name value + * @return the media type object + * @throws IllegalArgumentException if the argument is null or is not v= alid + */ + public static MediaType create(String mediaTypeName) throws IllegalArgu= mentException { if (mediaTypeName =3D=3D null) { @@ -78,7 +76,15 @@ return create(typeName, subtypeName); } = - public static MediaType create(String typeName, String subtypeName) + /** + * Create a media type object by using the provided type name and subty= pe name. + * + * @param typeName the type name + * @param subtypeName the subtype name + * @return the media type object + * @throws IllegalArgumentException if any argument is null or not valid + */ + public static MediaType create(String typeName, String subtypeName) thr= ows IllegalArgumentException { if (typeName =3D=3D null) { @@ -103,7 +109,15 @@ return new MediaType(type, subtype); } = - public static MediaType create(TypeDef type, SubtypeDef subtype) + /** + * Create a media type object using the provided type and subtype objec= ts. + * + * @param type the type + * @param subtype the subtype + * @return the media type object + * @throws IllegalArgumentException if any argument is null + */ + public static MediaType create(TypeDef type, SubtypeDef subtype) throws= IllegalArgumentException { if (type =3D=3D null) { @@ -118,6 +132,21 @@ return new MediaType(type, subtype); } = + /** The type identifier. */ + private final TypeDef type; + + /** The sub type identifier. */ + private final SubtypeDef subtype; + + /** The cached hashCode. */ + private volatile Integer hashCode; + + /** the cached toString. */ + private volatile String toString; + + /** the cached value. */ + private volatile String value; + MediaType(TypeDef type, SubtypeDef subtype) { this.type =3D type; @@ -134,6 +163,11 @@ return subtype; } = + /** + * Returns the value which is a concatenation ofthe type name, a slash = char and the subtype name. + * + * @return the value + */ public String getValue() { if (value =3D=3D null) Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common= /net/media/MediaTypeMapImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/MediaTypeMapImpl.java 2008-03-19 01:19:29 UTC (rev 10324) +++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/net/m= edia/MediaTypeMapImpl.java 2008-03-19 09:21:14 UTC (rev 10325) @@ -32,6 +32,8 @@ import java.util.Collections; = /** + * An implementation of the media type map interface. + * * @author Julien Viet * @version $Revision: 630 $ */ --===============7571560395445865988==--