Package org.simpleframework.http.parse
Class ContentDispositionParser
java.lang.Object
org.simpleframework.common.parse.Parser
org.simpleframework.http.parse.ContentDispositionParser
- All Implemented Interfaces:
ContentDisposition
The
ContentDispositionParser
object is used to represent
a parser used to parse the Content-Disposition header. Its used when
there is a multipart form upload to the server and allows the
server to determine the individual part types.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ParseBuffer
This is used to capture the name of the file if it is provided.private boolean
This is used to determine if the disposition is a file or form.private ParseBuffer
This is used to capture the name of the part if it is provided.private ParseBuffer
This is the buffer used to acquire values from the header. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for theContentDispositionParser
object.Constructor for theContentDispositionParser
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
clear()
This is used to clear all previously collected tokens.This method is used to acquire the file name of the part.getName()
This method is used to acquire the name of the part.protected void
init()
This will initialize theParser
when it is ready to parse a newString
.boolean
isFile()
This method is used to determine the type of a part.private void
name()
This will simply read all characters from the buffer before the first '=' character.private void
pack()
This is used to remove all whitespace characters from theString
excluding the whitespace within literals.private void
This will read the parameters from the header value.private void
This will read the parameters from the header value.protected void
parse()
This is the method that should be implemented to read the buffer.private boolean
quote
(char ch) This method is used to determine if the specified character is a quote character.private void
type()
This is used to determine the type of the disposition header.private void
value
(ParseBuffer value) This is used to read a parameters value from the buf.
-
Field Details
-
skip
This is the buffer used to acquire values from the header. -
file
This is used to capture the name of the file if it is provided. -
name
This is used to capture the name of the part if it is provided. -
form
private boolean formThis is used to determine if the disposition is a file or form.
-
-
Constructor Details
-
ContentDispositionParser
public ContentDispositionParser()Constructor for theContentDispositionParser
object. This is used to create a parser that can parse a disposition header which is typically sent as part of a multipart upload. It can be used to determine the type of the upload. -
ContentDispositionParser
Constructor for theContentDispositionParser
object. This is used to create a parser that can parse a disposition header which is typically sent as part of a multipart upload. It can be used to determine the type of the upload.- Parameters:
text
- this is the header value that is to be parsed
-
-
Method Details
-
getFileName
This method is used to acquire the file name of the part. This is used when the part represents a text parameter rather than a file. However, this can also be used with a file part.- Specified by:
getFileName
in interfaceContentDisposition
- Returns:
- this returns the file name of the associated part
-
getName
This method is used to acquire the name of the part. Typically this is used when the part represents a text parameter rather than a file. However, this can also be used with a file part.- Specified by:
getName
in interfaceContentDisposition
- Returns:
- this returns the name of the associated part
-
isFile
public boolean isFile()This method is used to determine the type of a part. Typically a part is either a text parameter or a file. If this is true then the content represented by the associated part is a file.- Specified by:
isFile
in interfaceContentDisposition
- Returns:
- this returns true if the associated part is a file
-
init
protected void init()This will initialize theParser
when it is ready to parse a newString
. This will reset the parser to a ready state. This method is invoked by the parser before the parse method is invoked, it is used to pack the contents of the header and clear any previous tokens used. -
clear
protected void clear()This is used to clear all previously collected tokens. This allows the parser to be reused when there are multiple source strings to be parsed. Clearing of the tokens is performed when the parser is initialized. -
parse
protected void parse()This is the method that should be implemented to read the buffer. This method will extract the type from the header and the tries to extract the optional parameters if they are in the header. The optional parts are the file name and name. -
pack
private void pack()This is used to remove all whitespace characters from theString
excluding the whitespace within literals. The definition of a literal can be found in RFC 2616.The definition of a literal for RFC 2616 is anything between 2 quotes but excuding quotes that are prefixed with the backward slash character.
-
type
private void type()This is used to determine the type of the disposition header. This will allow the parser to determine it the header represents form data or a file upload. Once it determines the type of the upload header it sets an internal flag which can be used. -
parameters
private void parameters()This will read the parameters from the header value. This will search for thefilename
parameter within the set of parameters which are given to the type. Thefilename
param and the thename
are tokenized by this method. -
parameter
private void parameter()This will read the parameters from the header value. This will search for thefilename
parameter within the set of parameters which are given to the type. Thefilename
param and the thename
are tokenized by this method. -
name
private void name()This will simply read all characters from the buffer before the first '=' character. This represents a parameter name (see RFC 2616 for token). The parameter name is not buffered it is simply read from the buffer. This will not cause anIndexOutOfBoundsException
as each offset is checked before it is acccessed. -
value
This is used to read a parameters value from the buf. This will read allchar
's upto but excluding the first terminalchar
encountered from the off within the buf, or if the value is a literal it will read a literal from the buffer (literal is any data between quotes except if the quote is prefixed with a backward slash character).- Parameters:
value
- this is the parse buffer to append the value to
-
quote
private boolean quote(char ch) This method is used to determine if the specified character is a quote character. The quote character is typically used as a boundary for the values within the header. This accepts a single or double quote.- Parameters:
ch
- the character to determine if it is a quotation- Returns:
- true if the character provided is a quotation character
-