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

📄 defaultuploadpolicy.java

📁 [linux.rar] - 嵌入式linux开发教程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    private int sslVerifyCert = InteractiveTrustManager.NONE;

    private final String CRLF = System.getProperty("line.separator");

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // /////////////////// INTERNAL ATTRIBUTE
    // ///////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * This Vector contains headers that will be added for each upload. It may
     * contains specific cookies, for instance.
     * 
     * @see #onAppendHeader(ByteArrayEncoder)
     */
    private Vector<String> headers = new Vector<String>();

    /**
     * The text area, where message are to be displayed.
     * 
     * @see #displayMsg(String, String)
     */
    private JUploadTextArea logWindow = null;

    /**
     * The resourceBundle contains all localized String (and others ??)
     */
    private ResourceBundle resourceBundle = null;

    /**
     * This stream is used to store all information that could be useful, in
     * case a problem occurs. Is content can then be sent to the webmaster.
     */
    protected PrintStream debugOut = null;

    /**
     * The actual file, used for the debug log.
     * 
     * @see #debugGenerateFile
     */
    protected File debugFile = null;

    /**
     * This flag prevents endless repeats of opening the debug log, if that
     * failed for some reason.
     */
    protected boolean debugOk = true;

    /** cookie is the value of the javascript <I>document.cookie</I> property. */
    protected String cookie = null;

    /**
     * userAgent is the value of the javascript <I>navigator.userAgent</I>
     * property. Protected as there is no setter for it, and no other way to
     * update it.
     */
    protected String userAgent = null;

    /**
     * This constant defines the upper limit of lines, kept in the log window.
     */
    private final static int MAX_DEBUG_LINES = 10000;

    /**
     * Same as {@link #patternSuccess}, but for the error message. If found,
     * then the upload was accepted by the remote HTTP server, but rejected by
     * the remote application. This pattern should also find the error message
     * in the first matching string.
     */
    protected Pattern patternError = Pattern
            .compile(UploadPolicy.DEFAULT_STRING_UPLOAD_ERROR);

    /**
     * The regexp pattern that is used to find the success string in the HTTP
     * response. If found, the upload is considered to be a success: it has been
     * accepted by the remote server and the remote application.
     */
    protected Pattern patternSuccess = Pattern
            .compile(UploadPolicy.DEFAULT_STRING_UPLOAD_SUCCESS);

    /**
     * Same as {@link #patternSuccess}, but for the warning message. Each time
     * it is found, a message is displayed to the user.
     */
    protected Pattern patternWarning = Pattern
            .compile(UploadPolicy.DEFAULT_STRING_UPLOAD_WARNING);

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // /////////////////// CONSTRUCTORS
    // //////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * The main constructor : use default values, and the given postURL.
     * 
     * @param theApplet The current applet. As the reference to the current
     *            upload policy exists almost everywhere, this parameter allows
     *            any access to anyone on the applet... including reading the
     *            applet parameters.
     * @throws JUploadException If an applet parameter is invalid
     */
    public DefaultUploadPolicy(JUploadApplet theApplet) throws JUploadException {
        // Call default constructor for all default initialization;.
        this.applet = theApplet;
        this.logWindow = theApplet.getLogWindow();

        // get the debug level. This control the level of debug messages that
        // are written in the log window (see displayDebugMessage). In all
        // cases, the full output is written in the debugBufferString (see also
        // urlToSendErrorTo)
        setDebugLevel(UploadPolicyFactory.getParameter(theApplet,
                PROP_DEBUG_LEVEL, DEFAULT_DEBUG_LEVEL, this), false);

        // Get resource file. This must be the very first parameter to be set,
        // because during initialization, translations may be needed.
        setLang(UploadPolicyFactory.getParameter(theApplet, PROP_LANG,
                DEFAULT_LANG, this));

        // Force the look and feel of the current system. This must be the
        // second
        // first parameter to be set, because during initialization, dialogs can
        // appear.
        setLookAndFeel(UploadPolicyFactory.getParameter(theApplet,
                PROP_LOOK_AND_FEEL, DEFAULT_LOOK_AND_FEEL, this));

        // This must be set before any URL's because these might trigger an
        // connection attempt.
        setSslVerifyCert(UploadPolicyFactory.getParameter(theApplet,
                PROP_SSL_VERIFY_CERT, DEFAULT_SSL_VERIFY_CERT, this));

        // get the afterUploadURL applet parameter.
        setAfterUploadURL(UploadPolicyFactory.getParameter(theApplet,
                PROP_AFTER_UPLOAD_URL, DEFAULT_AFTER_UPLOAD_URL, this));

        // Whether or not to create subfolders on the server side.
        setFtpCreateDirectoryStructure(UploadPolicyFactory.getParameter(
                theApplet, PROP_FTP_CREATE_DIRECTORY_STRUCTURE,
                DEFAULT_FTP_CREATE_DIRECTORY_STRUCTURE, this));
        // Whether or not to create subfolders on the server side.
        setFtpTransfertBinary(UploadPolicyFactory.getParameter(theApplet,
                PROP_FTP_TRANSFERT_BINARY, DEFAULT_FTP_TRANSFERT_BINARY, this));
        // Whether or not to create subfolders on the server side.
        setFtpTransfertPassive(UploadPolicyFactory
                .getParameter(theApplet, PROP_FTP_TRANSFERT_PASSIVE,
                        DEFAULT_FTP_TRANSFERT_PASSIVE, this));

        // get the allowedFileExtensions applet parameter
        setAllowedFileExtensions(UploadPolicyFactory.getParameter(theApplet,
                PROP_ALLOWED_FILE_EXTENSIONS, DEFAULT_ALLOWED_FILE_EXTENSIONS,
                this));

        setAllowHttpPersistent(UploadPolicyFactory
                .getParameter(theApplet, PROP_ALLOW_HTTP_PERSISTENT,
                        DEFAULT_ALLOW_HTTP_PERSISTENT, this));

        setShowStatusbar(UploadPolicyFactory.getParameter(theApplet,
                PROP_SHOW_STATUSBAR, DEFAULT_SHOW_STATUSBAR, this));

        setShowLogWindow(UploadPolicyFactory.getParameter(theApplet,
                PROP_SHOW_LOGWINDOW, DEFAULT_SHOW_LOGWINDOW, this));

        // set the fileChooser relative stuff.
        setFileChooserIconFromFileContent(UploadPolicyFactory.getParameter(
                theApplet, PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT,
                DEFAULT_FILE_CHOOSER_ICON_FROM_FILE_CONTENT, this));
        setFileChooserIconSize(UploadPolicyFactory.getParameter(theApplet,
                PROP_FILE_CHOOSER_ICON_SIZE, DEFAULT_FILE_CHOOSER_ICON_SIZE,
                this));
        setCurrentBrowsingDirectory(UploadPolicyFactory.getParameter(theApplet,
                PROP_BROWSING_DIRECTORY, DEFAULT_BROWSING_DIRECTORY, this));
        // get the filenameEncoding. If not null, it should be a valid argument
        // for the URLEncoder.encode method.
        // DEPRECATED.
        setFilenameEncoding(UploadPolicyFactory.getParameter(theApplet,
                PROP_FILENAME_ENCODING, DEFAULT_FILENAME_ENCODING, this));

        // get the maximum number of files to upload in one HTTP request.
        setNbFilesPerRequest(UploadPolicyFactory.getParameter(theApplet,
                PROP_NB_FILES_PER_REQUEST, DEFAULT_NB_FILES_PER_REQUEST, this));

        // get the maximum size of a file on one HTTP request (indicates if the
        // file must be splitted before upload, see UploadPolicy comment).
        setMaxChunkSize(UploadPolicyFactory.getParameter(theApplet,
                PROP_MAX_CHUNK_SIZE, DEFAULT_MAX_CHUNK_SIZE, this));

        // get the maximum size of an uploaded file.
        setMaxFileSize(UploadPolicyFactory.getParameter(theApplet,
                PROP_MAX_FILE_SIZE, DEFAULT_MAX_FILE_SIZE, this));

        // get the URL where files must be posted.
        setPostURL(UploadPolicyFactory.getParameter(theApplet, PROP_POST_URL,
                DEFAULT_POST_URL, this));

        // get any additional headers.
        setSpecificHeaders(UploadPolicyFactory.getParameter(theApplet,
                PROP_SPECIFIC_HEADERS, DEFAULT_SPECIFIC_HEADERS, this));
        setStringUploadError(UploadPolicyFactory.getParameter(theApplet,
                PROP_STRING_UPLOAD_ERROR, DEFAULT_STRING_UPLOAD_ERROR, this));
        setStringUploadSuccess(UploadPolicyFactory
                .getParameter(theApplet, PROP_STRING_UPLOAD_SUCCESS,
                        DEFAULT_STRING_UPLOAD_SUCCESS, this));
        setStringUploadWarning(UploadPolicyFactory
                .getParameter(theApplet, PROP_STRING_UPLOAD_WARNING,
                        DEFAULT_STRING_UPLOAD_WARNING, this));

        // get the URL where the full debug output can be sent when an error
        // occurs.
        setUrlToSendErrorTo(UploadPolicyFactory.getParameter(theApplet,
                PROP_URL_TO_SEND_ERROR_TO, DEFAULT_URL_TO_SEND_ERROR_TO, this));
        this.formData = UploadPolicyFactory.getParameter(theApplet,
                PROP_FORMDATA, DEFAULT_FORMDATA, this);
        this.afterUploadTarget = UploadPolicyFactory.getParameter(theApplet,
                PROP_AFTER_UPLOAD_TARGET, DEFAULT_AFTER_UPLOAD_TARGET, this);

        // /////////////////////////////////////////////////////////////////////////////
        // Load session data read from the navigator:
        // - cookies.
        // - User-Agent : useful, as the server will then see a post request
        // coming from the same navigator.
        //
        try {
            // Patch given by Stani: corrects the use of the applet on Firefox
            // on Mac.
            this.cookie = (String) JSObject.getWindow(getApplet()).eval(
                    "document.cookie");
            this.userAgent = (String) JSObject.getWindow(getApplet()).eval(
                    "navigator.userAgent");

            displayDebug("cookie: " + this.cookie, 30);
            displayDebug("userAgent: " + this.userAgent, 30);
        } catch (JSException e) {
            displayWarn("JSException (" + e.getClass() + ": " + e.getMessage()
                    + ") in DefaultUploadPolicy, trying default values.");

            // If we can't have access to the JS objects, we're in development :
            // Let's put some 'hard value', to test the applet from the
            // development tool (mine is eclipse).

            // felfert: I need different values so let's make that
            // configurable...
            this.cookie = System.getProperty("debug_cookie");
            this.userAgent = System.getProperty("debug_agent");

            displayDebug(
                    "  no navigator found, reading 'debug_cookie' from system properties ("
                            + this.cookie + ")", 30);
            displayDebug(
                    "  no navigator found, reading 'debug_agent' from system properties ("
                            + this.userAgent + ")", 30);
            /*
             * Exemple of parameter when calling the JVM:
             * -Ddebug_cookie="Cookie:cpg146_data=
             * YTo0OntzOjI6IklEIjtzOjMyOiJhZGU3MWIxZmU4OTZjNThhZjQ5N2FiY2ZiNmFlZTUzOCI7czoyOiJhbSI7aToxO3M6NDoibGFuZyI7czo2OiJmcmVuY2giO3M6MzoibGl2IjthOjI6e2k6MDtOO2k6MTtzOjQ6IjE0ODgiO319
             * ;cpg143_data=
             * YTozOntzOjI6IklEIjtzOjMyOiI4NjhhNmQ4ZmNlY2IwMTc5YTJiNmZlMGY3YWQzNThkNSI7czoyOiJhbSI7aToxO3M6NDoibGFuZyI7czo2OiJmcmVuY2giO30
             * %3D;
             * 8387c97d1f683b758a67a0473b586126=5ed998846fec70d6d2f73971b9cbbf0b;
             * b1d7468cf1b317c97c7c284f6bb14ff8
             * =587b82a7abb3d2aca134742b1df9acf7" -Ddebug_agent="userAgent:
             * Mozilla/5.0 (Windows; U; Windows NT 5.0; fr; rv:1.8.1.3)
             * Gecko/20070309 Firefox/2.0.0.3"
             */
        }
        // The cookies and user-agent will be added to the header sent by the
        // applet:
        if (this.cookie != null)
            addHeader("Cookie: " + this.cookie);
        if (this.userAgent != null)
            addHeader("User-Agent: " + this.userAgent);

        // Let's touch the server, to test that everything is Ok. Take care,
        // this is the only place where we override the default value, by null:
        // the default value will be used by the HttpConnect.getProtocol()
        // method.
        // Also, in FTP mode, there can be no default value.
        setServerProtocol(UploadPolicyFactory.getParameter(theApplet,
                PROP_SERVER_PROTOCOL, null, this));

        // We let the UploadPolicyFactory call the displayParameterStatus
        // method, so that the initialization is finished, including for classes
        // which inherit from DefaultUploadPolicy.
        displayDebug(
                "[DefaultUploadPolicy] end of constructor (serverProtocol has been set)",
                30);
    }

    // //////////////////////////////////////////////////////////////////////////////////////////////
    // /////////////////// UploadPolicy methods
    // //////////////////////////////////////////////////////////////////////////////////////////////

    // getters and setters are sorted below

    /**

⌨️ 快捷键说明

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