org.appng.forms.impl

## Class FormUploadBean

- java.lang.Object
- - org.appng.forms.impl.FormUploadBean

- All Implemented Interfaces:
    FormUpload

      public class FormUploadBean
      extends Object
      implements FormUpload

  Default `FormUpload` implementation.
  Author:
    Matthias Müller

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FormUploadBean(File file, String originalName, String contentType, List<String> acceptedTypes, long maxSize)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<String>` | `getAcceptedTypes()` Returns a `List` of accepted file-extensions (without `.`)/content-types for this `FormUpload`.
    `byte[]` | `getBytes()` Returns the bytes of the uploaded `File`.
    `String` | `getContentType()` Returns the content-type (if any) for this `FormUpload`.
    `File` | `getFile()` Returns the `File` which has been locally saved, but only if `FormUpload.isValid()` returns `true`.
    `long` | `getMaxSize()` Returns the maximum size (in bytes) for the uploaded `File` (default: -1, which means there is no limit).
    `long` | `getMinSize()` Returns the minimum size (in bytes) for the uploaded file (default: 0).
    `String` | `getOriginalFilename()` Returns the name of the original (without any path prefix) file which was uploaded.
    `boolean` | `isValid()` Returns `true` if, and only if, all of those methods return `true`: `FormUpload.isValidFile()` `FormUpload.isValidSize()` `FormUpload.isValidType()`
    `boolean` | `isValid(Class<? extends FormUploadValidator> validatorClass)` Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
    `boolean` | `isValid(FormUploadValidator validator)` Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
    `boolean` | `isValid(String[] types, long minSize, long maxSize)` Checks whether this `FormUpload` has one of the given types and matches the given size restrictions.
    `boolean` | `isValidFile()` Checks whether the `File` for this `FormUpload` exists and `File.isFile()` returns `true` .
    `boolean` | `isValidSize()` Checks whether the `File` has a valid size.
    `boolean` | `isValidType()` Checks whether the `File`'s extension or content-type are contained in the list of accepted types for this `FormUpload`.
    `long` | `size()` Returns the size (in bytes) of the uploaded `File`.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### FormUploadBean

          public FormUploadBean(File file,
                                String originalName,
                                String contentType,
                                List<String> acceptedTypes,
                                long maxSize)

  - ### Method Detail

    - #### getAcceptedTypes

          public List<String> getAcceptedTypes()

      Description copied from interface: `FormUpload`
      Returns a `List` of accepted file-extensions (without `.`)/content-types for this `FormUpload`.
      Specified by:
        `getAcceptedTypes` in interface `FormUpload`
      Returns:
        the list of accepted types
      See Also:
        `FormUpload.getContentType()`

    - #### getOriginalFilename

          public String getOriginalFilename()

      Description copied from interface: `FormUpload`
      Returns the name of the original (without any path prefix) file which was uploaded.
      Specified by:
        `getOriginalFilename` in interface `FormUpload`
      Returns:
        the name of the original file

    - #### getFile

          public File getFile()

      Description copied from interface: `FormUpload`
      Returns the `File` which has been locally saved, but only if `FormUpload.isValid()` returns `true`. The name of this file may have nothing to do with the file's original name.
      Specified by:
        `getFile` in interface `FormUpload`
      Returns:
        the `File`, or `null` if no file was uploaded or `FormUpload.isValid()` returns `false`
      See Also:
        `FormUpload.getOriginalFilename()`

    - #### size

          public long size()

      Description copied from interface: `FormUpload`
      Returns the size (in bytes) of the uploaded `File`.
      Specified by:
        `size` in interface `FormUpload`
      Returns:
        the size

    - #### getMaxSize

          public long getMaxSize()

      Description copied from interface: `FormUpload`
      Returns the maximum size (in bytes) for the uploaded `File` (default: -1, which means there is no limit).
      Specified by:
        `getMaxSize` in interface `FormUpload`
      Returns:
        the maximum size

    - #### getMinSize

          public long getMinSize()

      Description copied from interface: `FormUpload`
      Returns the minimum size (in bytes) for the uploaded file (default: 0).
      Specified by:
        `getMinSize` in interface `FormUpload`
      Returns:
        the minimum size

    - #### getBytes

          public byte[] getBytes()

      Description copied from interface: `FormUpload`
      Returns the bytes of the uploaded `File`.
      Specified by:
        `getBytes` in interface `FormUpload`
      Returns:
        the bytes

    - #### isValidSize

          public boolean isValidSize()

      Description copied from interface: `FormUpload`
      Checks whether the `File` has a valid size. Note that by default, there is no minimum size. The default maximum size is provided by the concrete `FormUpload`.
      Specified by:
        `isValidSize` in interface `FormUpload`
      Returns:
        `true` if the file's size is valid, `false` otherwise
      See Also:
        `FormUpload.isValid(String[], long, long)`, `FormUpload.getMinSize()`, `FormUpload.getMaxSize()`

    - #### isValid

          public boolean isValid()

      Description copied from interface: `FormUpload`
      Returns `true` if, and only if, all of those methods return `true`:
      - `FormUpload.isValidFile()`
      - `FormUpload.isValidSize()`
      - `FormUpload.isValidType()`
      Specified by:
        `isValid` in interface `FormUpload`
      Returns:
        `true` if this `FormUpload` is valid, `false` otherwise.

    - #### isValid

          public boolean isValid(String[] types,
                                 long minSize,
                                 long maxSize)

      Description copied from interface: `FormUpload`
      Checks whether this `FormUpload` has one of the given types and matches the given size restrictions. Delegates to `FormUpload.isValidSize()` and `FormUpload.isValidType()`.
      Specified by:
        `isValid` in interface `FormUpload`
      Parameters:
        `types` - an array containing the allowed file-extensions (without `.`) and content-types
        `minSize` - the minimum size of the file (in bytes)
        `maxSize` - the maximum size of the file (in bytes)
      Returns:
        `true` if this `FormUpload` is valid, `false` otherwise.
      See Also:
        `FormUpload.isValidSize()`, `FormUpload.isValidType()`, `FormUpload.getContentType()`, `FormUpload.getAcceptedTypes()`

    - #### isValid

          public boolean isValid(FormUploadValidator validator)

      Description copied from interface: `FormUpload`
      Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
      Specified by:
        `isValid` in interface `FormUpload`
      Parameters:
        `validator` - a `FormUploadValidator`
      Returns:
        the result returned by `FormUploadValidator.isValid(FormUpload)`

    - #### isValid

          public boolean isValid(Class<? extends FormUploadValidator> validatorClass)

      Description copied from interface: `FormUpload`
      Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
      Specified by:
        `isValid` in interface `FormUpload`
      Parameters:
        `validatorClass` - a type extending `FormUploadValidator`
      Returns:
        the result returned by `FormUploadValidator.isValid(FormUpload)`

    - #### isValidFile

          public boolean isValidFile()

      Description copied from interface: `FormUpload`
      Checks whether the `File` for this `FormUpload` exists and `File.isFile()` returns `true` .
      Specified by:
        `isValidFile` in interface `FormUpload`
      Returns:
        `true` if the `File` is valid, `false` otherwise

    - #### isValidType

          public boolean isValidType()

      Description copied from interface: `FormUpload`
      Checks whether the `File`'s extension or content-type are contained in the list of accepted types for this `FormUpload`. If `FormUpload.getAcceptedTypes()` is `null` or empty, all types are allowed.
      Specified by:
        `isValidType` in interface `FormUpload`
      Returns:
        `true` if the uploaded `File` has a valid type, `false` otherwise.
      See Also:
        `FormUpload.getAcceptedTypes()`, `FormUpload.getContentType()`

    - #### getContentType

          public String getContentType()

      Description copied from interface: `FormUpload`
      Returns the content-type (if any) for this `FormUpload`. Usually the content-type has been retrieved using `ServletRequest.getContentType()`
      Specified by:
        `getContentType` in interface `FormUpload`
      Returns:
        the content type for this `FormUpload`, or `null`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.