⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultuploadpolicy.java

📁 [linux.rar] - 嵌入式linux开发教程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
//
// $Id: DefaultUploadPolicy.java 289 2007-06-19 10:04:46 +0000 (mar., 19 juin
// 2007) etienne_sf $
//
// jupload - A file upload applet.
// Copyright 2007 The JUpload Team
//
// Created: 2006-05-04
// Creator: etienne_sf
// Last modified: $Date: 2009-02-27 21:56:14 +0100 (ven., 27 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.BorderLayout;
import java.awt.Cursor;
import java.awt.GridLayout;
import java.awt.SystemColor;
import java.awt.dnd.DropTargetDropEvent;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.text.BadLocationException;

import netscape.javascript.JSException;
import netscape.javascript.JSObject;
import wjhk.jupload2.JUploadApplet;
import wjhk.jupload2.exception.JUploadException;
import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
import wjhk.jupload2.exception.JUploadExceptionUploadFailed;
import wjhk.jupload2.exception.JUploadIOException;
import wjhk.jupload2.filedata.DefaultFileData;
import wjhk.jupload2.filedata.FileData;
import wjhk.jupload2.gui.JUploadFileChooser;
import wjhk.jupload2.gui.JUploadFileFilter;
import wjhk.jupload2.gui.JUploadPanel;
import wjhk.jupload2.gui.JUploadTextArea;
import wjhk.jupload2.upload.helper.ByteArrayEncoder;
import wjhk.jupload2.upload.helper.ByteArrayEncoderHTTP;
import wjhk.jupload2.upload.helper.HTTPConnectionHelper;
import wjhk.jupload2.upload.helper.HttpConnect;
import wjhk.jupload2.upload.helper.InteractiveTrustManager;

/**
 * This class implements all {@link wjhk.jupload2.policies.UploadPolicy}
 * methods. Its way of working is he same as the JUpload version 1. <BR>
 * The simplest way to use this policy is given in the presentation of
 * {@link UploadPolicy}. The DefaultUploadPolicy is used when no
 * <I>uploadPolicy</I> parameter is given to the applet, or this parameter has
 * 'DefaultUploadPolicy' as a value. <BR>
 * <P>
 * The <U>default behavior</U> is representated below. It can be overrided by
 * adding parameters to the applet. All available parameters are shown in the
 * presentation of {@link UploadPolicy}.
 * </P>
 * <UL>
 * <LI>Default implementation for all
 * {@link wjhk.jupload2.policies.UploadPolicy} methods.
 * <LI>Files are uploaded all in one HTTP request.
 * <LI>No handling for particular kind of files: files are transmitted without
 * any transformation.
 * <LI>The file are transmitted to the server with the navigator cookies,
 * userAgent and Protocol. This make upload occurs within the current user
 * session on the server. So, it allows right management and context during the
 * management of uploaded files, on the server.
 * </UL>
 * 
 * @author etienne_sf
 * @version $Revision: 640 $
 */

public class DefaultUploadPolicy implements UploadPolicy {

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // /////////////////// APPLET PARAMETERS
    // ///////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * applet contains the reference of the Applet. It's useful to interact with
     * it. <BR>
     * It also allows access to the navigator properties, if the html tag
     * MAYSCRIPT is put in the APPLET tag. This allows this class to get the
     * cookie, userAgent and protocol, to upload files in the current user
     * session on the server. <BR>
     * Default : no default value
     */
    private JUploadApplet applet = null;

    /**
     * Contains the applet parameter of the same name. If a valid URL is given
     * here, the navigator will get redirected to this page, after a successful
     * upload.
     */
    private String afterUploadURL = UploadPolicy.DEFAULT_AFTER_UPLOAD_URL;

    /**
     * Contains the allowedFileExtensions applet parameter.
     */
    private boolean allowHttpPersistent = UploadPolicy.DEFAULT_ALLOW_HTTP_PERSISTENT;

    /**
     * Contains the allowedFileExtensions applet parameter.
     */
    private String allowedFileExtensions = UploadPolicy.DEFAULT_ALLOWED_FILE_EXTENSIONS;

    /**
     * Indicate whether the log window is shown or not to the user. In all cases
     * it remains in memory, and stores all debug information. This allows a log
     * information, in case of an error occurs.
     * 
     * @see #urlToSendErrorTo
     */
    private String showLogWindow = UploadPolicy.DEFAULT_SHOW_LOGWINDOW;

    private boolean showStatusbar = UploadPolicy.DEFAULT_SHOW_STATUSBAR;

    private String specificHeaders = null;

    /** Indicates the directory in which the file chooser is to be opened */
    private File currentBrowsingDirectory = null;

    /**
     * This parameter controls whether the applet generates a debug file or not.
     * If true, this file contains the full debug output, whatever the current
     * debugLevel is.
     */
    private boolean debugGenerateFile = false;

    /**
     * The current debug level. This control the details of information that is
     * written in the log part of the applet.
     */
    private int debugLevel = UploadPolicy.DEFAULT_DEBUG_LEVEL;

    /**
     * Stored value for the fileChooserIconFromFileContent applet property.
     * 
     * @see UploadPolicy#PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT
     */
    private int fileChooserIconFromFileContent = UploadPolicy.DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT;

    /**
     * Stored value for the fileChooserIconSize applet property.
     * 
     * @see UploadPolicy#PROP_FILE_CHOOSER_ICON_SIZE
     */
    private int fileChooserIconSize = UploadPolicy.DEFAULT_FILE_CHOOSER_ICON_SIZE;

    /**
     * This String contains the filenameEncoding parameter. All details about
     * the available applet parameters are displayed in the <a
     * href="UploadPolicy.html@parameters">Upload Policy javadoc page</a>.
     */
    private String filenameEncoding = UploadPolicy.DEFAULT_FILENAME_ENCODING;

    /** Default value for the ftpCreateDirectoryStructure applet parameter */
    private boolean ftpCreateDirectoryStructure = UploadPolicy.DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE;

    /** Default value for the ftpCreateDirectoryStructure applet parameter */
    private boolean ftpTransfertBinary = UploadPolicy.DEFAULT_FTP_TRANSFERT_BINARY;

    /** Default value for the ftpCreateDirectoryStructure applet parameter */
    private boolean ftpTransfertPassive = UploadPolicy.DEFAULT_FTP_TRANSFERT_PASSIVE;

    /**
     * The lang parameter, given to the applet.
     */
    private String lang = UploadPolicy.DEFAULT_LANG;

    /**
     * Contains the last exception that occurs in the applet.
     * 
     * @see #displayErr(String, Exception)
     */
    private JUploadException lastException = null;

    /**
     * The look and feel is used as a parameter of the
     * UIManager.setLookAndFeel(String) method. See the parameters list on the
     * {@link UploadPolicy} page.
     */
    private String lookAndFeel = UploadPolicy.DEFAULT_LOOK_AND_FEEL;

    /**
     * The applet will do as may HTTP requests to upload all files, with the
     * number as a maximum number of files for each HTTP request. <BR>
     * Default : -1
     */
    private int nbFilesPerRequest = UploadPolicy.DEFAULT_NB_FILES_PER_REQUEST;

    /**
     * Current value (or default value) of the maxChunkSize applet parameter. <BR>
     * Default : Long.MAX_VALUE
     */
    private long maxChunkSize = UploadPolicy.DEFAULT_MAX_CHUNK_SIZE;

    /**
     * Current value (or default value) of the maxFileSize applet parameter. <BR>
     * Default : Long.MAX_VALUE
     */
    private long maxFileSize = UploadPolicy.DEFAULT_MAX_FILE_SIZE;

    /**
     * The URL where files should be posted. <BR>
     * Default : no default value. (mandatory)
     */
    private String postURL = UploadPolicy.DEFAULT_POST_URL;

    /**
     * @see UploadPolicy#getServerProtocol()
     */
    private String serverProtocol = UploadPolicy.DEFAULT_SERVER_PROTOCOL;

    /**
     * @see UploadPolicy#getStringUploadError()
     */
    private String stringUploadError = UploadPolicy.DEFAULT_STRING_UPLOAD_ERROR;

    /**
     * @see UploadPolicy#getStringUploadSuccess()
     */
    private String stringUploadSuccess = UploadPolicy.DEFAULT_STRING_UPLOAD_SUCCESS;

    /**
     * @see UploadPolicy#getStringUploadWarning()
     */
    private String stringUploadWarning = UploadPolicy.DEFAULT_STRING_UPLOAD_WARNING;

    /**
     * If an error occurs during upload, and this attribute is not null, the
     * applet asks the user if wants to send the debug ouput to the
     * administrator. If yes, the full debug information is POSTed to this URL.
     * It's a little development on the server side to send a mail to the
     * webmaster, or just log this error into a log file.
     * 
     * @see UploadPolicy#sendDebugInformation(String, Exception)
     */
    private String urlToSendErrorTo = UploadPolicy.DEFAULT_URL_TO_SEND_ERROR_TO;

    /**
     * Optional name of a form (in the same document like the applet) which is
     * used to populate POST parameters.
     */
    private String formData = UploadPolicy.DEFAULT_FORMDATA;

    private String afterUploadTarget = UploadPolicy.DEFAULT_AFTER_UPLOAD_TARGET;

    private String lastResponseBody = null;

    private String lastResponseMessage = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -