wjhk.jupload2.policies
Class PictureUploadPolicy

java.lang.Object
  extended by wjhk.jupload2.policies.DefaultUploadPolicy
      extended by wjhk.jupload2.policies.PictureUploadPolicy
All Implemented Interfaces:
ActionListener, ImageObserver, EventListener, UploadPolicy
Direct Known Subclasses:
CoppermineUploadPolicy

public class PictureUploadPolicy
extends DefaultUploadPolicy
implements ActionListener, ImageObserver

This class add handling of pictures to upload.

Functionalities:



See an example of HTML that calls this applet, just below.

Parameters

The description for all parameters of all polices has been grouped in the UploadPolicy parameters section.
The parameters implemented in this class are:

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 > <!-- First, mandatory parameters --> <PARAM NAME="postURL" VALUE="http://some.host.com/youruploadpage.php"> <PARAM NAME="uploadPolicy" VALUE="PictureUploadPolicy"> <!-- Then, optional parameters --> <PARAM NAME="lang" VALUE="fr"> <PARAM NAME="maxPicHeight" VALUE="768"> <PARAM NAME="maxPicWidth" VALUE="1024"> <PARAM NAME="debugLevel" VALUE="0"> Java 1.4 or higher plugin required. </APPLET>

Version:
$Revision: 884 $
Author:
etienne_sf

Field Summary
 
Fields inherited from class wjhk.jupload2.policies.DefaultUploadPolicy
cookie, debugFile, debugOk, debugOut, patternError, patternSuccess, patternWarning, userAgent
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Fields inherited from interface wjhk.jupload2.policies.UploadPolicy
DEFAULT_AFTER_UPLOAD_TARGET, DEFAULT_AFTER_UPLOAD_URL, DEFAULT_ALBUM_ID, DEFAULT_ALLOW_HTTP_PERSISTENT, DEFAULT_ALLOWED_FILE_EXTENSIONS, DEFAULT_BROWSING_DIRECTORY, DEFAULT_DATE_FORMAT, DEFAULT_DEBUG_LEVEL, DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT, DEFAULT_FILE_CHOOSER_ICON_SIZE, DEFAULT_FILE_CHOOSER_IMAGE_PREVIEW, DEFAULT_FILENAME_ENCODING, DEFAULT_FORMDATA, DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE, DEFAULT_FTP_TRANSFERT_BINARY, DEFAULT_FTP_TRANSFERT_PASSIVE, DEFAULT_HIGH_QUALITY_PREVIEW, DEFAULT_HTTP_UPLOAD_PARAMETER_NAME, DEFAULT_HTTP_UPLOAD_PARAMETER_TYPE, DEFAULT_KEEP_ORIG_EXTENSION, DEFAULT_LANG, DEFAULT_LOOK_AND_FEEL, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_HEIGHT, DEFAULT_MAX_WIDTH, DEFAULT_NB_FILES_PER_REQUEST, DEFAULT_PICTURE_COMPRESSION_QUALITY, DEFAULT_PICTURE_TRANSMIT_METADATA, DEFAULT_POST_URL, DEFAULT_READ_COOKIE_FROM_NAVIGATOR, DEFAULT_REAL_MAX_HEIGHT, DEFAULT_REAL_MAX_WIDTH, DEFAULT_SERVER_PROTOCOL, DEFAULT_SHOW_LOGWINDOW, DEFAULT_SHOW_STATUSBAR, DEFAULT_SPECIFIC_HEADERS, DEFAULT_SSL_VERIFY_CERT, DEFAULT_STORE_BUFFERED_IMAGE, DEFAULT_STRING_UPLOAD_ERROR, DEFAULT_STRING_UPLOAD_SUCCESS, DEFAULT_STRING_UPLOAD_WARNING, DEFAULT_TARGET_PICTURE_FORMAT, DEFAULT_UPLOAD_POLICY, DEFAULT_URL_TO_SEND_ERROR_TO, HTTPUPLOADPARAMETERTYPE_ARRAY, HTTPUPLOADPARAMETERTYPE_ITERATION, HTTPUPLOADPARAMETERTYPE_ONE_FILE, PROP_AFTER_UPLOAD_TARGET, PROP_AFTER_UPLOAD_URL, PROP_ALBUM_ID, PROP_ALLOW_HTTP_PERSISTENT, PROP_ALLOWED_FILE_EXTENSIONS, PROP_BROWSING_DIRECTORY, PROP_DEBUG_LEVEL, PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT, PROP_FILE_CHOOSER_ICON_SIZE, PROP_FILE_CHOOSER_IMAGE_PREVIEW, PROP_FILENAME_ENCODING, PROP_FORMDATA, PROP_FTP_CREATE_DIRECTORY_STRUCTURE, PROP_FTP_TRANSFERT_BINARY, PROP_FTP_TRANSFERT_PASSIVE, PROP_HIGH_QUALITY_PREVIEW, PROP_HTTP_UPLOAD_PARAMETER_NAME, PROP_HTTP_UPLOAD_PARAMETER_TYPE, PROP_KEEP_ORIG_EXTENSION, PROP_LANG, PROP_LOOK_AND_FEEL, PROP_MAX_CHUNK_SIZE, PROP_MAX_FILE_SIZE, PROP_MAX_HEIGHT, PROP_MAX_WIDTH, PROP_NB_FILES_PER_REQUEST, PROP_PICTURE_COMPRESSION_QUALITY, PROP_PICTURE_TRANSMIT_METADATA, PROP_POST_URL, PROP_READ_COOKIE_FROM_NAVIGATOR, PROP_REAL_MAX_HEIGHT, PROP_REAL_MAX_WIDTH, PROP_SERVER_PROTOCOL, PROP_SHOW_LOGWINDOW, PROP_SHOW_STATUSBAR, PROP_SPECIFIC_HEADERS, PROP_SSL_VERIFY_CERT, PROP_STORE_BUFFERED_IMAGE, PROP_STRING_UPLOAD_ERROR, PROP_STRING_UPLOAD_SUCCESS, PROP_STRING_UPLOAD_WARNING, PROP_TARGET_PICTURE_FORMAT, PROP_UPLOAD_POLICY, PROP_URL_TO_SEND_ERROR_TO, SHOWLOGWINDOW_FALSE, SHOWLOGWINDOW_ONERROR, SHOWLOGWINDOW_TRUE
 
Constructor Summary
PictureUploadPolicy(wjhk.jupload2.context.JUploadContext juploadContext)
          The standard constructor, which transmit most informations to the super.Constructor().
 
Method Summary
 void actionPerformed(ActionEvent e)
          This method handles the clicks on the rotation buttons.
 boolean beforeUpload()
          Execute any action, that must be done before upload.
 JUploadFileChooser createFileChooser()
          Creates the file chooser, from the default implementation, then add an accessory to preview pictures.
 FileData createFileData(File file, File root)
          This methods actually returns a PictureFileData instance.
 JPanel createTopPanel(JButton browse, JButton remove, JButton removeAll, JUploadPanel jUploadPanel)
          This method override the default topPanel, and adds:
Two rotation buttons, to rotate the currently selected picture.
 void displayParameterStatus()
          This method displays the applet parameter list, according to the current debugLevel.
 Icon fileViewGetIcon(File file)
          Returns an icon, calculated from the image content.
 boolean getFileChooserImagePreview()
          Getter for fileChooserImagePreview.
 boolean getHighQualityPreview()
           
 wjhk.jupload2.filedata.helper.ImageFileConversionInfo getImageFileConversionInfo()
           
 boolean getKeepOrigExtension()
           
 int getMaxHeight()
           
 int getMaxWidth()
           
 float getPictureCompressionQuality()
           
 boolean getPictureTransmitMetadata()
           
 int getRealMaxHeight()
           
 int getRealMaxWidth()
           
 String getTargetPictureFormat()
           
 String getUploadFilename(FileData fileData, int index)
          Get the original name of the file on the disk.
 boolean imageUpdate(Image arg0, int arg1, int arg2, int arg3, int arg4, int arg5)
          Implementation of the ImageObserver interface
 void onFileDoubleClicked(FileData pictureFileData)
          Open the 'big' preview dialog box.
 void onFileSelected(FileData fileData)
          Default implementation of the UploadPolicy.onFileSelected(wjhk.jupload2.filedata.FileData) .
 Cursor setCursor(Cursor cursor)
          Calls the DefaultUploadPolicy.setCursor(Cursor) method, then set the picture panel specific cursor.
 void setFileChooserImagePreview(boolean fileChooserImagePreview)
          Setter for fileChooserIconFromFileContent.
(package private)  void setHighQualityPreview(boolean highQualityPreview)
           
(package private)  void setKeepOrigExtension(boolean keepOrigExtension)
           
(package private)  void setMaxHeight(int maxHeight)
           
(package private)  void setMaxWidth(int maxWidth)
           
(package private)  void setPictureCompressionQuality(float pictureCompressionQuality)
           
(package private)  void setPictureTransmitMetadata(boolean pictureTransmitMetadata)
           
 void setProperty(String prop, String value)
          This method manages the applet parameters that are specific to this class.
(package private)  void setRealMaxHeight(int realMaxHeight)
           
(package private)  void setRealMaxWidth(int realMaxWidth)
           
(package private)  void setTargetPictureFormat(String targetPictureFormat)
          we expect e.g.
 Cursor setWaitCursor()
          Calls the DefaultUploadPolicy.setWaitCursor() method, then erases the picture panel specific cursor.
 
Methods inherited from class wjhk.jupload2.policies.DefaultUploadPolicy
addComponentsToJUploadPanel, addHeader, addMsgToDebugLog, afterFileDropped, afterUpload, alert, alertStr, checkUploadSuccess, createProgressPanel, createStatusBar, deleteLog, displayDebug, displayErr, displayErr, displayErr, displayInfo, displayWarn, fileFilterAccept, fileFilterGetDescription, getAfterUploadTarget, getAfterUploadURL, getAllowedFileExtensions, getAllowHttpPersistent, getContext, getCurrentBrowsingDirectory, getDateFormat, getDebugLevel, getEncodedFilename, getFileChooserIconFromFileContent, getFileChooserIconSize, getFilenameEncoding, getFormdata, getFtpCreateDirectoryStructure, getFtpTransfertBinary, getFtpTransfertPassive, getHttpUploadParameterName, getHttpUploadParameterType, getLastException, getLastResponseBody, getLastResponseMessage, getLookAndFeel, getMaxChunkSize, getMaxFileSize, getNbFilesPerRequest, getPostURL, getReadCookieFromNavigator, getServerProtocol, getShowLogWindow, getSpecificHeaders, getSslVerifyCert, getString, getStringUploadError, getStringUploadSuccess, getStringUploadWarning, getUploadName, getUrlToSendErrorTo, onAppendHeader, sendDebugInformation, setAfterUploadURL, setAllowedFileExtensions, setAllowHttpPersistent, setCurrentBrowsingDirectory, setCurrentBrowsingDirectory, setDebugLevel, setDebugLevel, setFileChooserIconFromFileContent, setFileChooserIconSize, setFilenameEncoding, setFtpCreateDirectoryStructure, setFtpTransfertBinary, setFtpTransfertPassive, setLang, setLastException, setLookAndFeel, setMaxChunkSize, setMaxFileSize, setNbFilesPerRequest, setPostURL, setServerProtocol, setShowLogWindow, setShowStatusbar, setSpecificHeaders, setSslVerifyCert, setStringUploadError, setStringUploadSuccess, setStringUploadWarning, setUrlToSendErrorTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PictureUploadPolicy

public PictureUploadPolicy(wjhk.jupload2.context.JUploadContext juploadContext)
                    throws JUploadException
The standard constructor, which transmit most informations to the super.Constructor().

Parameters:
juploadContext - Reference to the current applet. Allows access to javascript functions.
Throws:
JUploadException
Method Detail

createFileData

public FileData createFileData(File file,
                               File root)
                        throws JUploadExceptionStopAddingFiles
This methods actually returns a PictureFileData instance. It allows only pictures: if the file is not a picture, this method returns null, thus preventing the file to be added to the list of files to be uploaded.

Specified by:
createFileData in interface UploadPolicy
Overrides:
createFileData in class DefaultUploadPolicy
Parameters:
file - The file selected by the user (called once for each added file).
root - An optional toplevel directory of a hierarchy (can be null).
Returns:
An instance of PictureFileData or null if file is not a picture.
Throws:
JUploadExceptionStopAddingFiles - The exception is not really an error. It allows an easy way to indicates that the applet should stop adding files when the user clicked on the 'Cancel' button.
See Also:
UploadPolicy.createFileData(File,File)

createTopPanel

public JPanel createTopPanel(JButton browse,
                             JButton remove,
                             JButton removeAll,
                             JUploadPanel jUploadPanel)
This method override the default topPanel, and adds:

Specified by:
createTopPanel in interface UploadPolicy
Overrides:
createTopPanel in class DefaultUploadPolicy
Parameters:
browse - The default browse button.
remove - The default removeSelected button.
removeAll - The default removeAll button.
jUploadPanel - The panel that contains all objects.
Returns:
the topPanel, that will be displayed on the top of the Applet.
See Also:
UploadPolicy.createTopPanel(JButton, JButton, JButton, JUploadPanel)

actionPerformed

public void actionPerformed(ActionEvent e)
This method handles the clicks on the rotation buttons. All other actions are managed by the DefaultUploadPolicy.

Specified by:
actionPerformed in interface ActionListener
See Also:
ActionListener.actionPerformed(java.awt.event.ActionEvent)

onFileSelected

public void onFileSelected(FileData fileData)
Description copied from class: DefaultUploadPolicy
Default implementation of the UploadPolicy.onFileSelected(wjhk.jupload2.filedata.FileData) . Nothing's done.

Specified by:
onFileSelected in interface UploadPolicy
Overrides:
onFileSelected in class DefaultUploadPolicy
See Also:
UploadPolicy.onFileSelected(wjhk.jupload2.filedata.FileData)

onFileDoubleClicked

public void onFileDoubleClicked(FileData pictureFileData)
Open the 'big' preview dialog box. It allows the user to see a full screen preview of the choosen picture.
This method does nothing if the panel has no selected picture, that is when pictureFileData is null.

Specified by:
onFileDoubleClicked in interface UploadPolicy
Overrides:
onFileDoubleClicked in class DefaultUploadPolicy
See Also:
UploadPolicy.onFileDoubleClicked(FileData)

beforeUpload

public boolean beforeUpload()
Description copied from interface: UploadPolicy
Execute any action, that must be done before upload. For instance, PictureUploadPolicy disable the rotation buttons during buttons. The DefaultUploadPolicy.beforeUpload() method just returns true.

Specified by:
beforeUpload in interface UploadPolicy
Overrides:
beforeUpload in class DefaultUploadPolicy
Returns:
indicate if everything is ready for upload.
See Also:
UploadPolicy.beforeUpload()

getFileChooserImagePreview

public boolean getFileChooserImagePreview()
Getter for fileChooserImagePreview.

Returns:
Current value for the applet parameter: fileChooserImagePreview
See Also:
UploadPolicy.PROP_FILE_CHOOSER_IMAGE_PREVIEW

setFileChooserImagePreview

public void setFileChooserImagePreview(boolean fileChooserImagePreview)
Setter for fileChooserIconFromFileContent. Current allowed values are: -1, 0, 1. Default value is 0.

Parameters:
fileChooserImagePreview - new value to store, for the applet parameter: fileChooserImagePreview.
See Also:
UploadPolicy.PROP_FILE_CHOOSER_IMAGE_PREVIEW

getHighQualityPreview

public boolean getHighQualityPreview()
Returns:
the applet parameter highQualityPreview.

setHighQualityPreview

void setHighQualityPreview(boolean highQualityPreview)
Parameters:
highQualityPreview - the highQualityPreview to set

getMaxHeight

public int getMaxHeight()
Returns:
Returns the maxHeight, that should be used by pictures non transformed (rotated...) by the applet.

setMaxHeight

void setMaxHeight(int maxHeight)
Parameters:
maxHeight - the maxHeight to set

getMaxWidth

public int getMaxWidth()
Returns:
Returns the maxWidth, that should be used by pictures non transformed (rotated...) by the applet.

setMaxWidth

void setMaxWidth(int maxWidth)
Parameters:
maxWidth - the maxWidth to set

getPictureCompressionQuality

public float getPictureCompressionQuality()
Returns:
The current value for picture compression.

setPictureCompressionQuality

void setPictureCompressionQuality(float pictureCompressionQuality)
Parameters:
pictureCompressionQuality - The new value for picture compression.
See Also:
pictureCompressionQuality

getPictureTransmitMetadata

public boolean getPictureTransmitMetadata()
Returns:
The current value for transmission (or no transmission) of picture metadata.

setPictureTransmitMetadata

void setPictureTransmitMetadata(boolean pictureTransmitMetadata)
Parameters:
pictureTransmitMetadata - The new value for this attribute.
See Also:
pictureTransmitMetadata

getRealMaxHeight

public int getRealMaxHeight()
Returns:
Returns the maxHeight, that should be used by pictures that are transformed (rotated...) by the applet.

setRealMaxHeight

void setRealMaxHeight(int realMaxHeight)
Parameters:
realMaxHeight - the realMaxHeight to set

getRealMaxWidth

public int getRealMaxWidth()
Returns:
Returns the maxWidth, that should be used by pictures that are transformed (rotated...) by the applet.

setRealMaxWidth

void setRealMaxWidth(int realMaxWidth)
Parameters:
realMaxWidth - the realMaxWidth to set

getTargetPictureFormat

public String getTargetPictureFormat()
Returns:
Returns the targetPictureFormat.

getImageFileConversionInfo

public wjhk.jupload2.filedata.helper.ImageFileConversionInfo getImageFileConversionInfo()
Returns:
The current ImageFileConversionInfo

setTargetPictureFormat

void setTargetPictureFormat(String targetPictureFormat)
                      throws JUploadException
we expect e.g. "png,bmp:jpg;gif:png;"

Parameters:
targetPictureFormat - the targetPictureFormat to set
Throws:
JUploadException - if the conversionList is erroneous

getKeepOrigExtension

public boolean getKeepOrigExtension()
Returns:
  • true, if the the original file extension should be kept
  • false, if the the original file extension should be changed to the target picture format, that the file has been converted to

setKeepOrigExtension

void setKeepOrigExtension(boolean keepOrigExtension)
                    throws JUploadException
Parameters:
keepOrigExtension - if the original file extension should be kept ' true', or changed 'false' (if the image was converted)
Throws:
JUploadException

setProperty

public void setProperty(String prop,
                        String value)
                 throws JUploadException
This method manages the applet parameters that are specific to this class. The super.setProperty method is called for other properties.

Specified by:
setProperty in interface UploadPolicy
Overrides:
setProperty in class DefaultUploadPolicy
Parameters:
prop - The property which value should change
value - The new value for this property. If invalid, the default value is used.
Throws:
JUploadException
JUploadExceptionStopAddingFiles - indicates that the applet should stop strying adding the current file selection. Useful for instance, when a user drop a directory, full of unallowed file: it's annoying for the user to click 'Ok' for each file in the alert box.
See Also:
UploadPolicy.setProperty(java.lang.String, java.lang.String)

displayParameterStatus

public void displayParameterStatus()
Description copied from class: DefaultUploadPolicy
This method displays the applet parameter list, according to the current debugLevel. It is called by the DefaultUploadPolicy.setDebugLevel(int) method. It should be override by any subclasses, that should display its own parameters, then call super.displayParameterStatus().

Specified by:
displayParameterStatus in interface UploadPolicy
Overrides:
displayParameterStatus in class DefaultUploadPolicy
See Also:
DefaultUploadPolicy.displayParameterStatus()

setWaitCursor

public Cursor setWaitCursor()
Calls the DefaultUploadPolicy.setWaitCursor() method, then erases the picture panel specific cursor.

Specified by:
setWaitCursor in interface UploadPolicy
Overrides:
setWaitCursor in class DefaultUploadPolicy
Returns:
The cursor that was active before setting the new one. Can be used to restore its previous state.
See Also:
DefaultUploadPolicy.setCursor(Cursor)

setCursor

public Cursor setCursor(Cursor cursor)
Calls the DefaultUploadPolicy.setCursor(Cursor) method, then set the picture panel specific cursor.

Specified by:
setCursor in interface UploadPolicy
Overrides:
setCursor in class DefaultUploadPolicy
Parameters:
cursor - The cursor that must be set.
Returns:
The cursor that was active before setting the new one. Can be used to restore its previous state.
See Also:
DefaultUploadPolicy.setCursor(Cursor)

createFileChooser

public JUploadFileChooser createFileChooser()
Creates the file chooser, from the default implementation, then add an accessory to preview pictures.

Specified by:
createFileChooser in interface UploadPolicy
Overrides:
createFileChooser in class DefaultUploadPolicy
Returns:
Return the specific file choose, according to this upload policy.
See Also:
UploadPolicy.createFileChooser()

fileViewGetIcon

public Icon fileViewGetIcon(File file)
Returns an icon, calculated from the image content. Currently only pictures managed by ImageIO can be displayed. Once upon a day, extracting the first picture of a video may become reality... ;-)
Note: this method is called in a dedicated thread by the JUploadFileChooser, to avoid to calculate the icon for all pictures, when opening a new folder.

Specified by:
fileViewGetIcon in interface UploadPolicy
Overrides:
fileViewGetIcon in class DefaultUploadPolicy
Parameters:
file - The file from which the icon should represent.
Returns:
The calculated ImageIcon, or null if no picture can be extracted.
See Also:
UploadPolicy.fileViewGetIcon(File), UploadPolicy.PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT

getUploadFilename

public String getUploadFilename(FileData fileData,
                                int index)
                         throws JUploadException
Description copied from interface: UploadPolicy
Get the original name of the file on the disk. This function can encode the filename (see the filenameEncoding parameter). By default, the original filename is returned.

Specified by:
getUploadFilename in interface UploadPolicy
Overrides:
getUploadFilename in class DefaultUploadPolicy
Parameters:
fileData - The file data whose upload file name must be calculated.
index - index of the file in the current request to the server (from 0 to n)
Returns:
The filename the is given in the filename part of the Content-Disposition header.
Throws:
JUploadException
See Also:
DefaultUploadPolicy.getUploadFilename(wjhk.jupload2.filedata.FileData, int)

imageUpdate

public boolean imageUpdate(Image arg0,
                           int arg1,
                           int arg2,
                           int arg3,
                           int arg4,
                           int arg5)
Implementation of the ImageObserver interface

Specified by:
imageUpdate in interface ImageObserver
Parameters:
arg0 -
arg1 -
arg2 -
arg3 -
arg4 -
arg5 -
Returns:
true or false