This package contains upload policies, which allow easy configuration of the applet behaviour. The abstract class DefaultUploadPolicy contains all default policy.
It allows to specify :
  • The way files should be managed.
  • The target URL.
  • The way files are uploaded :
  • File by file
  • All files at once
  • Any specific behaviour. For instance, the {@link PictureUploadPolicy} allows picture management. This contains:
  • The current implemented upload policies are :
  • {@link wjhk.jupload2.policies.DefaultUploadPolicy}. It's a 'simple' instanciation of each UploadPolicy methods. It makes JUpload work the same way as the original JUpload (v1).
  • (deprecated){@link wjhk.jupload2.policies.CustomizedNbFilesPerRequestUploadPolicy} is a DefaultUploadPolicy, which allows to control how many files are to be uploaded for each HTTP request.
  • {@link wjhk.jupload2.policies.FileByFileUploadPolicy} is CustomizedNbFilesPerRequestUploadPolicy, where the number of files to upload for each HTTP request is ... one! This policy behaves as the DefaultUploadPolicy, when nbFilesPerRequest parameter (see below) is 1.
  • {@link wjhk.jupload2.policies.PictureUploadPolicy} adds picture handling the the applet. The main functionnalities are :
  • Preview picture: The look of the applet changes, to allow display of the selected picture.
  • Rotation: you can rotate the picture by quarter of turn.
  • Resizing: the applet can resize picture before upload, to lower network (and time) transfert. Just specify a maximum width and/or height, in pixels.
  • {@link wjhk.jupload2.policies.CoppermineUploadPolicy} is a special PictureUploadPolicy: it allows upload to the coppermine picture gallery.


  • From the application, the {@link wjhk.jupload2.policies.UploadPolicyFactory} allows easy instanciation of the needed UploadPolicy.
    All constructors for class inherited from UploadPolicy should have a protected contructor: all class creations are controled by the UploadPolicyFactory, which is the only class that should be used to create upload policies. You can:
  • Create a new UploadPolicy, by using the getUploadPolicy methods.
  • Get the previously created UploadPolicy, by using the {@link wjhk.jupload2.policies.UploadPolicyFactory#getCurrentUploadPolicy()} method.


  • The {link #progress} component is to be updated while uploading.
    The {link #status} component is to be used to display informations.

    To allow the easiest possible change of upload, all default upload code is embbeded into the {@link wjhk.jupload2.policies.DefaultUploadPolicy} class.

    Parameters

    Here is the list of all parameters available in the current package. These are applet parameters that should be 'given' to the applet, with tags, as precised below in the example.
    Parameter name Default value /
    Implemented in
    Description
    uploadPolicy DefaultUploadPolicy

    see {@link wjhk.jupload2.policies.UploadPolicyFactory}
    This parameter contains the class name for the UploadPolicy that should be used. If it is not set, or if its value is unknown from {@link wjhk.jupload2.policies.UploadPolicyFactory#getUploadPolicy(Applet, JTextArea, String)}, the {@link wjhk.jupload2.policies.DefaultUploadPolicy} is used.
    postURL Mandatory

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    It contains the target URL toward which the files should be upload. This parameter is mandatory for existing class. It may become optional in new UploadPolicy, that would create this URL from other data. If the this URL may change during the applet execution time, you can create a new UploadPolicy class, and either :
  • Override the {@link UploadPolicy#getPostURL()} method, to make the postURL totaly dynamic.
  • Override the {@link UploadPolicy#setPostURL(String)} method, to modify the postURL on the fly, when it is changed.
  • Override the {@link UploadPolicy#setProperty(String, String)} method. The {@link wjhk.jupload2.policies.CoppermineUploadPolicy} changes the postURL when the albumID property changes.
  • Find another solution ...
  • debugLevel 0

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    With 0, you get the normal production output. The higher the number is, the more information is displayed in the status bar.
    Note: the whole debug messages is stored in the {@link wjhk.jupload2.policies.DefaultUploadPolicy#debugBufferString}. It can be used to display more information, if needed. See also the 'webmasterMail' parameter.
    lang Navigator language

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    Should be something like en, fr... Currently only french and english are known from the applet. If anyone want to add another language ... Please translate the wjhk.jupload2.lang.lang_en, and send it back to .
    urlToSendErrorTo Empty String

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    If this url is given, and an upload error occurs, the applet post the all the debug output to this address. It's up to this URL to handle this mail. It is possible to just store the file, or to log the error in a database, or to send a mail (like the mail.php script given with the coppermine pack).
    nbFilesPerRequest -1

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    This allows the control of the maximal number of files that are uploaded in one HTTP upload to the server.
    If set to -1, there is no maximum. This means that all files are uploaded in the same HTTP request.
    If set to 5, for instance, and there are 6 files to upload, there will be two HTTP upload request to the server : 5 files in the first one, and that last file in a second HTTP request.
    serverProtocol HTTP/1.1

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    This parameter allows the control of the protocol toward the server. Currently, only HTTP is supported, so valid values are HTTP/0.9 (not tested), HTTP/1.0 and HTTP/1.1.
    This parameter is really useful only in {@link wjhk.jupload2.policies.CoppermineUploadPolicy}, as the coppermine application also controls that the requests send within an HTTP session uses the same HTTP protocol (as a protection to limit the 'steal' of session cookies).
    stringUploadSuccess .* 200 OK$

    {@link wjhk.jupload2.policies.DefaultUploadPolicy}
    This string is a regular expression. The upload thread will try to match this regular epression to each lines returned from the server. If the match is successfull, the upload is considered to be a success. If not, a {@link wjhk.jupload2.exception.JUploadExceptionUploadFailed} is thrown.
    The default test expression testes that the web server returns no HTTP error: 200 is the return code for a successfull HTTP request. It actually means that postURL is a valid URL, and that the applet was able to send a request to this URL: there should be no problem with the network configuration, like proxy, password proxy...).
    But it doesn't mean that the uploaded files have correctly be managed by the server. For instance, the URL can be http://sourceforge.net, which, of course, would not take your files into account.
    So, as soon as you know a regular expression that test the return from the target application (and not just a techical HTTP response code), change the stringUploadSuccess to this value. For instance, the {@link wjhk.jupload2.policies.CoppermineUploadPolicy} changes this value to "^SUCCESS$", as the HTTP body content of the server's answer contain just this exact line. This 'success' means that the pictures have correctly be added to the album, that vignettes have been generated (this I suppose), etc...
    maxPicHeight -1

    {@link wjhk.jupload2.policies.PictureUploadPolicy}
    This parameters allows the PHP script to control the maximum width for pictures. If a picture is to be download, and its height is bigger, the picture will be resized. The proportion between width and height of the resized picture are the same as those of the original picture. If both maxPicHeight and maxPicWidth are given, it can happen that the resized picture has a height lesser than maxPicHeight, so that width is no more than maxPicWidth.
    Precisions:
    If this parameter value is negative, then no control is done on the picture height.
    If the original picture is smaller than the maximum size, the picture is not enlarged.
    If the picture is resized, its other characteristics are kept (number of colors, ColorModel...). The picture format is ketp, if targetPictureFormat is empty. If the picture format is a destructive (like jpeg), the maximum available quality is choosed.
    maxPicWidth -1

    {@link wjhk.jupload2.policies.PictureUploadPolicy}
    Same as maxPicHeight, but for the maximum width of the uploaded picture.
    targetPictureFormat Empty String

    (to be implemented in {@link wjhk.jupload2.policies.PictureUploadPolicy})
    This parameter can contain any picture writer known by the JVM. For instance: jpeg, png, gif. All standard formats should be available. More information can be found on the java.sun.com web site.
    albumId -1

    {@link wjhk.jupload2.policies.CoppermineUploadPolicy}
    This parameter is only used by CoppermineUploadPolicy. So it is to be used to upload into a coppermine picture gallery. This parameter contains the identifier of the album, where pictures should be used. See CoppermineUploadPolicy for an example.
    Before upload, CoppermineUploadPolicy.{@link wjhk.jupload2.policies.CoppermineUploadPolicy#isUploadReady()} checks that the albumId is correct, that is: >=1.
    storeBufferedImage false

    {@link wjhk.jupload2.policies.PictureUploadPolicy}
    This parameter indicates that the preview image on the applet is kept in memory. It works really nice under eclise. But, once in the navigator, the applet runs very quickly out of memory. So I add a lot of calls to {@link wjhk.jupload2.filedata.PictureFileData#freeMemory(String)}, but it doesn't change anything. Be careful to this parameter, and let it to the default value, unless you've well tested it under all your target client configurations.

    HTML call example

    You'll find below an example of how to put the applet into a PHP page:
    <APPLET NAME="JUpload" CODE="wjhk.jupload2.JUploadApplet" ARCHIVE="plugins/jupload/wjhk.jupload.jar" <!-- Applet display size, on the navigator page --> WIDTH="500" HEIGHT="700" <!-- The applet call some javascript function, so we must allow it : --> MAYSCRIPT > <!-- Only one parameter is mandatory. We don't precise the UploadPolicy, so DefaultUploadPolicy is used. The applet behaves like the original JUpload. (jupload v1) --> <PARAM NAME="postURL" VALUE="http://some.host.com/youruploadpage.php"> Java 1.4 or higher plugin required. </APPLET>