Example usage for org.apache.commons.fileupload DefaultFileItem getStoreLocation

List of usage examples for org.apache.commons.fileupload DefaultFileItem getStoreLocation

Introduction

In this page you can find the example usage for org.apache.commons.fileupload DefaultFileItem getStoreLocation.

Prototype

public File getStoreLocation() 

Source Link

Document

Returns the java.io.File object for the FileItem's data's temporary location on the disk.

Usage

From source file:sos.settings.SOSSettingsDialog.java

private void checkRequest() throws Exception {
    this.debug(3, "checkRequest");

    this.settings.sources.put(this.settings.source, this.dialogApplicationsTitle);

    this.settings.application = "";
    this.settings.section = "";
    this.settings.entry = "";

    this.inputQuery = "";
    this.inputExport = "";
    this.inputImport = "";
    this.importOriginalFileName = "";

    // Daten aus fileUpload
    LinkedHashMap requestMultipart = new LinkedHashMap();

    if (this.request != null) {
        /////////////////////////////////////////////////////////
        String contentType = this.request.getHeader("Content-type");
        if (contentType != null && contentType.startsWith("multipart/")) { // ob Import
            try {
                DiskFileUpload upload = new DiskFileUpload();

                upload.setSizeMax(this.importMaxSize);
                upload.setSizeThreshold(0); // nicht im Memory sondern als
                // Datei speichern

                List items = upload.parseRequest(this.request);
                Iterator iter = items.iterator();

                while (iter.hasNext()) {
                    //FileItem item = (FileItem) iter.next();
                    DefaultFileItem item = (DefaultFileItem) iter.next();
                    if (item.isFormField()) {
                        requestMultipart.put(item.getFieldName(), item.getString());
                        this.request.setAttribute(item.getFieldName(), item.getString());
                    } else { // aus upload
                        if (item.getName() != null && !item.getName().equals("")) {
                            //requestMultipart.put(item.getFieldName(),item.getStoreLocation());
                            requestMultipart.put(item.getFieldName(),
                                    item.getStoreLocation().getAbsolutePath());
                            this.request.setAttribute(item.getFieldName(),
                                    item.getStoreLocation().getAbsolutePath());
                            this.importOriginalFileName = item.getName();
                        } else {
                            requestMultipart.put(item.getFieldName(), "");
                            this.request.setAttribute(item.getFieldName(), "");
                        }/*w  ww.  j av  a 2 s  . c o m*/

                    }

                }
            } catch (FileUploadException e) {
                this.setError(e.getMessage(), SOSClassUtil.getMethodName());
            }
        } // MULTIPART Form

        /////////////////////////////////////////////////////////              
        if (this.getRequestValue("application") != null) {
            this.settings.application = this.getRequestValue("application");
        }
        if (this.getRequestValue("section") != null) {
            this.settings.section = this.getRequestValue("section");
        }
        if (this.getRequestValue("entry") != null) {
            this.settings.entry = this.getRequestValue("entry");
        }
        if (this.getRequestValue("application_type") != null) {
            try {
                this.applicationType = Integer.parseInt(this.getRequestValue("application_type"));
            } catch (Exception e) {
                this.applicationType = 0;
            }
        }
        if (this.getRequestValue("section_type") != null) {
            try {
                this.sectionType = Integer.parseInt(this.getRequestValue("section_type"));
            } catch (Exception e) {
                this.sectionType = 0;
            }
        }

        if (this.getRequestValue("action") != null) {
            this.action = this.getRequestValue("action");

        }
        if (this.getRequestValue("range") != null) {
            this.range = this.getRequestValue("range");
        }
        if (this.getRequestValue("item") != null) {
            this.item = this.getRequestValue("item");
        }
        if ((this.getRequestValue("btn_store.x") != null) && (this.getRequestValue("btn_store.y") != null)) {
            this.action = "store";
        } else if ((this.getRequestValue("btn_insert.x") != null)
                && (this.getRequestValue("btn_insert.y") != null)) {
            this.action = "insert";
        } else if ((this.getRequestValue("btn_delete.x") != null)
                && (this.getRequestValue("btn_delete.y") != null)) {
            this.action = "delete";
        } else if ((this.getRequestValue("btn_schema.x") != null)
                && (this.getRequestValue("btn_schema.y") != null)) {
            this.action = "schema";
        } else if ((this.getRequestValue("btn_duplicate.x") != null)
                && (this.getRequestValue("btn_duplicate.y") != null)) {
            this.action = "duplicate";
            this.range = "entries";
        } else if ((this.getRequestValue("btn_cancel.x") != null)
                && (this.getRequestValue("btn_cancel.y") != null)) {
            this.action = "show";
            if (this.range.equals("application")) {
                this.range = "applications";
            } else if (this.range.equals("section")) {
                this.range = "sections";
            } else {
                this.range = this.range.equals("list") ? "sections" : "entries";
            }
        } else if ((this.getRequestValue("btn_query.x") != null)
                && (this.getRequestValue("btn_query.y") != null)) {
            this.action = "query";
            this.range = "entries";

            if (this.getRequestValue("query_select_range") != null
                    && this.getRequestValue("query_select_range").equals("2")) {
                this.item = "replace";
            }

        } else if ((this.getRequestValue("btn_export.x") != null)
                && (this.getRequestValue("btn_export.y") != null)) {
            this.action = "export";
            this.range = "entries";
        } else if ((this.getRequestValue("btn_import.x") != null)
                && (this.getRequestValue("btn_import.y") != null)) {
            this.action = "import";
            this.range = "entries";
        } else if ((this.getRequestValue("btn_clipboard_copy.x") != null)
                && (this.getRequestValue("btn_clipboard_copy.y") != null)) {
            if (this.getRequestValue("last_action") != null) {
                this.action = this.getRequestValue("last_action");
            } else {
                this.action = "show";
            }
            this.clipboardAction = "copy";
        } else if ((this.getRequestValue("btn_clipboard_paste.x") != null)
                && (this.getRequestValue("btn_clipboard_paste.y") != null)) {
            if (this.getRequestValue("last_action") != null) {
                this.action = this.getRequestValue("last_action");
            } else {
                this.action = "show";
            }

            this.clipboardAction = "paste";
        } else if ((this.getRequestValue("btn_import_file.x") != null)
                && (this.getRequestValue("btn_import_file.y") != null)) {

            this.action = ((this.getRequestValue("last_action") != null)
                    && this.getRequestValue("last_action").equals("new")) ? "insert" : "store";
            this.range = "entry";
            this.item = "upload";
        }

        if (this.getRequestValue("input_query") != null) {
            this.inputQuery = this.getRequestValue("input_query");
        }

        if (this.getRequestValue("input_query_replace") != null) {
            this.replaceQuery = this.getRequestValue("input_query_replace");
        }

        if (this.getRequestValue("input_export") != null) {
            this.inputExport = this.getRequestValue("input_export");
        }

        if (this.getRequestValue("export_documentation") != null) {
            this.exportDocumentation = 1;
        }

        if (this.getRequestValue("input_import") != null) {
            this.inputImport = this.getRequestValue("input_import");
        }

    }
    if (this.applicationName.equals("")) {
        this.applicationName = this.settings.application;
    }

    if (this.enableShowDevelopmentData) {
        this.showDevelopmentData(requestMultipart);
    }

}