Class ContentDispositionParser

  • All Implemented Interfaces:
    ContentDisposition

    public class ContentDispositionParser
    extends Parser
    implements 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

      Fields 
      Modifier and Type Field Description
      private ParseBuffer file
      This is used to capture the name of the file if it is provided.
      private boolean form
      This is used to determine if the disposition is a file or form.
      private ParseBuffer name
      This is used to capture the name of the part if it is provided.
      private ParseBuffer skip
      This is the buffer used to acquire values from the header.
    • Constructor Summary

      Constructors 
      Constructor Description
      ContentDispositionParser()
      Constructor for the ContentDispositionParser object.
      ContentDispositionParser​(java.lang.String text)
      Constructor for the ContentDispositionParser object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void clear()
      This is used to clear all previously collected tokens.
      java.lang.String getFileName()
      This method is used to acquire the file name of the part.
      java.lang.String getName()
      This method is used to acquire the name of the part.
      protected void init()
      This will initialize the Parser when it is ready to parse a new String.
      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 the String excluding the whitespace within literals.
      private void parameter()
      This will read the parameters from the header value.
      private void parameters()
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • skip

        private ParseBuffer skip
        This is the buffer used to acquire values from the header.
      • file

        private ParseBuffer file
        This is used to capture the name of the file if it is provided.
      • name

        private ParseBuffer name
        This is used to capture the name of the part if it is provided.
      • form

        private boolean form
        This is used to determine if the disposition is a file or form.
    • Constructor Detail

      • ContentDispositionParser

        public ContentDispositionParser()
        Constructor for the ContentDispositionParser 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

        public ContentDispositionParser​(java.lang.String text)
        Constructor for the ContentDispositionParser 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 Detail

      • getFileName

        public java.lang.String 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 interface ContentDisposition
        Returns:
        this returns the file name of the associated part
      • getName

        public java.lang.String 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 interface ContentDisposition
        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 interface ContentDisposition
        Returns:
        this returns true if the associated part is a file
      • init

        protected void init()
        This will initialize the Parser when it is ready to parse a new String. 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.
        Specified by:
        init in class Parser
      • 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.
        Specified by:
        parse in class Parser
      • pack

        private void pack()
        This is used to remove all whitespace characters from the String 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 the filename parameter within the set of parameters which are given to the type. The filename param and the the name are tokenized by this method.
      • parameter

        private void parameter()
        This will read the parameters from the header value. This will search for the filename parameter within the set of parameters which are given to the type. The filename param and the the name 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 an IndexOutOfBoundsException as each offset is checked before it is acccessed.
      • value

        private void value​(ParseBuffer value)
        This is used to read a parameters value from the buf. This will read all char's upto but excluding the first terminal char 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