public class MIMEType extends Object
AcceptMIMEType
has a default value and its values are compared
after conversion into a floating point number.Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log
The
Logger for MIMEType operations. |
protected static Pattern |
m_p1
Pattern used to match the type/subtype of a MIME expression.
|
protected static Pattern |
m_p2
Pattern used to match the optional parameters of a MIME
expression.
|
Constructor and Description |
---|
MIMEType(MIMEType mt)
Clones the specified
MIMEType . |
MIMEType(String s)
Constructor parses the string as a MIME Internet Type
expression.
|
MIMEType(String type,
String subtype)
Constructs a
MIMEType object from its component parts. |
MIMEType(String type,
String subtype,
NVPair[] params)
Constructs a
MIMEType object from its component
parts. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns true iff the MIME type, MIME subtype and any MIME
parameters are all the same as determined by
isExactMatch( MIMEType other, boolean compareParams ) when
compareParams is true . |
String[] |
getDefaultParamNames()
Returns the names of all default parameters recognized by this
class for the MIME type and subtype represented by this
MIMEType instances. |
MIMEType |
getIntersection(MIMEType other,
String[] dropParams)
Returns the intersection of the this media-range and the given
media-range.
|
String |
getMimeType()
Returns the MIME type and subtype as "type/subtype", but
does not format in any MIME parameters.
|
NVPair |
getParam(int i)
Returns the nth MIME type parameters, origin zero.
|
int |
getParamCount()
Returns the #of MIME parameters.
|
NVPair[] |
getParams()
An array of the explicitly declared MIME type parameters.
|
String |
getParamValue(String name)
Returns the value for the indicated name and
null
if there is no MIME parameter with that name. |
String |
getSubtype()
Returns the MIME subtype, eg, "plain" for "text/plain".
|
String |
getType()
Returns the MIME type, eg, "text" for "text/plain".
|
protected static void |
init()
Initialization for shared
Pattern object that matches
valid MIME type expressions. |
boolean |
isExactMatch(MIMEType otherType)
Convenience method compares type, subtype, and type parameters
|
boolean |
isExactMatch(MIMEType t,
boolean compareParams)
Returns true IFF the two MIME type expressions have the same
meaning.
|
boolean |
isExactMatch(String otherType)
Convenience method compares type, subtype, and type parameters
|
boolean |
isIgnoredParam(String name)
Returns true iff the named parameter should be ignored by the
spans logic for MIME type and subtype represented
by this MIMEType instance. |
boolean |
isSpannedBy(MIMEType other)
Convenience method for
other.spans( this, true ); |
boolean |
isSpannedBy(MIMEType other,
boolean compareParams)
Convenience method for
other.spans( this, compareParams ); |
boolean |
isSpannedBy(String other)
Convenience method for
new MIMEType( other ).spans( this,
true ); |
boolean |
isSubtypeWildcard()
Returns true iff the MIME subtype is "*", indicating a MIME
subtype wildcard.
|
boolean |
isTypeWildcard()
Returns true iff the MIME type is "*", indicating a MIME type
wildcard.
|
boolean |
isWildcard()
Deprecated.
Use
isSubtypeWildcard() instead. |
boolean |
matches(MIMEType otherMimeType)
Convenience method for
matches( MIMEType mimeType,
boolean matchParams ) that does NOT compare the MIME type
parameters. |
boolean |
matches(MIMEType other,
boolean compareParams)
|
boolean |
matches(String mimeType)
Convenience method for
matches( MIMEType mimeType,
boolean matchParams ) that does NOT compare the MIME type
parameters. |
boolean |
sameParamValue(String name,
String realValue,
String otherValue)
Returns true IFF this
MIMEType has the specified
parameter value. |
boolean |
spans(MIMEType other)
Convenience method compares type, subtype, and type parameters
|
boolean |
spans(MIMEType other,
boolean compareParams)
|
boolean |
spans(String other)
Convenience method compares type, subtype, and type parameters
|
boolean |
spans(String other,
boolean compareParams)
Convenience method compares type, subtype, and optionally any
type parameters.
|
String |
toString()
Generates a MIME type string from the parsed data.
|
String |
toString(String name,
String value)
This method may be extended to produce a specific
represensation of the value of the indicated parameter.
|
protected static final org.apache.log4j.Logger log
protected static Pattern m_p1
m_p2
.
protected static Pattern m_p2
m_p1
. The different
matching groups are:public MIMEType(String type, String subtype, NVPair[] params) throws IllegalArgumentException
MIMEType
object from its component
parts.type
- The media type or "*" (if the subtype if
also "*").subtype
- The media subtype or "*".params
- An array of name-value pairs specifying the MIME
attributes.IllegalArgumentException
- If the method is unable to
validate the syntax of the type, subtype and params.
Everything must be an HTTP token
except the
attribute value, which is interchanged as an HTTP
quoted-string
any may contain pretty much any
character sequence. Also thrown if params is
null
.public MIMEType(String s) throws IllegalArgumentException
From the HTTP/1.1 specification: The type, subtype, and parameter attribute names are case-insensitive. Parameter values might or might not be casesensitive, depending on the semantics of the parameter name. Linear white space (LWS) MUST NOT be used between the type and subtype, nor between an attribute and its value.
IllegalArgumentException
- Indicates that the
string could not be parsed as a valid MIME expression.protected static void init()
Pattern
object that matches
valid MIME type expressions.public String[] getDefaultParamNames()
MIMEType
instances.public boolean isIgnoredParam(String name)
spans
logic for MIME type and subtype represented
by this MIMEType
instance.false
. Implementors that subclass MIMEType
MUST extend this method if the subclass contains any
parameters that should be ignored by the spans
logic.public String getType()
public String getSubtype()
public boolean isTypeWildcard()
public boolean isWildcard()
isSubtypeWildcard()
instead.public boolean isSubtypeWildcard()
public String getMimeType()
Note: There is no LWS (linear whitespace) between the type and the subtype for a MIME string.
toString()
public boolean matches(String mimeType) throws IllegalArgumentException
matches( MIMEType mimeType,
boolean matchParams )
that does NOT compare the MIME type
parameters.IllegalArgumentException
public boolean matches(MIMEType otherMimeType) throws IllegalArgumentException
matches( MIMEType mimeType,
boolean matchParams )
that does NOT compare the MIME type
parameters.IllegalArgumentException
public boolean isExactMatch(MIMEType otherType)
public boolean isExactMatch(String otherType) throws IllegalArgumentException
IllegalArgumentException
public boolean isExactMatch(MIMEType t, boolean compareParams)
Note: The MIME parameter values are compared using a case-sensitive comparison, which is not correct for all MIME types since some explictly provide for case-insensitive semantics for their parameter values. Implementors are free to further specialize this method in derived subclasses to obtain MIME type specific comparision of MIME type parameter values or to establish default parameter values.
Note: Defaults may be provided for MIME parameters through
subclasses by extending ( String name,
String realValue, String otherValue )
, getDefaultParamNames()
, and #isIgnoredParamName(
String name )
.
public boolean sameParamValue(String name, String realValue, String otherValue) throws IllegalArgumentException
MIMEType
has the specified
parameter value. This method is exposed to account for any
MIME type specific case-sensitivity for the parameter name or
parameter value and any default MIME type parameters.The default implementation uses a case-sensitive comparison of the MIME parameter value. Implementors are free to created subclasses that extend this method to incorporate MIME type specific logic in their comparison.
name
- The name of the parameter whose value is being
compared. This parameter is ignored by this implementation but
is provided for subclasses that may have type specific value
comparison logic and/or parameter value default logic.realValue
- The value of the parameter on this MIMEType
object as discovered, e.g., by getParamValue(
String name )
. This may explicitly be null
.
Subclasses that have a default value for this named parameter,
e.g., AcceptMIMEType
which has a default value for the
"q" parameter, MUST substitute their default value when
realValue is null
.otberValue
- The value that is being compared to the
foundValue. This parameter MAY be null
, in
which case a subclass MAY choose to declare a default value to
be used in this comparison.IllegalArgumentException
public String toString(String name, String value)
toString()
when serializing the entire header
value.public MIMEType getIntersection(MIMEType other, String[] dropParams)
MIMEType
MAY be a fully
determined media type, but it MAY be undetermined, e.g., has a
type or subtype wildcard, does not specify a content encoding,
language family, etc. If this is NOT a fully determined media
type, then the server MUST make it into a concrete media type.other
- The other media-range whose intersection with this
media-range will be return.dropParams
- An array of zero or more parameter names that
will be dropped out of the intersected media-ranges. For
example, this is used to drop the "q" parameter during content
negotiation when computing the negotiated joint media-range.null
if the intersection does not exist. For
example, if the two media-ranges each specify different
concrete subtypes, such as "text/xml" vs "text/plain".public boolean spans(String other)
public boolean spans(MIMEType other)
public boolean spans(String other, boolean compareParams)
public boolean spans(MIMEType other, boolean compareParams)
MIMEType
expresses a constraint
that spans the other MIMEType
. The semantics of
"spans" are that the other may be either the same MIMEType
or may be a more constrained (aka specific) MIMEType
.compareParams
- IFF true the MIME type parameters are also
compared by this method. The specific parameter values are
compared using sameParamValue( String name, String
realValue, String otherValue )
.public boolean isSpannedBy(String other)
new MIMEType( other ).spans( this,
true );
public boolean isSpannedBy(MIMEType other)
other.spans( this, true );
public boolean isSpannedBy(MIMEType other, boolean compareParams)
other.spans( this, compareParams );
public boolean matches(MIMEType other, boolean compareParams)
MIMEType
has the same type and subtype
or if the types match and this MIMEType
is a
wildcard that covers the given mimeType. The parameters
are optionally compared by this method.compareParams
- IFF true the MIME type parameters are also
compared by this method. The specific parameter values are
compared using sameParamValue( String name, String
realValue, String otherValue )
.
Note: This is a convenience for spans( other, false
);
.spans( MIMEType other, boolean compareParams )
public boolean equals(Object o)
isExactMatch( MIMEType other, boolean compareParams )
when
compareParams is true
.public NVPair[] getParams()
public NVPair getParam(int i)
public int getParamCount()
public String getParamValue(String name)
null
if there is no MIME parameter with that name.name
- The name of a MIME parameter, which is
case-insensitive. Implementors can create subclasses if a
specific MIME type declares some case-sensitive MIME type
parameter names.public String toString()
token
then it
is serialized as an HTTP quoted-string
.Note: There is no LWS (linear whitespace) between the type and the subtype for a MIME string. Also, there is no LWS between the attribute name and the attribute value, e.g., "charset=xxx" but not "charset = xxx".
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.