wjhk.jupload2.context
Class DefaultJUploadContext

java.lang.Object
  extended by wjhk.jupload2.context.DefaultJUploadContext
All Implemented Interfaces:
JUploadContext
Direct Known Subclasses:
JUploadContextApplet, JUploadContextExecutable

public class DefaultJUploadContext
extends java.lang.Object
implements JUploadContext

The Jupload Context. One such context is created at run time. It can be the Applet, or the 'main' class, depending on the launch type.
It contains the call to the creation of the JUploadPanel, which contains the real code, and some technical stuff that depend on the technical context (mainly applet or stand alone application).
The functional control of JUpload is done by using UploadPolicy. This class should not be changed, in order to remain compatible with next JUpload releases.

Technical note: This class should be abstract. But it is used by the build.xml file, to load the version. So all methods of the JUploadContext interface are implemented. Those who actually can't be coded here, just generate a UnsupportedOperationException exception.

Version:
$Revision: 750 $
Author:
etienne_sf

Nested Class Summary
private static class DefaultJUploadContext.Callback
          This class represent the Callback method.
 
Field Summary
private  JavascriptHandler jsHandler
          variable to hold reference to JavascriptHandler object
private  JUploadPanel jUploadPanel
          The JUploadPanel, which actually contains all the applet components.
private  JUploadTextArea logWindow
          The log messages should go there ...
private  java.util.Properties mimeTypesProperties
          the mime type list, coming from: http://www.mimetype.org/ Thanks to them!
private static java.lang.String RELEASE_VERSION
          The version of this applet.
private  java.util.Properties svnProperties
          The properties, created at build time, by the build.xml ant file.
private static java.lang.String svnPropertiesFilename
          The final that contains the SVN properties.
private  java.util.Vector<DefaultJUploadContext.Callback> unloadCallbacks
          All registered callbacks.
protected  UploadPolicy uploadPolicy
          The current upload policy.
 
Constructor Summary
DefaultJUploadContext()
           
 
Method Summary
 void displayDebug(java.lang.String debug, int minDebugLevel)
          Call to UploadPolicy.displayDebug(String, int)
(package private)  void displayDebugParameterValue(java.lang.String key, java.lang.String value)
          Displays the debug information for the current parameter.
 void displayErr(java.lang.String err)
          Call to UploadPolicy.displayErr(Exception)
 void displayInfo(java.lang.String info)
          Call to UploadPolicy.displayInfo(String)
 void displayURL(java.lang.String url, boolean success)
          Just throws a UnsupportedOperationException exception.
 void displayWarn(java.lang.String warn)
          Call to UploadPolicy.displayWarn(String)
 javax.swing.JApplet getApplet()
          Just throws a UnsupportedOperationException exception.
 java.lang.String getBuildDate()
          
 int getBuildNumber()
          
 java.awt.Cursor getCursor()
          Just throws a UnsupportedOperationException exception.
 java.lang.String getLastModified()
          
 JUploadTextArea getLogWindow()
          Retrieves the current log window of this applet.
 java.lang.String getMimeType(java.lang.String fileExtension)
          Returns the mime type associated with the given file extension.
 boolean getParameter(java.lang.String key, boolean def)
          Just throws a UnsupportedOperationException exception.
 float getParameter(java.lang.String key, float def)
          Just throws a UnsupportedOperationException exception.
 int getParameter(java.lang.String key, int def)
          Just throws a UnsupportedOperationException exception.
 long getParameter(java.lang.String key, long def)
          Just throws a UnsupportedOperationException exception.
 java.lang.String getParameter(java.lang.String key, java.lang.String def)
          Just throws a UnsupportedOperationException exception.
static java.util.Properties getSvnProperties()
          Helper function, to get the Revision number, if available.
 JUploadPanel getUploadPanel()
          Retrieves the current upload panel.
 UploadPolicy getUploadPolicy()
          Retrieves the current upload policy.
 java.lang.String getVersion()
          
 void init(javax.swing.RootPaneContainer rootPaneContainer)
          Reaction on the start of the applet: creation of each specific item of the GUI, and the upload policy.
static void main(java.lang.String[] args)
          Helper function for ant build to retrieve the current version.
 java.lang.String normalizeURL(java.lang.String url)
          Just throws a UnsupportedOperationException exception.
 boolean parseBoolean(java.lang.String value, boolean def)
          This function try to parse value as a boolean.
 float parseFloat(java.lang.String value, float def)
          This function try to parse value as a float number.
 int parseInt(java.lang.String value, int def)
          This function try to parse value as an integer.
 long parseLong(java.lang.String value, long def)
          This function try to parse value as a Long.
 void readCookieFromNavigator(java.util.Vector<java.lang.String> headers)
          Just throws a UnsupportedOperationException exception.
 void readUserAgentFromNavigator(java.util.Vector<java.lang.String> headers)
          Just throws a UnsupportedOperationException exception.
 void registerUnload(java.lang.Object o, java.lang.String method)
          Register a callback to be executed during applet termination.
 void runUnload()
          Runs all callback that must be called when releasing the applet.
 java.awt.Cursor setCursor(java.awt.Cursor cursor)
          Just throws a UnsupportedOperationException exception.
 void setProperty(java.lang.String prop, java.lang.String value)
          This allow runtime modifications of properties, from javascript.
 java.awt.Cursor setWaitCursor()
          Sets the wait cursor on the current application (applet, executable...).
 void showStatus(java.lang.String status)
          Just throws a UnsupportedOperationException exception.
 java.lang.String startUpload()
          Public method that can be called by Javascript to start upload
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

svnPropertiesFilename

private static final java.lang.String svnPropertiesFilename
The final that contains the SVN properties. These properties are generated during compilation, by the build.xml ant file.

See Also:
Constant Field Values

svnProperties

private java.util.Properties svnProperties
The properties, created at build time, by the build.xml ant file. Or a dummy property set, with 'unknown' values.


jsHandler

private JavascriptHandler jsHandler
variable to hold reference to JavascriptHandler object


mimeTypesProperties

private java.util.Properties mimeTypesProperties
the mime type list, coming from: http://www.mimetype.org/ Thanks to them!


RELEASE_VERSION

private static final java.lang.String RELEASE_VERSION
The version of this applet. The version itself is to be updated in the JUploadApplet.java file. The revision is added at build time, by the build.xml ant file, packaged with the applet.

See Also:
Constant Field Values

uploadPolicy

protected UploadPolicy uploadPolicy
The current upload policy. This class is responsible for the call to the UploadPolicyFactory.


jUploadPanel

private JUploadPanel jUploadPanel
The JUploadPanel, which actually contains all the applet components.


logWindow

private JUploadTextArea logWindow
The log messages should go there ...


unloadCallbacks

private java.util.Vector<DefaultJUploadContext.Callback> unloadCallbacks
All registered callbacks.

See Also:
DefaultJUploadContext.Callback
Constructor Detail

DefaultJUploadContext

public DefaultJUploadContext()
Method Detail

init

public void init(javax.swing.RootPaneContainer rootPaneContainer)
Reaction on the start of the applet: creation of each specific item of the GUI, and the upload policy.
This method needs that the initialization of the called is finished. For instance, JUploadContextApplet needs to have set theApplet, to be able to properly execute some method calls that are in the init() method. So we can not do this initialization in the constructor of DefaultJUploadContext.

Parameters:
rootPaneContainer - The mother window (JApplet, JFrame...), which contains the rootPaneContainer. Used to set the JUploadPanel in it.

getVersion

public java.lang.String getVersion()

Specified by:
getVersion in interface JUploadContext
Returns:
The 'official' version (applet version and SVN revision)

getLastModified

public java.lang.String getLastModified()

Specified by:
getLastModified in interface JUploadContext
Returns:
Last modification date (date of last commit)

getBuildDate

public java.lang.String getBuildDate()

Specified by:
getBuildDate in interface JUploadContext
Returns:
Last modification date (date of last commit)

getBuildNumber

public int getBuildNumber()

Specified by:
getBuildNumber in interface JUploadContext
Returns:
Last modification date (date of last commit)

getLogWindow

public JUploadTextArea getLogWindow()
Retrieves the current log window of this applet. This log window may visible or not depending on various applet parameter.

Specified by:
getLogWindow in interface JUploadContext
Returns:
the current log window of this instance.
See Also:
JUploadPanel.showOrHideLogWindow()

getMimeType

public java.lang.String getMimeType(java.lang.String fileExtension)
Returns the mime type associated with the given file extension. As the applet may run on windows, the fileExtension is always changed to minor case, before looking for the corresponding mime type.

Specified by:
getMimeType in interface JUploadContext
Parameters:
fileExtension - The file extension, in any case.
Returns:
Returns the current mime type, for this extension.

getUploadPanel

public JUploadPanel getUploadPanel()
Retrieves the current upload panel.

Specified by:
getUploadPanel in interface JUploadContext
Returns:
the current upload panel of this instance.

getUploadPolicy

public UploadPolicy getUploadPolicy()
Retrieves the current upload policy. The JUploadContext is responsible for storing the UploadPolicy associated with the current instance.

Specified by:
getUploadPolicy in interface JUploadContext
Returns:
the current upload policy of this instance.

setProperty

public void setProperty(java.lang.String prop,
                        java.lang.String value)
This allow runtime modifications of properties, from javascript. Currently, this can only be used after full initialization. This method only calls the UploadPolicy.setProperty method.
Ex: document.jupload.setProperty(prop, value);

Specified by:
setProperty in interface JUploadContext
Parameters:
prop - The property name that must be set.
value - The value of this property.

startUpload

public java.lang.String startUpload()
Public method that can be called by Javascript to start upload

Specified by:
startUpload in interface JUploadContext
Returns:
Returns the upload result. See the constants defined in the JavascriptHandler javadoc.

displayErr

public void displayErr(java.lang.String err)
Call to UploadPolicy.displayErr(Exception)

Parameters:
err - The error text to be displayed.

displayInfo

public void displayInfo(java.lang.String info)
Call to UploadPolicy.displayInfo(String)

Parameters:
info - The info text to display

displayWarn

public void displayWarn(java.lang.String warn)
Call to UploadPolicy.displayWarn(String)

Parameters:
warn - The error text to be displayed.

displayDebug

public void displayDebug(java.lang.String debug,
                         int minDebugLevel)
Call to UploadPolicy.displayDebug(String, int)

Parameters:
debug - The debug message.
minDebugLevel - The minimum level that debug level should have, to display this message. Values can go from 0 to 100.

main

public static void main(java.lang.String[] args)
Helper function for ant build to retrieve the current version. This method is used by the build.xml ant build file, to get the release version, and put it into the svn.properties file.

Parameters:
args - Standard argument for main method. Not used.

getSvnProperties

public static java.util.Properties getSvnProperties()
Helper function, to get the Revision number, if available. The applet must be built from the build.xml ant file.

Returns:
The svn properties

registerUnload

public void registerUnload(java.lang.Object o,
                           java.lang.String method)
Register a callback to be executed during applet termination.

Specified by:
registerUnload in interface JUploadContext
Parameters:
o - The Object instance to be registered
method - The Method of that object to be registered. The method must be of type void and must not take any parameters and must be public.

runUnload

public void runUnload()
Runs all callback that must be called when releasing the applet.

Specified by:
runUnload in interface JUploadContext

displayDebugParameterValue

void displayDebugParameterValue(java.lang.String key,
                                java.lang.String value)
Displays the debug information for the current parameter.


parseInt

public int parseInt(java.lang.String value,
                    int def)
This function try to parse value as an integer. If value is not a correct integer, def is returned.

Specified by:
parseInt in interface JUploadContext
Parameters:
value - The string value, that must be parsed
def - The default value
Returns:
The integer value of value, or def if value is not valid.

parseFloat

public float parseFloat(java.lang.String value,
                        float def)
This function try to parse value as a float number. If value is not a correct float, def is returned.

Specified by:
parseFloat in interface JUploadContext
Parameters:
value - The string value, that must be parsed
def - The default value
Returns:
The float value of value, or def if value is not valid.

parseLong

public long parseLong(java.lang.String value,
                      long def)
This function try to parse value as a Long. If value is not a correct long, def is returned.

Specified by:
parseLong in interface JUploadContext
Parameters:
value - The string value, that must be parsed
def - The default value
Returns:
The integer value of value, or def if value is not valid.

parseBoolean

public boolean parseBoolean(java.lang.String value,
                            boolean def)
This function try to parse value as a boolean. If value is not a correct boolean, def is returned.

Specified by:
parseBoolean in interface JUploadContext
Parameters:
value - The new value for this property. If invalid, the default value is used.
def - The default value: used if value is invalid.
Returns:
The boolean value of value, or def if value is not a valid boolean.

setWaitCursor

public java.awt.Cursor setWaitCursor()
Description copied from interface: JUploadContext
Sets the wait cursor on the current application (applet, executable...).

Specified by:
setWaitCursor in interface JUploadContext
Returns:
The cursor that was active before the call to this method
See Also:
JUploadContext.setCursor(Cursor)

displayURL

public void displayURL(java.lang.String url,
                       boolean success)
Just throws a UnsupportedOperationException exception.

Specified by:
displayURL in interface JUploadContext
Parameters:
url -
success -

getApplet

public javax.swing.JApplet getApplet()
Just throws a UnsupportedOperationException exception.

Specified by:
getApplet in interface JUploadContext
Returns:
Not used

getCursor

public java.awt.Cursor getCursor()
Just throws a UnsupportedOperationException exception.

Specified by:
getCursor in interface JUploadContext
Returns:
Not used.
See Also:
UploadPolicy.setCursor(Cursor)

getParameter

public java.lang.String getParameter(java.lang.String key,
                                     java.lang.String def)
Just throws a UnsupportedOperationException exception.

Specified by:
getParameter in interface JUploadContext
Parameters:
key -
def -
Returns:
Not used

getParameter

public int getParameter(java.lang.String key,
                        int def)
Just throws a UnsupportedOperationException exception.

Specified by:
getParameter in interface JUploadContext
Parameters:
key -
def -
Returns:
Not used

getParameter

public float getParameter(java.lang.String key,
                          float def)
Just throws a UnsupportedOperationException exception.

Specified by:
getParameter in interface JUploadContext
Parameters:
key -
def -
Returns:
Not used

getParameter

public long getParameter(java.lang.String key,
                         long def)
Just throws a UnsupportedOperationException exception.

Specified by:
getParameter in interface JUploadContext
Parameters:
key -
def -
Returns:
Not used

getParameter

public boolean getParameter(java.lang.String key,
                            boolean def)
Just throws a UnsupportedOperationException exception.

Specified by:
getParameter in interface JUploadContext
Parameters:
key -
def -
Returns:
Not used

normalizeURL

public java.lang.String normalizeURL(java.lang.String url)
                              throws JUploadException
Just throws a UnsupportedOperationException exception.

Specified by:
normalizeURL in interface JUploadContext
Parameters:
url -
Returns:
Not used
Throws:
JUploadException

readCookieFromNavigator

public void readCookieFromNavigator(java.util.Vector<java.lang.String> headers)
Just throws a UnsupportedOperationException exception.

Specified by:
readCookieFromNavigator in interface JUploadContext
Parameters:
headers -

readUserAgentFromNavigator

public void readUserAgentFromNavigator(java.util.Vector<java.lang.String> headers)
Just throws a UnsupportedOperationException exception.

Specified by:
readUserAgentFromNavigator in interface JUploadContext
Parameters:
headers -

setCursor

public java.awt.Cursor setCursor(java.awt.Cursor cursor)
Just throws a UnsupportedOperationException exception.

Specified by:
setCursor in interface JUploadContext
Parameters:
cursor -
Returns:
Not used
See Also:
UploadPolicy.setCursor(Cursor)

showStatus

public void showStatus(java.lang.String status)
Just throws a UnsupportedOperationException exception.

Specified by:
showStatus in interface JUploadContext
Parameters:
status -