Example usage for org.apache.commons.fileupload.portlet PortletFileUpload PortletFileUpload

List of usage examples for org.apache.commons.fileupload.portlet PortletFileUpload PortletFileUpload

Introduction

In this page you can find the example usage for org.apache.commons.fileupload.portlet PortletFileUpload PortletFileUpload.

Prototype

public PortletFileUpload(FileItemFactory fileItemFactory) 

Source Link

Document

Constructs an instance of this class which uses the supplied factory to create FileItem instances.

Usage

From source file:hu.sztaki.lpds.pgportal.portlets.asm.ClientError.java

public void doUpload(ActionRequest request, ActionResponse response) throws PortletException {
    try {//from   w  w w  .  j a  va  2 s.c om
        String jobport = "";
        String selected_wf = "";
        //getting upload parameters
        ActionRequest temp_req = request;

        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);

        List fileItems = pfu.parseRequest(temp_req);

        Iterator iter = fileItems.iterator();
        FileItem file2upload = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();

            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                if (item.getFieldName().equals(new String("where2upload"))) {
                    jobport = item.getString();
                }
                if (item.getFieldName().startsWith(new String("instance_upload"))) {
                    selected_wf = item.getString();
                }
            } else {
                file2upload = item;
            }
        }

        String[] splitted = jobport.split("@");
        String selected_job = splitted[0];

        String selected_port = splitted[1];

        String userId = request.getRemoteUser();

        File uploadedFile = asm_service.uploadFiletoPortalServer(file2upload, userId, file2upload.getName());
        asm_service.placeUploadedFile(request.getRemoteUser(), uploadedFile, selected_wf, selected_job,
                selected_port);

    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(ASM_SamplePortlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:it.infn.ct.SemanticSearch_portlet.java

public void getInputForm(ActionRequest request, App_Input appInput) {
    if (PortletFileUpload.isMultipartContent(request)) {
        try {//from  www  . j  a v  a 2s  . c  o m
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";

            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {

                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    } // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.search_word = (String) request.getParameter("search_word");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
        appInput.nameSubject = (String) request.getParameter("nameSubject");

        appInput.idResouce = (String) request.getParameter("idResource");
        appInput.selected_language = (String) request.getParameter("selLanguage");
        appInput.numberPage = (String) request.getParameter("numberOfPage");
        appInput.numRecordsForPage = (String) request.getParameter("numberOfRecords");
        appInput.title_GS = (String) request.getParameter("title_GS");
        appInput.moreInfo = (String) request.getParameter("moreInfo");
        if (appInput.selected_language == null) {
            appInput.selected_language = (String) request.getParameter("nameLanguageDefault");
        }
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "Search Word: '"
            + appInput.search_word + "'" + LS + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS
            + "subject: '" + appInput.nameSubject + "'" + LS + "idResource: '" + appInput.idResouce + "'" + LS
            + "language selected: '" + appInput.selected_language + "'" + LS + "number page selected: '"
            + appInput.numberPage + "'" + LS + "number record for page: '" + appInput.numRecordsForPage + "'"
            + LS + "moreInfo: '" + appInput.moreInfo + "'" + LS);
}

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.RealWorkflowPortlet.java

@Override
public void doUpload(ActionRequest request, ActionResponse response) {
    PortletContext context = getPortletContext();
    context.log("[FileUploadPortlet] doUpload() called");

    try {//w ww.j  a  va2  s .  c o  m
        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);
        pfu.setSizeMax(uploadMaxSize); // Maximum upload size
        pfu.setProgressListener((ProgressListener) new FileUploadProgressListener());

        PortletSession ps = request.getPortletSession();
        if (ps.getAttribute("uploaded") == null)
            ps.setAttribute("uploaded", new Vector<String>());
        ps.setAttribute("upload", pfu);

        //get the FileItems
        String fieldName = null;

        List fileItems = pfu.parseRequest(request);
        Iterator iter = fileItems.iterator();
        File serverSideFile = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                fieldName = item.getFieldName();
            } else { // item is not a form field, do file upload
                Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                        .getAttribute("uploads", ps.APPLICATION_SCOPE);

                String s = item.getName();
                s = FilenameUtils.getName(s);
                ps.setAttribute("uploading", s);

                String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser();
                File f = new File(tempDir);
                if (!f.exists())
                    f.mkdirs();
                serverSideFile = new File(tempDir, s);
                item.write(serverSideFile);
                item.delete();
                context.log("[FileUploadPortlet] - file " + s + " uploaded successfully to " + tempDir);
                // file upload to storage
                try {
                    Hashtable h = new Hashtable();
                    h.put("portalURL", PropertyLoader.getInstance().getProperty("service.url"));
                    h.put("userID", request.getRemoteUser());

                    String uploadField = "";
                    // retrieve hidden parameters if item is a form field
                    for (FileItem item0 : (List<FileItem>) fileItems) {
                        if (item0.isFormField())
                            h.put(item0.getFieldName(), item0.getString());
                        else
                            uploadField = item0.getFieldName();

                    }

                    Hashtable hsh = new Hashtable();
                    ServiceType st = InformationBase.getI().getService("storage", "portal", hsh, new Vector());
                    PortalStorageClient psc = (PortalStorageClient) Class.forName(st.getClientObject())
                            .newInstance();
                    psc.setServiceURL(st.getServiceUrl());
                    psc.setServiceID("/upload");
                    if (serverSideFile != null) {
                        psc.fileUpload(serverSideFile, uploadField, h);
                    }
                } catch (Exception ex) {
                    response.setRenderParameter("full", "error.upload");
                    ex.printStackTrace();
                    return;
                }
                ((Vector<String>) ps.getAttribute("uploaded")).add(s);

            }

        }
        //            ps.removeAttribute("uploads",ps.APPLICATION_SCOPE);
        ps.setAttribute("finaluploads", "");

    } catch (FileUploadException fue) {
        response.setRenderParameter("full", "error.upload");

        fue.printStackTrace();
        context.log("[FileUploadPortlet] - failed to upload file - " + fue.toString());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        response.setRenderParameter("full", "error.exception");
        context.log("[FileUploadPortlet] - failed to upload file - " + e.toString());
        return;
    }
    response.setRenderParameter("full", "action.succesfull");

}

From source file:it.infn.ct.g_hmmer_portlet.java

/**
 * This method manages the user input fields managing two cases 
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the 
 * standard input case. The multipart content needs a manual processing of
 * all <form items/*www.  j av a 2 s  .c  om*/
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 * 
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}

From source file:hu.sztaki.lpds.pgportal.portlets.asm.SymbolMap.java

public void notdoUpload(ActionRequest request, ActionResponse response) throws PortletException {
    try {//from w  ww. ja  va  2  s. c  o m
        String jobport = "";
        String selected_wf = "";
        //getting upload parameters
        ActionRequest temp_req = request;

        DiskFileItemFactory factory = new DiskFileItemFactory();
        PortletFileUpload pfu = new PortletFileUpload(factory);

        List fileItems = pfu.parseRequest(temp_req);

        Iterator iter = fileItems.iterator();
        FileItem file2upload = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();

            // retrieve hidden parameters if item is a form field
            if (item.isFormField()) {
                if (item.getFieldName().equals(new String("where2upload"))) {
                    jobport = item.getString();
                }
                if (item.getFieldName().startsWith(new String("instance_upload"))) {
                    selected_wf = item.getString();
                }
            } else {
                file2upload = item;
            }
        }

        String[] splitted = jobport.split("@");
        String selected_job = splitted[0];

        String selected_port = splitted[1];

        String userId = request.getRemoteUser();

        File uploadedFile = asm_service.uploadFiletoPortalServer(file2upload, userId, file2upload.getName());
        asm_service.placeUploadedFile(request.getRemoteUser(), uploadedFile, selected_wf, selected_job,
                selected_port);

    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(ASM_SamplePortlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:it.infn.mib.AndreaPortlet.java

/**
 * This method manages the user input fields managing two cases 
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the 
 * standard input case. The multipart content needs a manual processing of
 * all <form items//from   ww w. ja  v  a 2  s  .c o m
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 * 
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
@SuppressWarnings("rawtypes")
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                //String fileName = item.getName();
                //String contentType = item.getContentType();
                //boolean isInMemory = item.isInMemory();
                //long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}

From source file:it.infn.ct.R_portlet.java

void getInputForm(ActionRequest request, App_Input appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {//w ww.  j  a v  a  2s  . co  m
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}

From source file:it.infn.ct.picalc_portlet.java

/**
 * This method manages the user input fields managing two cases 
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the 
 * standard input case. The multipart content needs a manual processing of
 * all <form items/*from w  ww  .  j  a v  a2 s .c  o m*/
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 * 
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                case CpuNumber:
                    appInput.cpuNumber = item.getString();
                    break;
                //case notifyEmail:
                //    appInput.notifyEmail=item.getString();
                //break;
                //case notifyStart:                        
                //    if (item.getString().equalsIgnoreCase("on"))
                //        appInput.notifyStart=true;
                //break;
                //case notifyStop:                        
                //    if (item.getString().equalsIgnoreCase("on"))
                //        appInput.notifyStop=true;
                //break;
                default:
                    // Should not happen unless inputControlsIds enum is not updated
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName                                                   
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.cpuNumber = (String) request.getParameter("CpuNumber");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
        //appInput.notifyEmail  = (String)request.getParameter("notifyEmail"  );
        //appInput.notifyStart  =((String)request.getParameter("notifyStart" )).equalsIgnoreCase("on")?true:false;
        //appInput.notifyStop   =((String)request.getParameter("notifyStop"  )).equalsIgnoreCase("on")?true:false;
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "CpuNumber    : '"
            + appInput.cpuNumber + "'" + LS + "JobIdentifier: '" + appInput.jobIdentifier + "'"
            //+LS+"notifyEmail  : '"+appInput.notifyEmail  +"'"
            //+LS+"notifyStart  : '"+appInput.notifyStart  +"'"
            //+LS+"notifyStop   : '"+appInput.notifyStop   +"'"
            + LS);
}

From source file:it.infn.ct.mi_parallel_portlet.java

/**
 * This method manages the user input fields managing two cases
 * distinguished by the type of the input <form ... statement The use of
 * upload file controls needs the use of "multipart/form-data" while the
 * else condition of the isMultipartContent check manages the standard input
 * case. The multipart content needs a manual processing of all <form items
 * All form' input items are identified by the 'name' input property inside
 * the jsp file//from www .  ja  v  a  2 s .  c o  m
 * @param request ActionRequest instance (processAction)
 * @param appInput AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request)) {
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            int i = 0;
            int j = 0;
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                //                    String fileName = item.getName();
                //                    String contentType = item.getContentType();
                //                    boolean isInMemory = item.isInMemory();
                //                    long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                case collection_type:
                    appInput.collectionType = item.getString();
                    break;
                case task_number:
                    appInput.taskNumber = item.getString();
                    break;
                case parametric_executable:
                    appInput.executable = item.getString();
                    break;
                case executables:
                    appInput.executables.add(item.getString());
                    i++;
                    break;
                case argument:
                    appInput.arguments.add(item.getString());
                    j++;
                    break;
                case final_executable:
                    appInput.finalJobExecutable = item.getString();
                    break;
                case final_argument:
                    appInput.finalJobArgument = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName
            } // while iter.hasNext()   
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    } // The input form do not use the "multipart/form-data" 
    else {
        // Retrieve from the input form the given application values
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
        appInput.collectionType = (String) request.getParameter("collection_type");
        appInput.taskNumber = (String) request.getParameter("task_number");

    } // ! isMultipartContent

    String tmp = "";
    for (int i = 0; i < appInput.executables.size(); i++) {
        if (!appInput.collectionType.equals("JOB_PARAMETRIC")) {
            tmp += LS + "executables[" + i + "]:" + appInput.executables.get(i) + "'";
        } else {
            tmp += LS + "executable:" + appInput.executable + "'";
        }
        tmp += LS + "arguments[" + i + "]:" + appInput.arguments.get(i) + "'";
    }
    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------"
    //                + LS + "inputFileName: '" + appInput.inputFileName + "'"
    //                + LS + "inputFileText: '" + appInput.inputFileText + "'"
            + LS + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS + "collectionType: '"
            + appInput.collectionType + "'" + LS + "taskNumber: '" + appInput.taskNumber + "'" + LS + tmp + LS
            + "finalJobExecutable: '" + appInput.finalJobExecutable + "'" + LS + "finalJobArgument: '"
            + appInput.finalJobArgument + "'" + LS);

}

From source file:it.infn.ct.code_rade_portlet.java

/**
 * This method manages the user input fields managing two cases
 * distinguished by the type of the input <form ... statement
 * The use of upload file controls needs the use of "multipart/form-data"
 * while the else condition of the isMultipartContent check manages the
 * standard input case. The multipart content needs a manual processing of
 * all <form items/*w  w  w.  j  a v  a2  s .  c  o  m*/
 * All form' input items are identified by the 'name' input property
 * inside the jsp file
 *
 * @param request   ActionRequest instance (processAction)
 * @param appInput  AppInput instance storing the jobSubmission data
 */
void getInputForm(ActionRequest request, AppInput appInput) {
    if (PortletFileUpload.isMultipartContent(request))
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List items = upload.parseRequest(request);
            File repositoryPath = new File("/tmp");
            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
            diskFileItemFactory.setRepository(repositoryPath);
            Iterator iter = items.iterator();
            String logstring = "";
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                // Prepare a log string with field list
                logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'";
                switch (inputControlsIds.valueOf(fieldName)) {
                case file_inputFile:
                    appInput.inputFileName = item.getString();
                    processInputFile(item, appInput);
                    break;
                case inputFile:
                    appInput.inputFileText = item.getString();
                    break;
                case JobIdentifier:
                    appInput.jobIdentifier = item.getString();
                    break;
                default:
                    _log.warn("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'");
                } // switch fieldName
            } // while iter.hasNext()
            _log.info(LS + "Reporting" + LS + "---------" + LS + logstring + LS);
        } // try
        catch (Exception e) {
            _log.info("Caught exception while processing files to upload: '" + e.toString() + "'");
        }
    // The input form do not use the "multipart/form-data"
    else {
        // Retrieve from the input form the given application values
        appInput.inputFileName = (String) request.getParameter("file_inputFile");
        appInput.inputFileText = (String) request.getParameter("inputFile");
        appInput.jobIdentifier = (String) request.getParameter("JobIdentifier");
    } // ! isMultipartContent

    // Show into the log the taken inputs
    _log.info(LS + "Taken input parameters:" + LS + "-----------------------" + LS + "inputFileName: '"
            + appInput.inputFileName + "'" + LS + "inputFileText: '" + appInput.inputFileText + "'" + LS
            + "jobIdentifier: '" + appInput.jobIdentifier + "'" + LS);
}