org.olat.core.gui.components.form.flexible.impl.elements
Class FileElementImpl

java.lang.Object
  extended by org.olat.core.gui.components.form.flexible.impl.FormItemImpl
      extended by org.olat.core.gui.components.form.flexible.impl.elements.FileElementImpl
All Implemented Interfaces:
FileElement, InlineElement, FormBaseComponentIdProvider, FormItem, FormMultipartItem, Disposable

public class FileElementImpl
extends FormItemImpl
implements FileElement, Disposable

Description:

Implementation of the file element. See the interface for more documentation.

The class implements the disposable interface to cleanup temporary files on form disposal.

Initial Date: 08.12.2008

Author:
Florian Gnaegi, frentix GmbH, http://www.frentix.com

Field Summary
 
Fields inherited from interface org.olat.core.gui.components.form.flexible.elements.FileElement
UPLOAD_ONE_MEGABYTE, UPLOAD_UNLIMITED
 
Fields inherited from interface org.olat.core.gui.components.form.flexible.FormItem
ERRORC, EXAMPLEC, LABELC
 
Fields inherited from interface org.olat.core.gui.components.form.flexible.FormBaseComponentIdProvider
DISPPREFIX
 
Constructor Summary
FileElementImpl(java.lang.String name)
          Constructor for a file element.
 
Method Summary
 void dispose()
          disposes the disposable
 void evalFormRequest(UserRequest ureq)
          gets called if the implementing component is part of a form which gets partly submitted -> extract data for you and store it temporarly for redisplay without a validation
 java.io.File getInitialFile()
          Get the initial file value
 int getMaxUploadSizeKB()
           
 java.util.Set<java.lang.String> getMimeTypeLimitations()
          Get the set of the mime types limitation
 java.io.File getUploadFile()
          Use the upload file only for temporary checks on the file.
 java.lang.String getUploadFileName()
           
 java.io.InputStream getUploadInputStream()
          Get the input stream of the uploaded file to copy it to some other place
 java.lang.String getUploadMimeType()
           
 long getUploadSize()
          Get the size of the uploaded file
 boolean isUploadSuccess()
           
 void limitToMimeType(java.util.Set<java.lang.String> mimeTypes, java.lang.String i18nErrKey, java.lang.String[] i18nArgs)
          Set a mime type limitation on which files are allowed in the upload process.
 java.io.File moveUploadFileTo(java.io.File destinationDir)
          Move the uploaded file from the temporary location to the given destination directory.
 void reset()
          reset the data in the field to a initial/predefined value.
 void setInitialFile(java.io.File initialFile)
          Set an initial value for the file element.
 void setMandatory(boolean mandatory, java.lang.String i18nErrKey)
          Set this form element mandatory.
 void setMaxUploadSizeKB(int maxUploadSizeKB, java.lang.String i18nErrKey, java.lang.String[] i18nArgs)
          Set the KB that are allowed in the file upload.
 void validate(java.util.List validationResults)
          validate the data in the field, create error messages or update any component.
 
Methods inherited from class org.olat.core.gui.components.form.flexible.impl.FormItemImpl
addActionListener, clearError, doDispatchFormRequest, getAction, getActionListenersFor, getComponent, getEmptyDisplayText, getErrorC, getErrorText, getExampleC, getExampleText, getFormDispatchId, getLabelC, getLabelText, getName, getRootForm, getTranslator, getUserObject, hasError, hasExample, hasFocus, hasLabel, isEnabled, isInlineEditingOn, isMandatory, isVisible, setEmptyDisplayText, setEnabled, setErrorComponent, setErrorKey, setExampleKey, setFocus, setLabel, setLabelComponent, setMandatory, setRootForm, setTranslator, setUserObject, setVisible, showError, showExample, showLabel, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.olat.core.gui.components.form.flexible.FormItem
addActionListener, clearError, doDispatchFormRequest, getAction, getActionListenersFor, getComponent, getErrorC, getErrorText, getExampleC, getExampleText, getLabelC, getLabelText, getName, getRootForm, getTranslator, getUserObject, hasError, hasExample, hasFocus, hasLabel, isEnabled, isMandatory, isVisible, setEnabled, setErrorComponent, setErrorKey, setExampleKey, setFocus, setLabel, setLabelComponent, setMandatory, setRootForm, setTranslator, setUserObject, setVisible, showError, showExample, showLabel
 
Methods inherited from interface org.olat.core.gui.components.form.flexible.FormBaseComponentIdProvider
getFormDispatchId
 

Constructor Detail

FileElementImpl

public FileElementImpl(java.lang.String name)
Constructor for a file element. Use the limitToMimeType and setter methods to configure the element

Parameters:
name -
Method Detail

evalFormRequest

public void evalFormRequest(UserRequest ureq)
Description copied from class: FormItemImpl
gets called if the implementing component is part of a form which gets partly submitted -> extract data for you and store it temporarly for redisplay without a validation

Specified by:
evalFormRequest in interface FormItem
Specified by:
evalFormRequest in class FormItemImpl
See Also:
FormItemImpl.evalFormRequest(org.olat.core.gui.UserRequest)

reset

public void reset()
Description copied from interface: FormItem
reset the data in the field to a initial/predefined value. This method is called if in a form a reset request is issued. It is the counterpart to the validate call which

Specified by:
reset in interface FormItem
Specified by:
reset in class FormItemImpl
See Also:
FormItemImpl.reset()

setMandatory

public void setMandatory(boolean mandatory,
                         java.lang.String i18nErrKey)
Description copied from interface: FileElement
Set this form element mandatory.

Specified by:
setMandatory in interface FileElement
Parameters:
mandatory - true: is mandatory; false: is optional
i18nErrKey - i18n key used in case user did not upload something
See Also:
FileElement.setMandatory(boolean, java.lang.String)

validate

public void validate(java.util.List validationResults)
Description copied from interface: FormItem
validate the data in the field, create error messages or update any component.

This method must be implemented by a specialised form item provider.

Specified by:
validate in interface FormItem
Specified by:
validate in class FormItemImpl
See Also:
FormItemImpl.validate(java.util.List)

setInitialFile

public void setInitialFile(java.io.File initialFile)
Description copied from interface: FileElement
Set an initial value for the file element. Optional. Use this to preload your file element with a previously submitted file.

Specified by:
setInitialFile in interface FileElement
See Also:
FileElement.setInitialFile(java.io.File)

getInitialFile

public java.io.File getInitialFile()
Description copied from interface: FileElement
Get the initial file value

Specified by:
getInitialFile in interface FileElement
Returns:
the file or NULL if not set
See Also:
FileElement.getInitialFile()

limitToMimeType

public void limitToMimeType(java.util.Set<java.lang.String> mimeTypes,
                            java.lang.String i18nErrKey,
                            java.lang.String[] i18nArgs)
Description copied from interface: FileElement
Set a mime type limitation on which files are allowed in the upload process. Wildcards like image/* are also allowed.

Specified by:
limitToMimeType in interface FileElement
i18nErrKey - i18n key used in case user uploaded wrong files
i18nArgs - optional arguments for thei18nErrKey
See Also:
FileElement.limitToMimeType(java.util.Set, java.lang.String, java.lang.String[])

getMimeTypeLimitations

public java.util.Set<java.lang.String> getMimeTypeLimitations()
Description copied from interface: FileElement
Get the set of the mime types limitation

Specified by:
getMimeTypeLimitations in interface FileElement
Returns:
Set containing mime types. Can be empty but is never NULL.
See Also:
FileElement.getMimeTypeLimitations()

setMaxUploadSizeKB

public void setMaxUploadSizeKB(int maxUploadSizeKB,
                               java.lang.String i18nErrKey,
                               java.lang.String[] i18nArgs)
Description copied from interface: FileElement
Set the KB that are allowed in the file upload. In case the user uploads too much, the error with the given key will be displayed.
Use UPLOAD_UNLIMITED to set no limit.

Specified by:
setMaxUploadSizeKB in interface FileElement
Parameters:
maxUploadSizeKB - max file size in KB
i18nErrKey - i18n key used in case user uploaded to big file
i18nArgs - optional arguments for thei18nErrKey
See Also:
FileElement.setMaxUploadSizeKB(int, java.lang.String, java.lang.String[])

getMaxUploadSizeKB

public int getMaxUploadSizeKB()
Specified by:
getMaxUploadSizeKB in interface FormMultipartItem
See Also:
FormMultipartItem.getMaxUploadSizeKB()

isUploadSuccess

public boolean isUploadSuccess()
Specified by:
isUploadSuccess in interface FileElement
Returns:
true: file has been uploaded; false: file has not been uploaded
See Also:
FileElement.isUploadSuccess()

getUploadFileName

public java.lang.String getUploadFileName()
Specified by:
getUploadFileName in interface FileElement
Returns:
The filename of the uploaded file
See Also:
FileElement.getUploadFileName()

getUploadMimeType

public java.lang.String getUploadMimeType()
Specified by:
getUploadMimeType in interface FileElement
Returns:
The mime type of the uploaded file
See Also:
FileElement.getUploadMimeType()

getUploadFile

public java.io.File getUploadFile()
Description copied from interface: FileElement
Use the upload file only for temporary checks on the file. Use the moveUploadFileTo() to move the file to the final destination. The temp file will be deleted on form disposal.

Specified by:
getUploadFile in interface FileElement
Returns:
A reference to the uploaded file
See Also:
FileElement.getUploadFile()

getUploadInputStream

public java.io.InputStream getUploadInputStream()
Description copied from interface: FileElement
Get the input stream of the uploaded file to copy it to some other place

Specified by:
getUploadInputStream in interface FileElement
Returns:
See Also:
FileElement.getUploadInputStream()

getUploadSize

public long getUploadSize()
Description copied from interface: FileElement
Get the size of the uploaded file

Specified by:
getUploadSize in interface FileElement
Returns:
See Also:
FileElement.getUploadSize()

moveUploadFileTo

public java.io.File moveUploadFileTo(java.io.File destinationDir)
Description copied from interface: FileElement
Move the uploaded file from the temporary location to the given destination directory.

If in the destination a file with the given name does already exist, rename the file accordingly

Specified by:
moveUploadFileTo in interface FileElement
Returns:
A reference to the moved file or NULL if file could not be moved
See Also:
FileElement.moveUploadFileTo(java.io.File)

dispose

public void dispose()
Description copied from interface: Disposable
disposes the disposable

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()