Package wjhk.jupload2.policies

This package contains the upload policies: they give you hook entry points, to override the default applet behaviour with a minimum of java code.


Interface Summary
UploadPolicy This package contains upload policies, which allow easy configuration of the applet behavior.

Class Summary
CoppermineUploadPolicy Specific UploadPolicy for the coppermine picture gallery.
CustomizedNbFilesPerRequestUploadPolicy Deprecated. This class is of no use, as it actually behaves exactly as the DefaultUploadPolicy.
DefaultUploadPolicy This class implements all UploadPolicy methods.
FileByFileUploadPolicy Deprecated. You can use the applet, without the uploadPolicy applet parameter, and put the nbFilesPerRequest to 1.
FilesTogetherUploadPolicy Upload policy that is a simple box.
PictureUploadPolicy This class add handling of pictures to upload.
UploadPolicyFactory This class is used to control creation of the uploadPolicy instance, according to applet parameters (or System properties).

Package wjhk.jupload2.policies Description

This package contains the upload policies: they give you hook entry points, to override the default applet behaviour with a minimum of java code.

This pages describes how to create a new upload policy, to adapt the applet to your needs, without interfering with the core applet, that is: with having compatibility with future JUpload versions. Here are other links on this subject:
  • See UploadPolicy for the list of applet parameters
  • howto customize for a presentation of the main ways to adapt the applet to your needs.
  • Creating a new upload policy: introduction

    Creating a new upload policy, allows you to change the applet behaviour, and still use the core applet function. This insures you that your development will remain compatible with next applet versions.

    You'll find on this page a description of the UploadPolicy methods, grouped by categories.

    Note: Creating a new upload policy is mandatory, if you want to manage some other kind of FileData. You can then add some kind of 'before upload check', or have a specific applet behaviour, for instance be able to hear sound file before upload.


    To create a new upload policy, you need to create a new java class: the easiest way is to inherit from @link wjhk.jupload2.policies.DefaultUploadPolicy}. You can then override methods of the UploadPolicy interface that you need to update for your needs.

    This kind of customization will be compatible within next JUpload applet release. If you need other hooks (method within the UploadPolicy interface, to allow other customizations), please let me know by posting a message on the sourceforge jupload forums (open discussions for instance), or post a new Feature Request in the jupload sourceforge project page. For instance, some attributes and methods from DefaultUploadPolicy are protected (not private), so that you can use them in your own upload policies.

    Here is a sample description of the customization that you can do by using the creating a new policy, using the UploadPolicy interface. All methods are described in the next section of this page.

    Note: UploadPolicyFactory

    The JuploadApplet asks the UploadPolicyFactory to create (instanciate) the needed UploadPolicy. That is:

  • During initialization of the applet, the UploadPolicyFactory.getUploadPolicy() method is called. This method checks the uploadPolicy parameter. If this uploadPolicy is unknown or not set, the DefaultUploadPolicy is used. If a specific uploadPolicy is found, it can of course read specific parameters from the APPLET tag.
  • Then, UploadPolicyFactory.getUploadPolicy() creates the class implementing the UploadPolicy factory, and returns the reference to this class.
  • The upload policy can not be changed while the applet is running.
  • Creation of a new UploadPolicy: detailed steps

    To create a new UploadPolicy, you'll need to:

    Methods to control file management

    FileData createFileData(File file, File root) throws JUploadExceptionStopAddingFiles

    This methods creates a new FileData object. It returns null is no file data was created, for instance if this file didn't check some specific validation checks.
    Note: use this method to use any FileData specific to your needs. See PictureUploadPolicy for a sample of this.

    void afterFileDropped(DropTargetDropEvent dropEvent)

    Specific reaction of the applet, when file are dropped onto it.

    Methods to control the applet GUI (display, behaviour)

    This methods are used to control what the JUploadFileChooser has to do.

    JPanel createTopPanel(JButton browse, JButton remove, JButton removeAll, JUploadPanel mainPanel)

    Allows the applet to change the way the top part of the applet is displayed, that is: the place where the Choose, remove, remove all buttons are. If you override this method, you must use the given button if you want these functionalities to work. If you don't put the browse button, for instance, the user won't be able to display a file chooser, unless you manage it yourself. See PictureUploadPolicy, for a way to use the standard buttons, and add specific ones.

    void addComponentsToJUploadPanel(JUploadPanel jUploadPanel)

    Extension of the createTopPanel() idea. You can place any component of JUpload at any place ... or at no place. If you override this method, you'll have to call the JUploadPanel getter to get core applet objects. These are:

  • Standard buttons: browseButton, removeButton, removeAllButton, stopButton, uploadButton.
  • Drag'n drop listener: dndListener, to manage files dropped on the applet
  • The log output: jLogWindowPane
  • The progress bar, which indicated the upload progress (from 0 to 100%): progressBar.
  • The status label, where upload speed is indicated:
  • The file panel, that contains the list of files to upload: filePanel.
  • JPanel createProgressPanel(JProgressBar progressBar, JButton uploadButton, JButton stopButton, JPanel mainPanel)

    You probably won't have to override this method. Note that this method allows you to not display the stop and upload buttons.

    JPanel createStatusBar(JLabel statusContent, JPanel mainPanel)

    This method should not be used any more. Use the showStatusBar applet parameter instead.

    void onFileSelected(FileData fileData)

    Reaction of the applet, when a file is selected in the file list. For instance, PictureUploadPolicy displays the selected picture in the preview component.

    void onFileDoubleClicked(FileData fileData)

    Reaction of the applet, when a file is double clicked. For instance, PictureUploadPolicy opens a dialog box, that contain a full screen display of the current picture.

    Methods to control the file chooser

    This methods are used to control what the JUploadFileChooser has to do.

    JUploadFileChooser createFileChooser()

    Allows the applet to change user another JFileChooser. Your specific file chooser should inherit from JUploadFileChooser

    boolean fileFilterAccept(File file)

    Called by the JUploadFileFilter. This method contains the actual response to the {