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

📄 defaultuploadpolicy.java

📁 [linux.rar] - 嵌入式linux开发教程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }// appendHeader

    /**
     * Default implementation of the
     * {@link wjhk.jupload2.policies.UploadPolicy#onFileSelected(wjhk.jupload2.filedata.FileData)}
     * . Nothing's done.
     */
    public void onFileSelected(FileData fileData) {
        // Default implementation : no action
    }

    /**
     * Default implementation of the
     * {@link wjhk.jupload2.policies.UploadPolicy#onFileDoubleClicked(FileData)}
     * . Nothing's done.
     */
    public void onFileDoubleClicked(FileData fileData) {
        // Default implementation : no action
    }

    /** @see UploadPolicy#sendDebugInformation(String, Exception) */
    public void sendDebugInformation(String description, Exception exception) {
        try {
            displayInfo("Sending debug information to " + getUrlToSendErrorTo());
            if (null != getUrlToSendErrorTo()) {
                if (JOptionPane.showConfirmDialog(null,
                        getString("questionSendMailOnError"),
                        getString("Confirm"), JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                    displayDebug(
                            "[sendDebugInformation] Within response == true",
                            30);

                    String action = null;
                    String line;
                    HTTPConnectionHelper connectionHelper = null;
                    boolean localDebugOk = this.debugOk;

                    try {
                        URL url = new URL(this.urlToSendErrorTo);
                        connectionHelper = new HTTPConnectionHelper(this);
                        connectionHelper.initRequest(url, "POST", false, true);

                        ByteArrayEncoder baeContent = new ByteArrayEncoderHTTP(
                                this, connectionHelper.getByteArrayEncoder()
                                        .getBoundary(), connectionHelper
                                        .getByteArrayEncoder().getEncoding());
                        // The message is written in English, as it is not sure
                        // that
                        // the webmaster speaks the same language as the current
                        // user.
                        baeContent.appendTextProperty("description",
                                "An error occured during upload, in JUpload.");
                        String exceptionClass = null;
                        String exceptionCause = null;
                        String exceptionStackTrace = null;
                        if (exception != null) {
                            exceptionClass = exception.getClass().getName();
                            if (exception.getCause() != null) {
                                exceptionCause = exception.getCause()
                                        .getClass().getName();
                            }
                            StackTraceElement[] elements = exception
                                    .getStackTrace();
                            ByteArrayEncoderHTTP baeStackTrace = new ByteArrayEncoderHTTP(
                                    this, connectionHelper
                                            .getByteArrayEncoder()
                                            .getBoundary(), connectionHelper
                                            .getByteArrayEncoder()
                                            .getEncoding());
                            for (int i = 0; i < elements.length; i += 1) {
                                baeStackTrace.append(" at ");
                                baeStackTrace
                                        .append(elements[i].getClassName());
                                baeStackTrace.append(".");
                                baeStackTrace.append(elements[i]
                                        .getMethodName());
                                baeStackTrace.append("() [line ");
                                baeStackTrace.append(Integer
                                        .toString(elements[i].getLineNumber()));
                                baeStackTrace.append("]\r\n");
                            }
                            baeStackTrace.close();
                            exceptionStackTrace = baeStackTrace.getString();
                        }
                        baeContent.appendTextProperty("exceptionClass",
                                exceptionClass);
                        baeContent.appendTextProperty("exceptionCause",
                                exceptionCause);
                        baeContent.appendTextProperty("exceptionStackTrace",
                                exceptionStackTrace);

                        String baeBound = connectionHelper
                                .getByteArrayEncoder().getBoundary();
                        String baeEncoding = connectionHelper
                                .getByteArrayEncoder().getEncoding();
                        ByteArrayEncoder baeDebug = new ByteArrayEncoderHTTP(
                                this, baeBound, baeEncoding);
                        if (this.debugGenerateFile) {
                            // During debug output, we need to make sure that
                            // the debug log is not changed, so we set debugOk
                            // to false temporarily. -> Everything goes to
                            // stdout.
                            action = "flush (debugGenerateFile=true)";
                            this.debugOut.flush();
                            this.debugOk = false;
                            // First, calculate the size of the strings we will
                            // send.
                            action = "read debug file (debugGenerateFile=true)";
                            BufferedReader debugIn = new BufferedReader(
                                    new FileReader(this.debugFile));
                            while ((line = debugIn.readLine()) != null) {
                                baeDebug.append(line).append("\r\n");
                            }
                            debugIn.close();

                            // We are done with the debug log, so re-enable it.
                            this.debugOk = localDebugOk;
                        }// if (this.debugGenerateFile)
                        else {
                            action = "read debug file (debugGenerateFile=false)";
                            baeDebug.append(this.applet.getLogWindow()
                                    .getText());
                        }
                        action = "baeDebug.close()";
                        baeDebug.close();                        

                        baeContent.appendTextProperty("debugOutput", baeDebug
                                .getString());
                        baeContent.appendEndPropertyList();
                        // The content has been built.
                        baeContent.close();

                        // byteArrayEncoder
                        // .append("Content-type:
                        // application/x-www-form-urlencoded\r\n");
                        action = "send request";
                        connectionHelper.append(
                                "Content-Type: multipart/form-data; boundary=")
                                .append(
                                        connectionHelper.getBoundary()
                                                .substring(2)).append("\r\n");
                        connectionHelper.append("Content-length: ").append(
                                String.valueOf(baeContent.getEncodedLength()))
                                .append("\r\n");

                        // Let's send the headers (without baeDescription) ...
                        connectionHelper.sendRequest();
                        // Blank line (end of header)
                        connectionHelper.append("\r\n");
                        connectionHelper.append(baeContent);

                        // .. then the debug information
                        /*
                         * debugIn = new BufferedReader(new FileReader(
                         * this.debugFile)); while ((line = debugIn.readLine())
                         * != null) { baeDebug = new ByteArrayEncoderHTTP(this,
                         * baeBound, baeEncoding);
                         * baeDebug.append(line).append("\r\n");
                         * baeDebug.close(); connectionHelper.append(baeDebug);
                         * } debugIn.close();
                         */

                        action = "connectionHelper.readHttpResponse()";
                        int status = connectionHelper.readHttpResponse();

                        displayDebug(
                                "========================================================================================",
                                90);
                        displayDebug(
                                "==================      sendDebugInformation [start]   =================================",
                                90);
                        displayDebug(
                                "========================================================================================",
                                90);
                        displayDebug(
                                "[sendDebugInformation] Sent to server: \r\n"
                                        + connectionHelper
                                                .getByteArrayEncoder()
                                                .getString(), 90);
                        displayDebug(
                                "========================================================================================",
                                90);
                        displayDebug(
                                "[sendDebugInformation] Body received: \r\n"
                                        + connectionHelper.getResponseBody(),
                                90);
                        displayDebug(
                                "========================================================================================",
                                90);
                        displayDebug(
                                "==================      sendDebugInformation [end]     =================================",
                                90);
                        displayDebug(
                                "========================================================================================",
                                90);

                        // Is our upload a success ?
                        if (!checkUploadSuccess(status, connectionHelper
                                .getResponseMsg(), connectionHelper
                                .getResponseBody())) {
                            throw new JUploadExceptionUploadFailed(
                                    getString("errHttpResponse"));
                        }

                        displayInfo("debug information sent correctly");
                    } catch (MalformedURLException e) {
                        throw new JUploadIOException(
                                "Malformed URL Exception for "
                                        + this.urlToSendErrorTo, e);
                    } catch (Exception e) {
                        this.debugOk = localDebugOk;
                        displayErr(getString("errDuringLogManagement") + " ("
                                + action + ")", e);
                    } finally {
                        this.debugOk = localDebugOk;
                    }
                }
            }
        } catch (JUploadIOException e) {
            displayErr("Could not send debug information", e);
        }
    }// sendDebugInformation

    /**
     * This method manages all applet parameters. It allows javascript to update
     * their value, for instance after the user chooses a value in a list ...
     * 
     * @throws JUploadException
     * @see wjhk.jupload2.policies.UploadPolicy#setProperty(java.lang.String,
     *      java.lang.String)
     */
    public void setProperty(String prop, String value) throws JUploadException {

        displayDebug("[DefaultUploadPolicy] Call of setProperty: " + prop
                + " => " + value, 30);

        if (prop.equals(PROP_AFTER_UPLOAD_URL)) {
            setAfterUploadURL(value);
        } else if (prop.equals(PROP_ALLOW_HTTP_PERSISTENT)) {
            setAllowHttpPersistent(Boolean.parseBoolean(value));
        } else if (prop.equals(PROP_ALLOWED_FILE_EXTENSIONS)) {
            setAllowedFileExtensions(value);
        } else if (prop.equals(PROP_DEBUG_LEVEL)) {
            setDebugLevel(UploadPolicyFactory.parseInt(value, this.debugLevel,
                    this));
        } else if (prop.equals(PROP_FILE_CHOOSER_ICON_FROM_FILE_CONTENT)) {
            setFileChooserIconFromFileContent(UploadPolicyFactory.parseInt(
                    value, getFileChooserIconFromFileContent(), this));
        } else if (prop.equals(PROP_FILE_CHOOSER_ICON_SIZE)) {
            setFileChooserIconSize(UploadPolicyFactory.parseInt(value,
                    getFileChooserIconSize(), this));
        } else if (prop.equals(PROP_LANG)) {
            setLang(value);
        } else if (prop.equals(PROP_FILENAME_ENCODING)) {
            setFilenameEncoding(value);
        } else if (prop.equals(PROP_LOOK_AND_FEEL)) {
            setLookAndFeel(value);
        } else if (prop.equals(PROP_MAX_CHUNK_SIZE)) {
            setMaxChunkSize(UploadPolicyFactory.parseLong(value,
                    this.maxChunkSize, this));
        } else if (prop.equals(PROP_MAX_FILE_SIZE)) {
            setMaxFileSize(UploadPolicyFactory.parseLong(value,
                    this.maxFileSize, this));
        } else if (prop.equals(PROP_NB_FILES_PER_REQUEST)) {
            setNbFilesPerRequest(UploadPolicyFactory.parseInt(value,
                    this.nbFilesPerRequest, this));
        } else if (prop.equals(PROP_POST_URL)) {
            setPostURL(value);
        } else if (prop.equals(PROP_SERVER_PROTOCOL)) {
            setServerProtocol(value);
        } else if (prop.equals(PROP_STRING_UPLOAD_SUCCESS)) {
            setStringUploadSuccess(value);
        } else if (prop.equals(PROP_SSL_VERIFY_CERT)) {
            setSslVerifyCert(value);
        } else if (prop.equals(PROP_URL_TO_SEND_ERROR_TO)) {
            setUrlToSendErrorTo(value);
        } else {
            displayWarn("Unknown applet parameter: " + prop
                    + " (in DefaultUploadPolicy.setProperty)");
        }
    }

    /**
     * This method displays the applet parameter list, according to the current
     * debugLevel. It is called by the {@link #setDebugLevel(int)} method. It
     * should be override by any subclasses, that should display its own
     * parameters, then call <I>

⌨️ 快捷键说明

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