Package org.apache.tapestry5.http
Class ContentType
- java.lang.Object
-
- org.apache.tapestry5.http.ContentType
-
public final class ContentType extends java.lang.Object
Represents an HTTP content type. Allows to set various elements like the MIME type, the character set, and other parameters. This is similar to a number of other implementations of the same concept in JAF, etc. We have created this simple implementation to avoid including the whole libraries. As of Tapestry 5.4, this is now an immutable data type.
-
-
Constructor Summary
Constructors Constructor Description ContentType(java.lang.String contentType)Creates a new content type from the argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)Returns true only if the other object is another instance of ContentType, and has the same baseType, subType and set of parameters.java.lang.StringgetBaseType()java.lang.StringgetCharset()java.lang.StringgetMimeType()java.lang.StringgetParameter(java.lang.String key)java.util.List<java.lang.String>getParameterNames()java.lang.StringgetSubType()inthashCode()booleanhasParameters()java.lang.StringtoString()ContentTypewithCharset(java.lang.String charset)ContentTypewithParameter(java.lang.String key, java.lang.String value)Returns a new content type with the indicated parameter.
-
-
-
Constructor Detail
-
ContentType
public ContentType(java.lang.String contentType)
Creates a new content type from the argument. The format of the argument has to be basetype/subtype(;key=value)*- Parameters:
contentType- the content type that needs to be represented
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
Returns true only if the other object is another instance of ContentType, and has the same baseType, subType and set of parameters.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getBaseType
public java.lang.String getBaseType()
- Returns:
- the base type of the content type
-
getSubType
public java.lang.String getSubType()
- Returns:
- the sub-type of the content type
-
getMimeType
public java.lang.String getMimeType()
- Returns:
- the MIME type of the content type (the base type and the subtype, seperated with a '/').
-
getParameterNames
public java.util.List<java.lang.String> getParameterNames()
- Returns:
- the list of names of parameters in this content type, in alphabetical order.
-
getCharset
public java.lang.String getCharset()
- Returns:
- the character set (the "charset" parameter) or null.
-
getParameter
public java.lang.String getParameter(java.lang.String key)
- Parameters:
key- the name of the content type parameter- Returns:
- the value of the content type parameter
-
withParameter
public ContentType withParameter(java.lang.String key, java.lang.String value)
Returns a new content type with the indicated parameter.- Since:
- 5.4
-
withCharset
public ContentType withCharset(java.lang.String charset)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- the string representation of this content type.
-
hasParameters
public boolean hasParameters()
- Returns:
- true if the content type includes parameters (such as 'charset').
- Since:
- 5.4
-
-