Class FormDataSet


  • public class FormDataSet
    extends OutputRepresentation
    HTML form supporting either URL encoding or multipart encoding.
    • Field Detail

      • DEFAULT_BOUNDARY

        private static final java.lang.String DEFAULT_BOUNDARY
        The default boundary separating multipart entries.
        See Also:
        Constant Field Values
      • entries

        private final Series<FormData> entries
        The modifiable series of data entries.
      • multipart

        private volatile boolean multipart
        Indicates if the form is multipart encoded.
      • multipartBoundary

        private volatile java.lang.String multipartBoundary
        The boundary separating multipart entries.
    • Constructor Detail

      • FormDataSet

        public FormDataSet()
        Default constructor, creates a single part form.
      • FormDataSet

        private FormDataSet​(MediaType mediaType,
                            boolean multipart,
                            java.lang.String multipartBoundary)
        Constructor.
        Parameters:
        mediaType - The representation's mediaType.
        multipart - Indicates if the form is multipart encoded.
        multipartBoundary - The boundary separating multipart entries.
      • FormDataSet

        public FormDataSet​(Representation formRepresentation)
        Constructor.
        Parameters:
        formRepresentation - The representation to parse.
      • FormDataSet

        public FormDataSet​(java.lang.String multipartBoundary)
        Creates a multipart form.
        Parameters:
        multipartBoundary - The boundary separating multipart entries.
    • Method Detail

      • createMultipartMediaType

        private static MediaType createMultipartMediaType​(java.lang.String boundary)
        Creates the media type of a multipart form which must include the used boundary.
        Parameters:
        boundary - The multipart boundary.
        Returns:
        The multipart media type.
      • add

        public FormData add​(java.lang.String name,
                            java.lang.String value)
        Adds a new form data entry.
        Parameters:
        name - The entry name.
        value - The entry value.
        Returns:
        The entry created and added to getEntries().
      • encode

        public java.lang.String encode()
                                throws java.io.IOException
        Encodes the form using the standard HTML form encoding mechanism and the UTF-8 character set.
        Returns:
        The encoded form.
        Throws:
        java.io.IOException
      • encode

        public java.lang.String encode​(boolean queryString)
                                throws java.io.IOException
        Encodes the form using the standard URI encoding mechanism and the UTF-8 character set.
        Parameters:
        queryString - True if the target is a query string.
        Returns:
        The encoded form.
        Throws:
        java.io.IOException
      • encode

        public java.lang.String encode​(char separator,
                                       boolean queryString)
                                throws java.io.IOException
        URL encodes the form.
        Parameters:
        separator - The separator character to append between parameters.
        queryString - True if the target is a query string.
        Returns:
        The encoded form.
        Throws:
        java.io.IOException
      • getEntries

        public Series<FormData> getEntries()
        Returns the modifiable series of form entries.
        Returns:
        The modifiable series of form entries.
      • getMatrixString

        public java.lang.String getMatrixString()
        Formats the form as a matrix path string. Uses UTF-8 as the character set for encoding non-ASCII characters.
        Returns:
        The form as a matrix string.
        See Also:
        Matrix URIs by Tim Berners Lee
      • getMultipartBoundary

        public java.lang.String getMultipartBoundary()
        Returns the boundary separating multipart entries.
        Returns:
        The boundary separating multipart entries.
      • getQueryString

        public java.lang.String getQueryString()
        Formats the form as a query string. Uses UTF-8 as the character set for encoding non-ASCII characters.
        Returns:
        The form as a query string.
      • isMultipart

        public boolean isMultipart()
        Indicates if the form is multipart encoded.
        Returns:
        True if the form is multipart encoded.
      • setMultipart

        public void setMultipart​(boolean multipart)
        Indicates if the form is multipart encoded.
        Parameters:
        multipart - True if the form is multipart encoded.
      • setMultipartBoundary

        public void setMultipartBoundary​(java.lang.String boundary)
        Sets the boundary separating multipart entries.
        Parameters:
        boundary - The boundary separating multipart entries.
      • write

        public void write​(java.io.OutputStream outputStream)
                   throws java.io.IOException
        Description copied from class: Representation
        Writes the representation to a byte stream. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.

        Note that the class implementing this method shouldn't flush or close the given OutputStream after writing to it as this will be handled by the Restlet connectors automatically.
        Specified by:
        write in class Representation
        Parameters:
        outputStream - The output stream.
        Throws:
        java.io.IOException