📄 uploadpolicy.java
字号:
//
// $Id: UploadPolicy.java 287 2007-06-17 09:07:04 +0000 (dim., 17 juin 2007)
// felfert $
//
// jupload - A file upload applet.
// Copyright 2007 The JUpload Team
//
// Created: 2006-05-04
// Creator: etienne_sf
// Last modified: $Date: 2009-02-25 17:41:26 +0100 (mer., 25 févr. 2009) $
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version. This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details. You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation, Inc.,
// 675 Mass Ave, Cambridge, MA 02139, USA.
package wjhk.jupload2.policies;
import java.awt.Cursor;
import java.awt.dnd.DropTargetDropEvent;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import wjhk.jupload2.JUploadApplet;
import wjhk.jupload2.exception.JUploadException;
import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
import wjhk.jupload2.exception.JUploadIOException;
import wjhk.jupload2.filedata.FileData;
import wjhk.jupload2.gui.JUploadFileChooser;
import wjhk.jupload2.gui.JUploadFileFilter;
import wjhk.jupload2.gui.JUploadFileView;
import wjhk.jupload2.gui.JUploadPanel;
import wjhk.jupload2.gui.image.PictureDialog;
import wjhk.jupload2.upload.helper.ByteArrayEncoder;
/**
* This package contains upload policies, which allow easy configuration of the
* applet behaviour. <br>
* <br>
* The class {@link DefaultUploadPolicy} contains a default implementation for
* all UploadPolicy methods. <br>
* <br>
* <h4><a name="parameters">Parameters</a></h4>
* <!-- ATTENTION: The following comment is used by Ant build. DO NOT CHANGE!!
* --> <!-- ANT_COPYDOC_START -->
* <p>
* Here is the list of all parameters available in the current package, that is:
* available in available upload policies. These are applet parameters that can
* be 'given' to the applet, with <PARAM> tags, as explained below in the <a
* href="#example">example</a>.
* </p>
* <P>
* Let's start with some hints: <DIR>
* <LI><A href="debugLevel">debugLevel</A> and <A
* href="showLogWindow">showLogWindow</A>: I recommend putting debugLevel to 99
* and showLogWindow to onError.
* <LI><A href="maxFileSize">maxFileSize</A>: this prevents the user to upload
* too big files. The value depends on your needs.
* <LI><A href="#maxChunkSize">maxChunkSize</A>: allows you to override the
* server's maximum upload file size. The uploaded file will be split in pieces
* of maxChunkSize bytes. Then, it's up to you to concatenate the file pieces,
* into a server script. There are sample in this doc, and in the JUpload wiki.
* Please add your samples also...</DIR>
* </P>
* <table border="1">
* <tr>
* <th>Parameter name</th>
* <th>Default value / <br>
* Implemented in</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>afterUploadTarget<br>
* Since 2.9.2rc4</td>
* <td>_self<br>
* <br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>This parameter allows to select a specific target frame when redirecting
* to <code>afterUploadURL</code>. The following values are possible:<br>
* <ul>
* <li><code>_self</code> - Show in the window and frame that contain the
* applet. </li>
* <li><code>_parent</code> - Show in the applet's parent frame. If the
* applet's frame has no parent frame, acts the same as <i>_self</i>.</li>
* <li><code>_top</code> - Show in the top-level frame of the applet's
* window. If the applet's frame is the top-level frame, acts the same as
* <i>_self</i>.</li>
* <li><code>_blank</code> - Show in a new, unnamed top-level window.
* <li><i>name</i> - Show in the frame or window named <i>name</i>. If a
* target named <i>name</i> does not already exist, a new top-level window with
* the specified name is created, and the document is shown there.</li>
* </ul>
* See also:
* {@link java.applet.AppletContext#showDocument(java.net.URL, java.lang.String)}
* </td>
* </tr>
* <tr>
* <td>afterUploadURL</td>
* <td><i>null</i><br>
* since 2.9.0<br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>This parameter is used by all policies. It allows the applet to change
* the current page to another one after a successful upload. <br>
* This allows, for instance, to display a page containing the file description
* of the newly uploaded page. Since version 3.0.2b2, you can specify a
* JavaScript expression instead of a plain URL. So afterUploadURL can now
* contain:<br>
* <UL>
* <LI><B>A javascript expression</B>: The URL must start by <I>javascript:</I>.
* See below for details.</LI>
* <LI><B>A http URL</B>: the navigator will open this URL, in the current
* page or another, according to the <I>afterUploadTarget</I> parameter. Any
* URL that doesn't start by <I>javascript:</I> is handled as an http URL.</LI>
* </UL>
* If the value of afterUploadURL starts with the string "javascript:", the
* remainder of the string is evaluated as JavaScript expression in the current
* document context. For example: If afterUloadURL is<br>
* <code>"javascript:alert('Thanks for the upload');"</code>,</br> then
* after a successful upload, a messagebox would pop up. Since 3.0.2b3 there are
* now three place holders available which can be used as parameters in function
* calls:
* <ul>
* <li><code>%success%</code> is replaced by <b>true</b> or <b>false</b>
* depending on upload success.
* <li><code>%msg%</code> is replaced by an unquoted string, containing the
* error message received from the server (if any). Inside that string, all
* occurances of the single-quote character (hex 27) are quoted by backslashes.
* <li><code>%body%</code> is replaced by an unquoted string, containing the
* complete response body. Inside that string, all occurances of the
* single-quote character (hex 27) are quoted by backslashes.
* </ul>
* So if you set afterUloadURL to <code>"javascript:alert('%body%');"</code>,
* then the resulting message box will show the body content of the last server
* response.</td>
* </tr>
* <tr>
* <td>albumId</td>
* <td>-1 <br>
* <br>
* {@link wjhk.jupload2.policies.CoppermineUploadPolicy}</td>
* <td>This parameter is only used by CoppermineUploadPolicy. So it is to be
* used to upload into a <a href="http://coppermine.sourceforge.net/">coppermine
* picture gallery</a>. This parameter contains the identifier of the album,
* where pictures should be used. See CoppermineUploadPolicy for an example.
* <br>
* Before upload, CoppermineUploadPolicy.{@link wjhk.jupload2.policies.CoppermineUploadPolicy#isUploadReady()}
* checks that the albumId is correct, that is: >=1. </td>
* </tr>
* <tr>
* <td>allowedFileExtensions</td>
* <td><i>empty string</i><br>
* since 2.9.0<br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>This parameter allows the caller to specify a list of file extension. If
* this parameter is specified, only file with this extension can be selected in
* the applet.<br>
* This parameter must contains a list of extensions, in lower case, separated
* by slashes. eg: jpg/jpeg/gif </td>
* </tr>
* <tr>
* <td>allowHttpPersistent</td>
* <td><i>false</i><br>
* since 3.0.0rc1<br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>This parameter allows to switch off persistent HTTP connections which
* are enabled by default (and the protocol version allows it). Currently, we
* encountered problems with persistent connections when testing on a windows
* box using a loopback interface only.
* <BR>Note: default value changed to false in 4.0 version.</td>
* </tr>
* <tr>
* <td>browsingDirectory</td>
* <td><i>null</i><br>
* since 4.0.0b2<br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>This parameter allows to control the starting browsing directory, that
* is, the directory the is the current one when the file chooser is open.<BR>
* <U>Note:</U> if the directory doesn't exist, or can not be read, a warning
* is written on the local log window (visible only in debug mode), and this
* parameter is ignored.</td>
* </tr>
* <tr>
* <td>debugLevel</td>
* <td>0 <br>
* <br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}</td>
* <td>With 0, you get the normal production output. The higher the number is,
* the more information is displayed in the log window. Here are some hints
* about debug level values (please note that this is indicative ... including
* for me, as I'me writing this during 3.3.2 release: <DIR>
* <LI>0: No debug output. Only INFO and ERROR
* <LI>10: Structural debug output (entering method, exception info...)
* <LI>30: Details about method parameters
* <LI>50: Details about internal method variables.
* <LI>70: Details about encoding toward the server
* <LI>80: Details about server's response
* <LI>90: Details about query and server response when sending debug output to
* urlToSendErrorTo
* <LI>100: Maximum output information level. The redirection toward
* afterUploadURL is blocked
* <LI>>100: Additional things for internal debug, like some wait in the code
* to check what messages the applet displays, while uploading small files on
* localhost.</DIR> <br>
* Note: All debug messages are stored in a temporary log file. This can be used
* to display more information, if needed. See also the <I>urlToSendErrorTo</I>
* applet parameter. </td>
* </tr>
* <tr>
* <td>fileChooserIconFromFileContent</td>
* <td><i>0</i><br>
* since 3.1.0b<br>
* {@link wjhk.jupload2.policies.UploadPolicy}</td>
* <td>This parameter allows to control whether the file icons in the file
* chooser are calculated from the file content. This is currently only
* available for pictures.<BR>
* If activated, the file chooser will open each pictures, and calculate the
* icon by resizing the picture. This is done in by using thread of minimam
* priority, to minimize performances impact on the navigator. Available values
* are: <DIR>
* <LI>-1: disabled. The default system are used.
* <LI>0 (default): available only in picture mode. That is: the current upload
* policy is an instance of or a class inheriting from
* {@link PictureUploadPolicy}
* <LI>1: available for all upload policies. </DIR></td>
* </tr>
* <tr>
* <td>fileChooserIconSize</td>
* <td><i>20</i><br>
* since 3.1.0b<br>
* {@link wjhk.jupload2.policies.UploadPolicy}</td>
* <td>This parameter allows to control the size of icons, in pixels, in the
* file chooser. Used only when fileChooserIconFromFileContent is activated.<BR>
* Note: The standard icon size is a value of 20. With 50, you'll get a better
* view of the picture. </td>
* </tr>
* <tr>
* <td>fileChooserImagePreview</td>
* <td><i>true</i><br>
* since 3.1.0b<br>
* {@link wjhk.jupload2.policies.PictureUploadPolicy}</td>
* <td>This parameter allows to control whether an preview is available for
* picture in the file chooser. If activated, the file chooser will open the
* preview in a separate thread, of high priority. This avoid blocking the
* applet while calculating the preview picture, when the user just
* double-clicked a picture file. This parameter is ignored for
* DefaultUploadPolicy. </tr>
* <tr>
* <td><s>filenameEncoding</s></td>
* <td><S><i>null</i></S><br>
* <br>
* <S>{@link wjhk.jupload2.policies.DefaultUploadPolicy}</S></td>
* <td> Since 3.3.0, this parameter is no more used. The full applet upload HTTP
* request to the server is now correctly encoded.<BR>
* <S>With null, the filename in the <i>Content-Disposition</i> header is not
* encoded. If not null, the applet tries to encode this filename with the given
* encoding. It's up to the receiver (the web site) to decode this encoding (see
* {@link #getUploadFilename(FileData, int)}. <br>
* Example: if the "UTF8" encoding is choosen, the PHP function urldecode can be
* used to decode the filename. </S></td>
* </tr>
* <tr>
* <tr>
* <td>formdata</td>
* <td><i>null</i><br>
* <br>
* {@link wjhk.jupload2.policies.DefaultUploadPolicy}<br>
* <i>Since 2.9.2rc4</i></td>
* <td>With this parameter, the name of a HTML form can be specified. If the
* specified form exists in the same document like the applet, all all
* form-variables are added as POST parameters to the applet's POST request.</td>
* </tr>
* <tr>
* <td>ftpCreateDirectoryStructure</td>
* <td><i>false</i><br>
* since 4.1.0<br>
* {@link wjhk.jupload2.policies.UploadPolicy}</td>
* <td>This parameter allows to control whether the directory structure on the
* client side must be created on the server side.<BR>
* Example: if the user upload the test/ directory, which contains the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -