|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.simpleframework.util.parse.Parser
org.simpleframework.http.parse.ContentParser
public class ContentParser
This provides access to the MIME type parts, that is the primary
type, the secondary type and an optional character set parameter.
The charset
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.
Field Summary |
---|
Fields inherited from class org.simpleframework.util.parse.Parser |
---|
buf, count, off |
Constructor Summary | |
---|---|
ContentParser()
The default constructor will create a ContentParser
that contains no charset, type or subtype. |
|
ContentParser(java.lang.String header)
This is primarily a convenience constructor. |
Method Summary | |
---|---|
java.lang.String |
getCharset()
This is used to retrieve the charset 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. |
protected void |
init()
This will initialize the parser when it is ready to parse a new String . |
protected void |
parse()
Reads and parses the MIME type from the given String
object. |
void |
setCharset(java.lang.String enc)
This will set the charset 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 primary)
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. |
Methods inherited from class org.simpleframework.util.parse.Parser |
---|
digit, ensureCapacity, parse, skip, space, toLower |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ContentParser()
ContentParser
that contains no charset, type or subtype. This can be used to
extract the type, subtype and the optional charset
parameter by using the parser's parse(String)
method.
public ContentParser(java.lang.String header)
String
given to extract the MIME type. This
could be achived by calling the default no-arg constructor
and then using the instance to invoke the parse
method on that String
.
header
- String
containing a MIME type valueMethod Detail |
---|
public void setPrimary(java.lang.String primary)
setPrimary
in interface ContentType
primary
- the type to set for the primary type of thispublic java.lang.String getPrimary()
text/plain; charset=UTF-8
. This will
return the text value. If there is no primary type then this
will return null
otherwise the string value.
getPrimary
in interface ContentType
public void setSecondary(java.lang.String type)
setSecondary
in interface ContentType
type
- the type to set for the primary type of thispublic java.lang.String getSecondary()
text/html; charset=UTF-8
. This
will return the HTML value. If there is no secondary type then
this will return null
otherwise the string value.
getSecondary
in interface ContentType
public void setCharset(java.lang.String enc)
charset
to whatever value the
string contains. If the string is null then this will not set
the parameter to any value and the toString
method
will not contain any details of the parameter.
setCharset
in interface ContentType
enc
- parameter value to add to the MIME typepublic java.lang.String getCharset()
charset
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.
getCharset
in interface ContentType
public java.lang.String getParameter(java.lang.String name)
boundary
or other such parameters are not lost when the header is parsed.
This will return the value, unquoted if required, as a string.
getParameter
in interface ContentType
name
- this is the name of the parameter to be retrieved
public void setParameter(java.lang.String name, java.lang.String value)
boundary
as well as other
common parameters can be set with this method.
setParameter
in interface ContentType
name
- this is the name of the parameter to be addedvalue
- this is the value to associate with the nameprotected void init()
String
. This will reset the parser to a
ready state. The init method is invoked by the parser when
the Parser.parse
method is invoked.
init
in class Parser
protected void parse()
String
object. This uses the syntax defined by RFC 2616 for the media-type
syntax. This parser is only concerned with one parameter, the
charset
parameter. The syntax for the media type is
media-type = token "/" token *( ";" parameter ) parameter = token | literal
parse
in class Parser
public java.lang.String toString()
charset
parameter to the type which will
recreate the content type.
toString
in interface ContentType
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |