Class ContentType
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.web.ContentType
-
- All Implemented Interfaces:
Serializable
public class ContentType extends Object implements Serializable
Simple class for parsing and generating Content-Type header values, per RFC 2045 (MIME) and 2616 (HTTP 1.1).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ContentTypeANYWildcard content type that will match any MIME typestatic ContentTypeAPPLICATION_XMLA ContentType constant that describes the application/xml content type.static ContentTypeATOMA ContentType constant that describes the base unqualified Atom content type.static ContentTypeATOM_ENTRYA ContentType constant that describes the qualified Atom entry content type.static ContentTypeATOM_FEEDA ContentType constant that describes the qualified Atom feed content type.static ContentTypeATOM_SERVICEA ContentType constant that describes the Atom Service content type.static StringATTR_CHARSETName of the attribute that contains the encoding character set for the content type.static ContentTypeGDATA_ERRORA ContentType constant that describes the GData error content type.static ContentTypeJAVASCRIPTA ContentType constant that describes the Javascript content type.static ContentTypeJSONA ContentType constant that describes the JSON content type.static ContentTypeJSON_LDA ContentType constant that describes the JSON-LD content type.static ContentTypeMESSAGE_RFC822A ContentType constant that indicates that the body contains an encapsulated message, with the syntax of an RFC 822 email message.static ContentTypeMULTIPART_RELATEDA ContentType constant that describes the MIME multipart/related content type.static ContentTypeN3A ContetType that describes N3 RDF, this is unofficial and unregistered Added by Brian Caruso for VIVO.static ContentTypeOPENSEARCHA ContentType constant that describes the OpenSearch description documentstatic ContentTypeRDFXMLA ContetType that describes RDF/XML.static ContentTypeRSSA ContentType constant that describes the RSS channel/item content type.static ContentTypeTEXT_HTMLA ContentType constant that describes the generic text/html content type.static ContentTypeTEXT_PLAINA ContentType constant that describes the generic text/plain content type.static ContentTypeTEXT_XMLA ContentType constant that describes the generic text/xml content type.static ContentTypeTURTLEA ContetType that describes turtle RDF, this is unofficial and unregistered Added by Brian Caruso for VIVO.
-
Constructor Summary
Constructors Constructor Description ContentType()Constructs a new instance with default media typeContentType(String typeHeader)Constructs a new instance from a content-type header value parsing the MIME content type (RFC2045) format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static ContentTypegetAtomEntry()Returns the ContentType that should be used in contexts that expect an Atom entry.static ContentTypegetAtomFeed()Returns the ContentType that should be used in contexts that expect an Atom feed.StringgetAttribute(String name)Returns the additional attribute by name of the content type.Map<String,String>getAttributes()Returns the additional attributes of the content type.static ContentTypegetBestContentType(String acceptHeader, List<ContentType> actualContentTypes)Determines the best "Content-Type" header to use in a servlet response based on the "Accept" header from a servlet request.static StringgetBestContentType(Map<String,Float> clientAcceptsTypes, Map<String,Float> serverTypes)Gets the best content type based weighted q from client accept header and the server weighted q of the extent that the type conveys the resource.StringgetCharset()StringgetMediaType()Returns the full media typefloatgetQ()returns q associated with content type.StringgetSubType()StringgetType()static Map<String,Float>getTypesAndQ(String acceptHeader)This method was added by Brian Caruso of the VIVO project.inthashCode()ContentTypelock()Makes the object immutable and returns it.booleanmatch(ContentType acceptedContentType)Returns whether this content type is match by the content type found in the "Accept" header field of an HTTP request.voidsetQ(float q)voidsetSubType(String subType)voidsetType(String type)StringtoString()Generates the Content-Type value
-
-
-
Field Detail
-
ATTR_CHARSET
public static final String ATTR_CHARSET
Name of the attribute that contains the encoding character set for the content type.- See Also:
getCharset(), Constant Field Values
-
ATOM
public static final ContentType ATOM
A ContentType constant that describes the base unqualified Atom content type.
-
ATOM_ENTRY
public static final ContentType ATOM_ENTRY
A ContentType constant that describes the qualified Atom entry content type.- See Also:
getAtomEntry()
-
ATOM_FEED
public static final ContentType ATOM_FEED
A ContentType constant that describes the qualified Atom feed content type.- See Also:
getAtomFeed()
-
ATOM_SERVICE
public static final ContentType ATOM_SERVICE
A ContentType constant that describes the Atom Service content type.
-
RSS
public static final ContentType RSS
A ContentType constant that describes the RSS channel/item content type.
-
JSON
public static final ContentType JSON
A ContentType constant that describes the JSON content type.
-
JSON_LD
public static final ContentType JSON_LD
A ContentType constant that describes the JSON-LD content type.
-
JAVASCRIPT
public static final ContentType JAVASCRIPT
A ContentType constant that describes the Javascript content type.
-
TEXT_XML
public static final ContentType TEXT_XML
A ContentType constant that describes the generic text/xml content type.
-
TEXT_HTML
public static final ContentType TEXT_HTML
A ContentType constant that describes the generic text/html content type.
-
TEXT_PLAIN
public static final ContentType TEXT_PLAIN
A ContentType constant that describes the generic text/plain content type.
-
GDATA_ERROR
public static final ContentType GDATA_ERROR
A ContentType constant that describes the GData error content type.
-
OPENSEARCH
public static final ContentType OPENSEARCH
A ContentType constant that describes the OpenSearch description document
-
MULTIPART_RELATED
public static final ContentType MULTIPART_RELATED
A ContentType constant that describes the MIME multipart/related content type.
-
APPLICATION_XML
public static final ContentType APPLICATION_XML
A ContentType constant that describes the application/xml content type.
-
MESSAGE_RFC822
public static final ContentType MESSAGE_RFC822
A ContentType constant that indicates that the body contains an encapsulated message, with the syntax of an RFC 822 email message.
-
ANY
public static final ContentType ANY
Wildcard content type that will match any MIME type
-
RDFXML
public static final ContentType RDFXML
A ContetType that describes RDF/XML. Added by Brian Caruso for VIVO.
-
N3
public static final ContentType N3
A ContetType that describes N3 RDF, this is unofficial and unregistered Added by Brian Caruso for VIVO.
-
TURTLE
public static final ContentType TURTLE
A ContetType that describes turtle RDF, this is unofficial and unregistered Added by Brian Caruso for VIVO.
-
-
Constructor Detail
-
ContentType
public ContentType()
Constructs a new instance with default media type
-
ContentType
public ContentType(String typeHeader)
Constructs a new instance from a content-type header value parsing the MIME content type (RFC2045) format. If the type isnull, then media type and charset will be initialized to default values.- Parameters:
typeHeader- content type value in RFC2045 header format.
-
-
Method Detail
-
getAtomEntry
public static ContentType getAtomEntry()
Returns the ContentType that should be used in contexts that expect an Atom entry.
-
getAtomFeed
public static ContentType getAtomFeed()
Returns the ContentType that should be used in contexts that expect an Atom feed.
-
getBestContentType
public static ContentType getBestContentType(String acceptHeader, List<ContentType> actualContentTypes)
Determines the best "Content-Type" header to use in a servlet response based on the "Accept" header from a servlet request.- Parameters:
acceptHeader- "Accept" header value from a servlet request (notnull)actualContentTypes- actual content types in descending order of preference (non-empty, and each entry is of the form "type/subtype" without the wildcard char '*') ornullif no "Accept" header was specified- Returns:
- the best content type to use (or
nullon no match).
-
getBestContentType
public static String getBestContentType(Map<String,Float> clientAcceptsTypes, Map<String,Float> serverTypes)
Gets the best content type based weighted q from client accept header and the server weighted q of the extent that the type conveys the resource. From suggestions by Tim Berners-Lee at http://www.w3.org/DesignIssues/Conneg- Parameters:
clientAcceptsTypes- types the client can accept with Q weights.serverTypes- types the server can provide with Q weights.- Returns:
- returns content type of best match or null if no match.
-
getTypesAndQ
public static Map<String,Float> getTypesAndQ(String acceptHeader)
This method was added by Brian Caruso of the VIVO project. March 15 2011.- Parameters:
acceptHeader- Accept header- Returns:
- the types and the q values from the accept header
-
getType
public String getType()
-
setType
public void setType(String type)
-
getSubType
public String getSubType()
-
setSubType
public void setSubType(String subType)
-
getMediaType
public String getMediaType()
Returns the full media type
-
lock
public ContentType lock()
Makes the object immutable and returns it. This should at least be used when keeping an instance as a static.
-
getAttributes
public Map<String,String> getAttributes()
Returns the additional attributes of the content type.
-
getAttribute
public String getAttribute(String name)
Returns the additional attribute by name of the content type.- Parameters:
name- attribute name
-
getQ
public float getQ()
returns q associated with content type.
-
setQ
public void setQ(float q)
-
getCharset
public String getCharset()
-
match
public boolean match(ContentType acceptedContentType)
Returns whether this content type is match by the content type found in the "Accept" header field of an HTTP request.For atom content type, this method will check the optional attribute 'type'. If the type attribute is set in both this and
acceptedContentType, then they must be the same. That is,application/atom+xmlwill match bothapplication/atom+xml;type=feedandapplication/atom+xml;type=entry, butapplication/atom+xml;type=entrywill not matchapplication/atom+xml;type=feed.a- Parameters:
acceptedContentType- content type found in the "Accept" header field of an HTTP request
-
toString
public String toString()
Generates the Content-Type value
-
-