Package org.simpleframework.http
Interface ContentType
-
- All Known Implementing Classes:
ContentTypeParser
public interface ContentType
This provides access to the MIME type parts, that is the primary type, the secondary type and an optional character set parameter. Thecharset
parameter is one of many parameters that can be associated with a MIME type. This however this exposes this parameter with a typed method.The
getCharset
will return the character encoding the content type is encoded within. This allows the user of the content to decode it correctly. Other parameters can be acquired from this by simply providing the name of the parameter.- Author:
- Niall Gallagher
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
getCharset()
This is used to retrieve thecharset
of this MIME type.java.lang.String
getParameter(java.lang.String name)
This is used to retrieve an arbitrary parameter from the MIME type header.java.lang.String
getPrimary()
This is used to retrieve the primary type of this MIME type.java.lang.String
getSecondary()
This is used to retrieve the secondary type of this MIME type.java.lang.String
getType()
This method is used to get the primary and secondary parts joined together with a "/".void
setCharset(java.lang.String charset)
This will set thecharset
to whatever value the string contains.void
setParameter(java.lang.String name, java.lang.String value)
This will add a named parameter to the content type header.void
setPrimary(java.lang.String type)
This sets the primary type to whatever value is in the string provided is.void
setSecondary(java.lang.String type)
This sets the secondary type to whatever value is in the string provided is.java.lang.String
toString()
This will return the value of the MIME type as a string.
-
-
-
Method Detail
-
getType
java.lang.String getType()
This method is used to get the primary and secondary parts joined together with a "/". This is typically how a content type is examined. Here convenience is most important, we can easily compare content types without any parameters.- Returns:
- this returns the primary and secondary types
-
setPrimary
void setPrimary(java.lang.String type)
This sets the primary type to whatever value is in the string provided is. If the string is null then this will contain a null string for the primary type of the parameter, which is likely invalid in most cases.- Parameters:
type
- the type to set for the primary type of this
-
getPrimary
java.lang.String getPrimary()
This is used to retrieve the primary type of this MIME type. The primary type part within the MIME type defines the generic type. For exampletext/plain; charset=UTF-8
. This will return the text value. If there is no primary type then this will returnnull
otherwise the string value.- Returns:
- the primary type part of this MIME type
-
setSecondary
void setSecondary(java.lang.String type)
This sets the secondary type to whatever value is in the string provided is. If the string is null then this will contain a null string for the secondary type of the parameter, which is likely invalid in most cases.- Parameters:
type
- the type to set for the primary type of this
-
getSecondary
java.lang.String getSecondary()
This is used to retrieve the secondary type of this MIME type. The secondary type part within the MIME type defines the generic type. For exampletext/html; charset=UTF-8
. This will return the HTML value. If there is no secondary type then this will returnnull
otherwise the string value.- Returns:
- the primary type part of this MIME type
-
setCharset
void setCharset(java.lang.String charset)
This will set thecharset
to whatever value the string contains. If the string is null then this will not set the parameter to any value and thetoString
method will not contain any details of the parameter.- Parameters:
charset
- parameter value to add to the MIME type
-
getCharset
java.lang.String getCharset()
This is used to retrieve thecharset
of this MIME type. This is a special parameter associated with the type, if the parameter is not contained within the type then this will return null, which typically means the default of ISO-8859-1.- Returns:
- the value that this parameter contains
-
getParameter
java.lang.String getParameter(java.lang.String name)
This is used to retrieve an arbitrary parameter from the MIME type header. This ensures that values forboundary
or other such parameters are not lost when the header is parsed. This will return the value, unquoted if required, as a string.- Parameters:
name
- this is the name of the parameter to be retrieved- Returns:
- this is the value for the parameter, or null if empty
-
setParameter
void setParameter(java.lang.String name, java.lang.String value)
This will add a named parameter to the content type header. If a parameter of the specified name has already been added to the header then that value will be replaced by the new value given. Parameters such as theboundary
as well as other common parameters can be set with this method.- Parameters:
name
- this is the name of the parameter to be addedvalue
- this is the value to associate with the name
-
toString
java.lang.String toString()
This will return the value of the MIME type as a string. This will concatenate the primary and secondary type values and add thecharset
parameter to the type which will recreate the content type.- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns the string representation of the type
-
-