Package org.apache.axiom.mime
Class ContentType
java.lang.Object
org.apache.axiom.mime.ContentType
Represents the (parsed) value of a
Content-Type header as defined by
RFC 2045.
The relevant productions from RFC 2045 and RFC 822 are:
content := "Content-Type" ":" type "/" subtype *(";" parameter)
parameter := attribute "=" value
attribute := token
value := token / quoted-string
token := 1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>
tspecials := "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "\" / <"> / "/" / "[" / "]" / "?" / "="
quoted-string := <"> *(qtext/quoted-pair) <">
qtext := <any CHAR excepting <">, "\" & CR, and including linear-white-space>
quoted-pair := "\" CHAR
This class is similar to Activation's MimeType and JavaMail's ContentType classes, but the
following differences exist:
- This class is more lenient than (certain implementations of)
MimeType. It will accept content types that are not strictly valid, but that are commonly found. E.g. it will accept content types with an extra semicolon at the end. - This class is immutable.
- This class makes a distinction between a media type (which is defined by a primary type and a
sub type and represented by a
MediaTypeobject) and a content type, which is defined by a media type and a set of parameters.
Another reason for the existence of this class is to avoid a dependency on JavaMail.
Note that this class doesn't override Object.equals(Object) because there is no
meaningful way to compare content types with parameters.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionContentType(String type) Constructor that parses aContent-Typeheader value.ContentType(MediaType mediaType, String... parameters) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic ContentType.Builderbuilder()Get a new builder instance.Get the media type this content type refers to.getParameter(String name) Get the specified parameter value.booleanCheck if the content type is textual, i.e. if an entity with this content type should be human readable.Get a new builder initialized with the media type and parameters from this instance.toString()Create a string representation of this content type suitable as the value for aContent-Typeheader as specified by RFC 2045.
-
Constructor Details
-
ContentType
Constructor.- Parameters:
mediaType- the media typeparameters- the parameters as name/value pairs (with even entries representing the parameter names, and odd entries the corresponding values)
-
ContentType
Constructor that parses aContent-Typeheader value.- Parameters:
type- the value of theContent-Typeheader conforming to RFC 2045- Throws:
ParseException- if the value is invalid and could not be parsed
-
-
Method Details
-
builder
Get a new builder instance.- Returns:
- the builder
-
toBuilder
Get a new builder initialized with the media type and parameters from this instance.- Returns:
- the builder
-
getMediaType
Get the media type this content type refers to.- Returns:
- the media type
-
getParameter
Get the specified parameter value.- Parameters:
name- the parameter name- Returns:
- the parameter value, or
nullif no parameter with the given name was found
-
isTextual
public boolean isTextual()Check if the content type is textual, i.e. if an entity with this content type should be human readable. This information may be used to select a content transfer encoding.- Returns:
- whether the content type is textual
-
toString
Create a string representation of this content type suitable as the value for aContent-Typeheader as specified by RFC 2045. Note that this method serializes all parameter values as quoted strings, even values that could be represented as tokens. This is compatible with R1109 in WS-I Basic Profile 1.2 and 2.0.
-