| java.lang.Object org.wings.SComponent org.wings.SFileChooser
SFileChooser | public class SFileChooser extends SComponent implements LowLevelEventListener,SParentFrameListener(Code) | | 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
SFileChooser.getFileDir() and
SFileChooser.getFileId() methods.
The user provided filename can be queried with the
SFileChooser.getFileName() method.
Since the file is stored temporarily in the filesystem, you should
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
SFileChooser.getFile() ).
The form, you add this SFileChooser to, needs to have the encoding type
multipart/form-data set
(form.
SForm.setEncodingType(String) 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
org.wings.session.Session.setMaxContentLength(int) . This is
64 kByte by default, so you might want to change this in your application.
The SFileChooser notifies the form if something has gone
wrong with uploading a file.
Szenario
Files that are too big to be uploaded are blocked
very early in the upload-process (if you are curious: this is done in
org.wings.session.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.
author: Holger Engels author: Henner Zeller |
Constructor Summary | |
public | SFileChooser() Creates a new FileChooser. |
Method Summary | |
public void | fireIntermediateEvents() | public int | getColumns() returns the number of visible columns. | public File | getFile() returns the file, that has been uploaded. | public String | getFileDir() Returns the name of the system directory, the file has been stored
temporarily in. | public String | getFileId() Returns the internal ID of this file, that has been assigned at upload
time. | public String | getFileName() Returns the filename, that has been given by the user in the
upload text-field. | public String | getFileNameFilter() returns the current filename filter. | public String | getFileType() Returns the mime type of this file, if known. | final protected SForm | getParentForm() Find the form, this FileChooser is embedded in. | public File | getSelectedFile() returns the file, that has been uploaded. | public Class | getUploadFilter() | public FilterOutputStream | getUploadFilterInstance() | public boolean | isEpochCheckEnabled() | final protected void | notifyParentForm() notifies the parent form, to fire action performed. | public void | parentFrameAdded(SParentFrameEvent e) | public void | parentFrameRemoved(SParentFrameEvent e) | public void | processLowLevelEvent(String action, String[] values) | public void | reset() resets this FileChooser (no file selected). | public void | setCG(FileChooserCG cg) | public void | setColumns(int c) Set the visible amount of columns in the textfield. | public void | setEpochCheckEnabled(boolean epochCheckEnabled) | public void | setFileNameFilter(String mimeFilter) Unlike the swing filechooser that allows to match certain file-suffices,
this sets the mimetype to be accepted. | public void | setUploadFilter(Class filter) An FilterOutputStream, that filters incoming files. |
columns | protected int columns(Code) | | maximum visible amount of characters in the file chooser.
|
currentFile | protected TempFile currentFile(Code) | | the temporary file created on upload. This file is automatically
removed if and when it is not accessible anymore.
|
exception | protected IOException exception(Code) | | the temporary file created on upload. This file is automatically
removed if and when it is not accessible anymore.
|
SFileChooser | public SFileChooser()(Code) | | Creates a new FileChooser.
|
fireIntermediateEvents | public void fireIntermediateEvents()(Code) | | |
getColumns | public int getColumns()(Code) | | returns the number of visible columns.
number of visible columns. |
getFile | public File getFile() throws IOException(Code) | | returns the file, that has been uploaded. Use this, to open and
read from the file uploaded by the user. Don't use this method
to query the actual filename given by the user, since this file
wraps a system generated file with a different (unique) name.
Use
SFileChooser.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.
a File to access the content of the uploaded file. throws: IOException - if something went wrong with the upload (mostlikely, the maximum allowed filesize is exceeded, seeorg.wings.session.Session.setMaxContentLength(int))org.wings.SFileChooser.getSelectedFile |
getFileDir | public String getFileDir() throws IOException(Code) | | Returns the name of the system directory, the file has been stored
temporarily in. You won't need this, unless you want to access the
file directly. Don't store the value you receive here for use later,
since the SFileChooser does its own garbage collecting of unused files.
the pathname of the system directory, the file is stored in. throws: IOException - if something went wrong with the upload (mostlikely, the maximum allowed filesize is exceeded, seeorg.wings.session.Session.setMaxContentLength(int)) |
getFileId | public String getFileId() throws IOException(Code) | | Returns the internal ID of this file, that has been assigned at upload
time. This ID is unique to prevent clashes with other uploaded files.
You won't need this, unless you want to access the file directly. Don't
store the value you receive here for later use, since the SFileChooser
does its own garbage collecting of unused files.
the internal, unique file id given to the uploaded file. throws: IOException - if something went wrong with the upload (mostlikely, the maximum allowed filesize is exceeded, seeorg.wings.session.Session.setMaxContentLength(int)) |
getParentForm | final protected SForm getParentForm()(Code) | | Find the form, this FileChooser is embedded in.
|
getSelectedFile | public File getSelectedFile() throws IOException(Code) | | returns the file, that has been uploaded. Use this, to open and
read from the file uploaded by the user. Don't use this method
to query the actual filename given by the user, since this file
wraps a system generated file with a different (unique) name.
Use
SFileChooser.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.
a File to access the content of the uploaded file. throws: IOException - if something went wrong with the upload (mostlikely, the maximum allowed filesize is exceeded, seeorg.wings.session.Session.setMaxContentLength(int)) |
notifyParentForm | final protected void notifyParentForm()(Code) | | notifies the parent form, to fire action performed. This is necessary,
if an exception in parsing a MultiPartRequest occurs, e.g. upload
file is too big.
|
processLowLevelEvent | public void processLowLevelEvent(String action, String[] values)(Code) | | |
reset | public void reset()(Code) | | resets this FileChooser (no file selected). It does not remove an
upload filter!.
reset() will not remove a previously selected file from
the local tmp disk space, so as long as you have a reference to
such a file, you can still access it. If you don't have a reference
to the file, it will automatically be removed when the file object
is garbage collected.
|
setColumns | public void setColumns(int c)(Code) | | Set the visible amount of columns in the textfield.
Parameters: c - columns; '-1' sets the default that is browser dependent. |
setFileNameFilter | public void setFileNameFilter(String mimeFilter)(Code) | | Unlike the swing filechooser that allows to match certain file-suffices,
this sets the mimetype to be accepted. This filter may be fully
qualified like 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...
Parameters: mimeFilter - the mime type to be filtered. |
setUploadFilter | public void setUploadFilter(Class filter)(Code) | | An FilterOutputStream, that filters incoming files. You can use
UploadFilters to inspect the stream or rewrite it to some own
format.
Parameters: filter - the Class that is instanciated to filter incomingfiles. |
Methods inherited from org.wings.SComponent | final public void addComponentListener(SComponentListener l)(Code)(Java Doc) public void addDynamicStyle(Style style)(Code)(Java Doc) final protected void addEventListener(Class<T> type, T listener)(Code)(Java Doc) public void addNotify()(Code)(Java Doc) final public void addParentFrameListener(SParentFrameListener l)(Code)(Java Doc) final public void addRenderListener(SRenderListener renderListener)(Code)(Java Doc) final public void addScriptListener(ScriptListener listener)(Code)(Java Doc) public void addStyle(String additionalCssClassName)(Code)(Java Doc) public Object clone()(Code)(Java Doc) protected void fireComponentChangeEvent(SComponentEvent aEvent)(Code)(Java Doc) public void fireFinalEvents()(Code)(Java Doc) protected void fireKeyEvents()(Code)(Java Doc) final public void fireRenderEvent(int type)(Code)(Java Doc) public ActionMap getActionMap()(Code)(Java Doc) public Color getBackground()(Code)(Java Doc) public SBorder getBorder()(Code)(Java Doc) public ComponentCG getCG()(Code)(Java Doc) final public Object getClientProperty(Object key)(Code)(Java Doc) public SPopupMenu getComponentPopupMenu()(Code)(Java Doc) public Style getDynamicStyle(Selector selector)(Code)(Java Doc) public Collection getDynamicStyles()(Code)(Java Doc) public int getFocusTraversalIndex()(Code)(Java Doc) public SFont getFont()(Code)(Java Doc) public Color getForeground()(Code)(Java Doc) public int getHorizontalAlignment()(Code)(Java Doc) public InputMap getInputMap()(Code)(Java Doc) public InputMap getInputMap(int condition)(Code)(Java Doc) final protected int getListenerCount(Class type)(Code)(Java Doc) final protected Object[] getListenerList()(Code)(Java Doc) final public EventListener[] getListeners(Class<? extends EventListener> type)(Code)(Java Doc) public String getLowLevelEventId()(Code)(Java Doc) final public String getName()(Code)(Java Doc) final public SContainer getParent()(Code)(Java Doc) public SFrame getParentFrame()(Code)(Java Doc) public SDimension getPreferredSize()(Code)(Java Doc) public RequestURL getRequestURL()(Code)(Java Doc) public boolean getResidesInForm()(Code)(Java Doc) public List<ScriptListener> getScriptListenerList()(Code)(Java Doc) public ScriptListener[] getScriptListeners()(Code)(Java Doc) final public Session getSession()(Code)(Java Doc) public boolean getShowAsFormComponent()(Code)(Java Doc) public String getStyle()(Code)(Java Doc) public String getToolTipText()(Code)(Java Doc) public int getVerticalAlignment()(Code)(Java Doc) public void invite(ComponentVisitor visitor) throws Exception(Code)(Java Doc) protected static boolean isDifferent(Object oldObject, Object newObject)(Code)(Java Doc) public boolean isEnabled()(Code)(Java Doc) public boolean isFocusOwner()(Code)(Java Doc) public boolean isRecursivelyVisible()(Code)(Java Doc) public boolean isReloadForced()(Code)(Java Doc) protected boolean isUpdatePossible()(Code)(Java Doc) public boolean isVisible()(Code)(Java Doc) protected String paramString()(Code)(Java Doc) protected void processComponentEvent(SComponentListener listener, SComponentEvent e)(Code)(Java Doc) protected boolean processKeyEvents(String[] values)(Code)(Java Doc) protected void processLowLevelEvent(String name, String[] values)(Code)(Java Doc) final public void putClientProperty(Object key, Object value)(Code)(Java Doc) final void register()(Code)(Java Doc) public void reload()(Code)(Java Doc) final protected void reloadIfChange(Object oldVal, Object newVal)(Code)(Java Doc) final protected void reloadIfChange(int oldVal, int newVal)(Code)(Java Doc) final protected void reloadIfChange(boolean oldVal, boolean newVal)(Code)(Java Doc) final protected void reloadIfChange(byte oldVal, byte newVal)(Code)(Java Doc) final protected void reloadIfChange(short oldVal, short newVal)(Code)(Java Doc) final protected void reloadIfChange(long oldVal, long newVal)(Code)(Java Doc) final protected void reloadIfChange(float oldVal, float newVal)(Code)(Java Doc) final protected void reloadIfChange(double oldVal, double newVal)(Code)(Java Doc) final protected void reloadIfChange(char oldVal, char newVal)(Code)(Java Doc) final public void removeComponentListener(SComponentListener l)(Code)(Java Doc) public void removeDynamicStyle(Selector selector)(Code)(Java Doc) final protected void removeEventListener(Class<T> type, T listener)(Code)(Java Doc) public void removeNotify()(Code)(Java Doc) final public void removeParentFrameListener(SParentFrameListener l)(Code)(Java Doc) final public void removeRenderListener(SRenderListener renderListener)(Code)(Java Doc) final public void removeScriptListener(ScriptListener listener)(Code)(Java Doc) public void removeStyle(String cssStyleClassName)(Code)(Java Doc) public void requestFocus()(Code)(Java Doc) public void scrollRectToVisible(Rectangle aRect)(Code)(Java Doc) public void setActionMap(ActionMap actionMap)(Code)(Java Doc) public void setAttribute(String cssPropertyName, String value)(Code)(Java Doc) public void setAttribute(CSSProperty property, String propertyValue)(Code)(Java Doc) public void setAttribute(Selector selector, CSSProperty property, String propertyValue)(Code)(Java Doc) public void setAttribute(Selector selector, CSSProperty property, SIcon icon)(Code)(Java Doc) public void setAttribute(Selector selector, CSSProperty property, Color color)(Code)(Java Doc) public void setAttributes(Selector selector, CSSAttributeSet attributes)(Code)(Java Doc) public void setBackground(Color color)(Code)(Java Doc) public void setBorder(SBorder border)(Code)(Java Doc) public void setCG(ComponentCG newCG)(Code)(Java Doc) public void setComponentPopupMenu(SPopupMenu popupMenu)(Code)(Java Doc) public void setDynamicStyles(Collection dynamicStyles)(Code)(Java Doc) public void setEnabled(boolean enabled)(Code)(Java Doc) public void setFocusTraversalIndex(int index)(Code)(Java Doc) public void setFont(SFont font)(Code)(Java Doc) public void setForeground(Color color)(Code)(Java Doc) public void setHorizontalAlignment(int alignment)(Code)(Java Doc) public void setInputMap(InputMap inputMap)(Code)(Java Doc) public void setInputMap(int condition, InputMap inputMap)(Code)(Java Doc) public void setName(String uniqueName)(Code)(Java Doc) public void setNameRaw(String uncheckedName)(Code)(Java Doc) public void setParent(SContainer parent)(Code)(Java Doc) protected void setParentFrame(SFrame parentFrame)(Code)(Java Doc) public void setPreferredSize(SDimension preferredSize)(Code)(Java Doc) public void setReloadForced(boolean forced)(Code)(Java Doc) public void setShowAsFormComponent(boolean showAsFormComponent)(Code)(Java Doc) public void setStyle(String cssClassName)(Code)(Java Doc) public void setToolTipText(String t)(Code)(Java Doc) public void setVerticalAlignment(int alignment)(Code)(Java Doc) public void setVisible(boolean visible)(Code)(Java Doc) public String toString()(Code)(Java Doc) final void unregister()(Code)(Java Doc) public void update(Update update)(Code)(Java Doc) public void updateCG()(Code)(Java Doc) public void write(Device s) throws IOException(Code)(Java Doc)
|
|
|