|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wings.SComponent
org.wings.SFileChooser
public class SFileChooser
Shows a textfield with a browse-button to enter a filename. The file is uploaded via HTTP and made accessible to the WingS application.
The uploaded file is stored temporarily in the filesystem of the
server with a unique name, so that uploaded files with the same
filename do not clash. You can access this internal name with
the getFileDir() and getFileId() methods.
The user provided filename can be queried with the
getFileName() method.
File.delete() it, when you are done with it.
However, if you don't delete the file yourself, it is eventually
being removed by the Java garbage collector, if you haven't renamed it
(see getFile()).
The form, you add this SFileChooser to, needs to have the encoding type
multipart/form-data set
(form.setEncodingType("multipart/form-data")).
This is handled by the form. You can explicitly set it via the above
method, though, in order to increase speed.
You can limit the size of files to be uploaded, so it is hard to make
a denial-of-service (harddisk, bandwidth) attack from outside to your
server. You can modify the maximum content length to be posted in
Session.setMaxContentLength(int). This is
64 kByte by default, so you might want to change this in your application.
MultipartRequest).
At that time, only a partial input is
read, the rest is discarded to thwart denial of service attacks. Since we
read only part of the input, we cannot make sure, that all
parameters are gathered from the input, thus we cannot just deliver the
events contained, since they might be incomplete. However, the file
chooser needs to be informed, that something went wrong as to present
an error message to the user. So in that case, only one event
is delivered to the enclosing form, that contains this
SFileChooser.
Note, that in this case, this will not trigger the action
listener that you might have added to the submit-button.
This means, that you always should add your action listener
to the SForm (SForm.addActionListener(java.awt.event.ActionListener)),
not the submit button.
| Field Summary | |
|---|---|
protected int |
columns
maximum visible amount of characters in the file chooser. |
protected org.wings.SFileChooser.TempFile |
currentFile
the temporary file created on upload. |
protected IOException |
exception
the temporary file created on upload. |
protected String |
fileDir
|
protected String |
fileId
|
protected String |
fileName
|
protected String |
fileNameFilter
|
protected String |
fileType
|
protected Class |
filter
|
| Fields inherited from class org.wings.SComponent |
|---|
DONE_RENDERING, dynamicStyles, enabled, propertyChangeSupport, SELECTOR_ALL, START_RENDERING, visible, WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_FRAME |
| Constructor Summary | |
|---|---|
SFileChooser()
Creates a new FileChooser. |
|
| Method Summary | |
|---|---|
void |
fireIntermediateEvents()
fire events which describes a "in progress" state change, like TreeWillExpand, or ListSelectionEvent with getIsAdjusting() true, ... |
int |
getColumns()
returns the number of visible columns. |
File |
getFile()
Deprecated. use getSelectedFile() instead. |
String |
getFileDir()
Returns the name of the system directory, the file has been stored temporarily in. |
String |
getFileId()
Returns the internal ID of this file, that has been assigned at upload time. |
String |
getFileName()
Returns the filename, that has been given by the user in the upload text-field. |
String |
getFileNameFilter()
returns the current filename filter. |
String |
getFileType()
Returns the mime type of this file, if known. |
protected SForm |
getParentForm()
Find the form, this FileChooser is embedded in. |
File |
getSelectedFile()
returns the file, that has been uploaded. |
Class |
getUploadFilter()
Returns the upload filter set in setUploadFilter(Class) |
FilterOutputStream |
getUploadFilterInstance()
|
boolean |
isEpochCheckEnabled()
Asks the low-level event listener if epoch checking should be perfomed on it. |
protected void |
notifyParentForm()
notifies the parent form, to fire action performed. |
void |
parentFrameAdded(SParentFrameEvent e)
Called, whenever a parentFrame reference is added to the container. |
void |
parentFrameRemoved(SParentFrameEvent e)
Called, whenever a parentFrame reference is removed from the container. |
void |
processLowLevelEvent(String action,
String[] values)
Deliver low level/http events (parameters). |
void |
reset()
resets this FileChooser (no file selected). |
void |
setCG(FileChooserCG cg)
|
void |
setColumns(int c)
Set the visible amount of columns in the textfield. |
void |
setEpochCheckEnabled(boolean epochCheckEnabled)
|
void |
setFileNameFilter(String mimeFilter)
Unlike the swing filechooser that allows to match certain file-suffices, this sets the mimetype to be accepted. |
void |
setUploadFilter(Class filter)
An FilterOutputStream, that filters incoming files. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.wings.LowLevelEventListener |
|---|
fireFinalEvents, getLowLevelEventId, getName, isEnabled |
| Field Detail |
|---|
protected int columns
protected String fileNameFilter
protected Class filter
protected String fileDir
protected String fileName
protected String fileId
protected String fileType
protected org.wings.SFileChooser.TempFile currentFile
protected IOException exception
| Constructor Detail |
|---|
public SFileChooser()
| Method Detail |
|---|
protected final SForm getParentForm()
protected final void notifyParentForm()
public void parentFrameAdded(SParentFrameEvent e)
SParentFrameListenerframe.add(component).
parentFrameAdded in interface SParentFrameListenerpublic void parentFrameRemoved(SParentFrameEvent e)
SParentFrameListener
parentFrameRemoved in interface SParentFrameListenerpublic void setColumns(int c)
c - columns; '-1' sets the default that is browser dependent.public int getColumns()
public void setFileNameFilter(String mimeFilter)
text/html or can contain
a wildcard in the subtype like text/ *. Some browsers
may as well accept a file-suffix wildcard as well.
In any case, you hould check the result, since you cannot assume, that the browser actually does filter. Worse, browsers may not guess the correct type so users cannot upload a file even if it has the correct type. So, bottomline, it is generally a good idea to let the file name filter untouched, unless you know bugs of the browser at the other end of the wire...
mimeFilter - the mime type to be filtered.public String getFileNameFilter()
setFileNameFilter(String)
public String getFileName()
throws IOException
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))
public String getFileDir()
throws IOException
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))
public String getFileId()
throws IOException
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))
public String getFileType()
throws IOException
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))
public File getSelectedFile()
throws IOException
getFileName() instead.
The file returned here will delete itself if you loose the reference to it and it is garbage collected to avoid filling up the filesystem (This doesn't mean, that you shouldn't be a good programmer and delete the file yourself, if you don't need it anymore :-). If you rename() the file to use it somewhere else, it is regarded not temporary anymore and thus will not be removed from the filesystem.
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))public void reset()
public File getFile()
throws IOException
getSelectedFile() instead.
getFileName() instead.
The file returned here will delete itself if you loose the reference to it and it is garbage collected to avoid filling up the filesystem (This doesn't mean, that you shouldn't be a good programmer and delete the file yourself, if you don't need it anymore :-). If you rename() the file to use it somewhere else, it is regarded not temporary anymore and thus will not be removed from the filesystem.
IOException - if something went wrong with the upload (most
likely, the maximum allowed filesize is exceeded, see
Session.setMaxContentLength(int))public void setUploadFilter(Class filter)
filter - the Class that is instanciated to filter incoming
files.public Class getUploadFilter()
setUploadFilter(Class)
public FilterOutputStream getUploadFilterInstance()
public void setCG(FileChooserCG cg)
public void processLowLevelEvent(String action,
String[] values)
LowLevelEventListener
processLowLevelEvent in interface LowLevelEventListenerprocessLowLevelEvent in class SComponentaction - the name-value-pair's namevalues - the name-value-pair's valuespublic void fireIntermediateEvents()
LowLevelEventListener
fireIntermediateEvents in interface LowLevelEventListenerpublic boolean isEpochCheckEnabled()
LowLevelEventListenertrue the Dispatcher will ignore request originating from old views
(typically iniated by triggering browser back and clicking somewhere.)
isEpochCheckEnabled in interface LowLevelEventListenertrue if epoch checking should be perfomed, false
if all request for this component should be processed.LowLevelEventListener.isEpochCheckEnabled()public void setEpochCheckEnabled(boolean epochCheckEnabled)
LowLevelEventListener.isEpochCheckEnabled()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||