List of usage examples for org.apache.commons.fileupload.portlet PortletFileUpload PortletFileUpload
public PortletFileUpload(FileItemFactory fileItemFactory)
FileItem
instances. From source file:hu.sztaki.lpds.pgportal.portlets.file.LFCFileStoragePortlet.java
@Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException { try {/*from www. j a v a2 s .co m*/ String userId = request.getRemoteUser(); /* if(request.getAttribute(SportletProperties.ACTION_EVENT)!=null) action=(""+request.getAttribute(SportletProperties.ACTION_EVENT)).split("=")[1]; */ String action = null; if ((request.getParameter("action") != null) && (!request.getParameter("action").equals(""))) { action = request.getParameter("action"); } if (PortletFileUpload.isMultipartContent(request)) { DiskFileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload pfu = new PortletFileUpload(factory); pfu.setSizeMax(10485760); // Maximum upload size //pfu.setProgressListener(new FileUploadProgressListener()); /* PortletSession ps = request.getPortletSession(); ps.setAttribute("upload", pfu, ps.APPLICATION_SCOPE); String actionName = null;*/ String fieldName; List fileItems = pfu.parseRequest(request); Iterator iter = fileItems.iterator(); HashMap params = new HashMap(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); // retrieve hidden parameters if item is a form field if (item.isFormField()) { //getting parameters fieldName = item.getFieldName(); // System.out.println("Name is : " + fieldName + " value is : " + item.getString()); if (item.getFieldName().equals(new String("SEListBoxBean_select"))) { params.put("se", item.getString()); } if (item.getFieldName().equals(new String("uploadName"))) { params.put("upName", item.getString()); } if (item.getFieldName().equals(new String("ownRead"))) { params.put("urBean", item.getString()); } if (item.getFieldName().equals(new String("ownWrite"))) { params.put("uwBean", item.getString()); } if (item.getFieldName().equals(new String("ownExecute"))) { params.put("uxBean", item.getString()); } if (item.getFieldName().equals(new String("grRead"))) { params.put("grBean", item.getString()); } if (item.getFieldName().equals(new String("grWrite"))) { params.put("gwBean", item.getString()); } if (item.getFieldName().equals(new String("grExecute"))) { params.put("gxBean", item.getString()); } if (item.getFieldName().equals(new String("othRead"))) { params.put("orBean", item.getString()); } if (item.getFieldName().equals(new String("othWrite"))) { params.put("owBean", item.getString()); } if (item.getFieldName().equals(new String("othExecute"))) { params.put("oxBean", item.getString()); } } else { // item is not a form field, do file upload String s = item.getName(); s = FilenameUtils.getName(s); String tempDir = System.getProperty("java.io.tmpdir") + "/uploads/" + request.getRemoteUser(); String origfile = tempDir + "/" + s; params.put("origfile", origfile); File f = new File(tempDir); if (!f.exists()) f.mkdirs(); File serverSideFile = new File(tempDir, s); item.write(serverSideFile); item.delete(); } } if (action == null) { doUpload(request, response, params); } } if (action != null) { try { Method method = this.getClass().getMethod(action, new Class[] { ActionRequest.class, ActionResponse.class }); method.invoke(this, new Object[] { request, response }); } catch (IllegalArgumentException ex) { Logger.getLogger(LFCFileStoragePortlet.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(LFCFileStoragePortlet.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchMethodException e) { System.out.println("-----------------------Nincs ilyen metdus:"); } catch (IllegalAccessException e) { System.out.println("----------------------Nincs jogod a metdushoz"); } } PortletMode pMode = request.getPortletMode(); // upload -- enctype="multipart/form-data" } catch (Exception ex) { Logger.getLogger(LFCFileStoragePortlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:hu.sztaki.lpds.pgportal.portlets.credential.AssertionPortlet.java
/** * Uploading SAML file(s) for interaction with the Java Applet. * The parameters are filled in by the SAML assiertion applet. * This function contains a fallback to the help provider of gUSE. * @param request ResourceRequest//from w w w . j av a 2 s .c o m * @param response ResouceResponse * @throws PortletException * @throws IOException */ @Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { logger.debug("serveResource: guse=" + request.getParameter("guse")); if (!"doAppletUpload".equals(request.getParameter("guse"))) { super.serveResource(request, response); return; } String msg; try { logger.debug("Assertion-doUpload"); FileItem samlFile = null; String sresource = null; // selected resource try { DiskFileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload pfu = new PortletFileUpload(factory); pfu.setSizeMax(1048576); // Maximum upload size 1Mb Iterator iter = pfu.parseRequest(PortalUtil.getHttpServletRequest(request)).iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { // retrieve parameters if item is a form field if ("sresource".equals(item.getFieldName())) { sresource = item.getString(); } } else { if ("samlFile".equals(item.getFieldName())) { samlFile = item; } } } List<String> result = uploadSaml(request.getPortletSession(), samlFile, sresource, request.getRemoteUser()); StringBuilder sb = new StringBuilder(); boolean flag = false; for (String m : result) { if (flag) { sb.append("\n"); } else { flag = true; } sb.append(m); } msg = sb.toString(); } catch (Exception e) { msg = "Upload failed. Reason: " + e.getMessage(); logger.info("Upload of assertion failed. Reason: " + e.getMessage()); logger.debug("Exception:", e); } response.setContentType("text/plain"); response.addProperty("Cache-Control", "no-cache"); response.getWriter().write(msg); logger.info("Returning: " + msg); } catch (Exception e2) { logger.error("Error in " + getClass().getName() + "\n", e2); } return; }
From source file:hu.sztaki.lpds.pgportal.portlets.asm.ClientError.java
@SuppressWarnings("empty-statement") public void doUploadLigands(ActionRequest request, ActionResponse response) { try {//from www . j a v a 2 s . c o m // MULTIPART REQUEST ActionRequest temp_req = request; DiskFileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload pfu = new PortletFileUpload(factory); List fileItems = pfu.parseRequest(temp_req); // ligands Iterator iter = fileItems.iterator(); ArrayList<FileItem> file2upload = new ArrayList<FileItem>(); FileItem receptorFileItem = null; FileItem configFileItem = null; String vina_configuration = ""; String vina_best_result = ""; String rep_owner = ""; String task_name = ""; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { // TEXT FIELD if (item.getFieldName().equals("vina_configuration")) { vina_configuration = item.getString(); } if (item.getFieldName().startsWith("vina_best_result")) { vina_best_result = item.getString(); } if (item.getFieldName().startsWith("rep_owner")) { rep_owner = item.getString(); } if (item.getFieldName().startsWith("task_name")) { task_name = item.getString(); } } else { // FILE UPLOAD String fieldName = item.getFieldName(); String fileName = item.getName(); long sizeInBytes = item.getSize(); if (fieldName.equals("receptor")) { receptorFileItem = item; } if (fieldName.equals("ligands")) { file2upload.add(item); } if (fieldName.equals("vina_config_file")) { configFileItem = item; } } } //IMPORT NEW WORKFLOW INSTANCE // selected_wf_type="122"; String newWfinstanceID = selected_wf_type + "_" + task_name; String ruser = request.getRemoteUser(); rep_owner = ruser; String userId = rep_owner; String rowner = request.getParameter("owner"); selected_wf = importWorkflow(rep_owner, ruser, selected_wf_type, newWfinstanceID); if (selected_wf.length() < 3) { throwError("Import " + newWfinstanceID + " workflow is failed", 1); } String job_generator = "Generator"; String port_input_receptor = "5"; //input-receptor.pdbqt String port_vina_config = "4"; //vina-config.txt String port_input_ligands = "3"; //input-ligands.zip String cmd_parameter_wus_nr = ""; // number of WUs String job_collector = "collector.sh"; String cmd_parameter_best = ""; // number of Best results // UPLOAD LIGAND ZIP FILE String selected_job = job_generator; String selected_port = port_input_ligands; for (FileItem f : file2upload) { if (f.getName().endsWith(".zip")) { File uploadedFile = asm_service.uploadFiletoPortalServer(f, userId, f.getName()); asm_service.placeUploadedFile(userId, uploadedFile, selected_wf, selected_job, selected_port); } } /* // UPLOAD MULTIPLE PDBQT LIGAND FILE String ligandDir="/tmp/wf_dir_ligands"; String zipName="upload.zip"; Runtime.getRuntime().exec("rm -rf "+ligandDir+"/"+zipName); for(FileItem f:file2upload){ File uploadedFile = asm_service.uploadFiletoPortalServer(f, userId, f.getName()); System.out.println("jaj"+uploadedFile.getAbsolutePath()); // PREPARE UPLOADED FILES to SUBMIT MOVE AND COMPRESS Runtime.getRuntime().exec("cp "+uploadedFile+" "+ligandDir); Runtime.getRuntime().exec("zip "+ligandDir+"/"+zipName+" "+ligandDir+"/"+uploadedFile.getName()); } File ligandsFile=new File(ligandDir+"/"+zipName); selected_port = "0"; asm_service.placeUploadedFile(userId, ligandsFile, selected_wf, selected_job, selected_port); */ // UPLOAD RECEPTOR PDBQT FILE selected_port = port_input_receptor; File receptorFile = asm_service.uploadFiletoPortalServer(receptorFileItem, userId, receptorFileItem.getName()); asm_service.placeUploadedFile(userId, receptorFile, selected_wf, selected_job, selected_port); // SETUP CONFIGURATION if (configFileItem == null) { String content = vina_configuration; selected_port = port_vina_config; asm_service.setInputText(userId, content, selected_wf, selected_job, selected_port); } else { selected_port = port_vina_config; File configFile = asm_service.uploadFiletoPortalServer(configFileItem, userId, configFileItem.getName()); asm_service.placeUploadedFile(userId, configFile, selected_wf, selected_job, selected_port); } // WUs number String wu_content = "5"; asm_service.setCommandLineArg(userId, selected_wf, selected_job, wu_content); // setup Best result number, at the collector job argument String best_content = vina_best_result; selected_job = job_collector; asm_service.setCommandLineArg(userId, selected_wf, selected_job, best_content); asm_service.submit(userId, selected_wf, "", ""); request.setAttribute("nextJSP", DISPLAY_PAGE); throwError("Wow! Submitted task! Success! Wait for run, and check eventually!", 10); String nextJSP = DISPLAY_PAGE; PortletRequestDispatcher dispatcher; dispatcher = getPortletContext().getRequestDispatcher(nextJSP); dispatcher.include(request, response); } catch (Exception ex) { throwError(ex.getMessage(), 10); } }
From source file:hu.sztaki.lpds.pgportal.portlets.asm.SymbolMap.java
@SuppressWarnings("empty-statement") public void doUploadLigands(ActionRequest request, ActionResponse response) { String errorMessage = ""; String userMessage = ""; String selected_wf = ""; int docking_type = 0; try {/* w ww . j a va2 s.c o m*/ // MULTIPART REQUEST ActionRequest temp_req = request; String userId = request.getRemoteUser(); DiskFileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload pfu = new PortletFileUpload(factory); List fileItems = pfu.parseRequest(temp_req); // ligands Iterator iter = fileItems.iterator(); FileItem ligandFileItem = null; FileItem receptorFileItem = null; FileItem configFileItem = null; FileItem inputsFileItem = null; String vina_configuration = ""; String vina_best_result = ""; String docking_wu = ""; String task_name = ""; FileItem gpfFileItem = null; FileItem dpfFileItem = null; throwMessage("Submitting started, processing inputs & files", 1); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { if (!Validate.textIsAlphaNumeric(item.getString())) throw new Exception(" Input parameter string is not valid from FORM " + item.getFieldName() + ", value:" + item.getString()); // TEXT FIELD if (item.getFieldName().equals("vina_configuration")) { vina_configuration = item.getString(); } if (item.getFieldName().startsWith("docking_wu")) { // number docking_wu = item.getString(); } if (item.getFieldName().startsWith("best_result")) { vina_best_result = item.getString(); } if (item.getFieldName().startsWith("task_name")) { task_name = item.getString(); } if (item.getFieldName().startsWith("docking_type")) { docking_type = Integer.parseInt(item.getString()); } } else { // FILE UPLOAD String fieldName = item.getFieldName(); String fileName = item.getName(); long sizeInBytes = item.getSize(); // pdb or pdbqt if (!Validate.fileNameValid(fileName)) throw new Exception(" Input parameter file is not valid from FORM " + fieldName); // pdb or pdbqt if (fieldName.equals("receptor")) { receptorFileItem = item; } if (fieldName.equals("gpfparameter")) { gpfFileItem = item; } if (fieldName.equals("dpfparameter")) { dpfFileItem = item; } // .zip if (fieldName.equals("ligands")) { ligandFileItem = item; } // .pdb if (fieldName.equals("ligand")) { ligandFileItem = item; } // inputs.zip if (fieldName.equals("inputs")) { inputsFileItem = item; } if (fieldName.equals("vina_config_file")) { configFileItem = item; } } } throwMessage("Submitting started, checking inputs & uploading files", 1); String selected_wf_type = WfTypeFromDockingType(docking_type); if (!Validate.numberIsNaturalNumber(docking_wu, 1, Maximum_WU)) throw new Exception(" Input parameter docking_wu is not valid, value " + docking_wu + " Maximum_WU:" + Maximum_WU); if (!Validate.numberIsNaturalNumber(vina_best_result, 1, Integer.parseInt(docking_wu))) throw new Exception(" Input parameter best_result is not in valid range (1," + docking_wu + "), value: " + vina_best_result); //IMPORT NEW WORKFLOW INSTANCE String newWfinstanceID = selected_wf_type + "_" + task_name; selected_wf = importWorkflow(developerId, userId, selected_wf_type, newWfinstanceID); if (!Validate.wfInstanceValid(selected_wf)) throw new Exception(" Input parameter selected_wf is not valid, value " + selected_wf); String job_generator = ""; String port_input_receptor = ""; //input-receptor.pdbqt String port_vina_config = ""; //vina-config.txt String port_input_ligands = ""; //input-ligands.zip String cmd_parameter_wus_nr = "" + docking_wu; // number of WUs String job_collector = ""; String selected_job = ""; String port_docking_gpf = ""; String port_docking_dpf = ""; String port_input_zip = ""; // VINA if (docking_type == DOCKING_VINA) { job_generator = "Generator"; port_input_receptor = "5"; //input-receptor.pdbqt port_vina_config = "4"; //vina-config.txt port_input_ligands = "3"; //input-ligands.zip job_collector = "collector.sh"; selected_job = job_generator; //UPLOAD LIGAND ZIP File uploadedFile = asm_service.uploadFiletoPortalServer(ligandFileItem, userId, ligandFileItem.getName()); asm_service.placeUploadedFile(userId, uploadedFile, selected_wf, selected_job, port_input_ligands); // UPLOAD RECEPTOR PDBQT FILE File receptorFile = asm_service.uploadFiletoPortalServer(receptorFileItem, userId, receptorFileItem.getName()); asm_service.placeUploadedFile(userId, receptorFile, selected_wf, selected_job, port_input_receptor); // SETUP CONFIGURATION if (configFileItem == null) { String content = vina_configuration; asm_service.setInputText(userId, content, selected_wf, selected_job, port_vina_config); } else { File configFile = asm_service.uploadFiletoPortalServer(configFileItem, userId, configFileItem.getName()); asm_service.placeUploadedFile(userId, configFile, selected_wf, selected_job, port_vina_config); } } if (docking_type == DOCKING_AUTODOCKAUTOGRID) { job_generator = "AutoGrid"; port_input_receptor = "0"; //receptor.pdb port_docking_gpf = "1"; String port_exec = "2"; //executables lol //port_vina_config = "2"; port_docking_dpf = "3"; // ligand.pdb port_input_ligands = "4"; // ligand.pdb job_collector = "Collector"; selected_job = job_generator; //UPLOAD LIGAND File uploadedFile = asm_service.uploadFiletoPortalServer(ligandFileItem, userId, ligandFileItem.getName()); asm_service.placeUploadedFile(userId, uploadedFile, selected_wf, selected_job, port_input_ligands); // UPLOAD RECEPTOR PDB FILE File receptorFile = asm_service.uploadFiletoPortalServer(receptorFileItem, userId, receptorFileItem.getName()); asm_service.placeUploadedFile(userId, receptorFile, selected_wf, selected_job, port_input_receptor); // // SHOULD NOT BE IN PUBLIC VERSION! // //UPLOAD EXEC // File execFile = asm_service.uplloadFiletoPortalServer(execFileItem, userId, execFileItem.getName()); // asm_service.placeUploadedFile(userId, execFile , selected_wf, selected_job, port_exec); // UPLOAD GPF FILE File gpfFile = asm_service.uploadFiletoPortalServer(gpfFileItem, userId, gpfFileItem.getName()); asm_service.placeUploadedFile(userId, gpfFile, selected_wf, selected_job, port_docking_gpf); // UPLOAD DPF FILE File dpfFile = asm_service.uploadFiletoPortalServer(dpfFileItem, userId, dpfFileItem.getName()); asm_service.placeUploadedFile(userId, dpfFile, selected_wf, selected_job, port_docking_dpf); } if (docking_type == DOCKING_AUTODOCKNO) { job_generator = "Generator"; port_input_zip = "1"; //inputs.zip port_docking_dpf = "3"; job_collector = "Collector"; selected_job = job_generator; //UPLOAD LIGAND File uploadedFile = asm_service.uploadFiletoPortalServer(inputsFileItem, userId, inputsFileItem.getName()); asm_service.placeUploadedFile(userId, uploadedFile, selected_wf, selected_job, port_input_zip); // UPLOAD GPF FILE File dpfFile = asm_service.uploadFiletoPortalServer(dpfFileItem, userId, dpfFileItem.getName()); asm_service.placeUploadedFile(userId, dpfFile, selected_wf, selected_job, port_docking_dpf); } // setup WUs Number // Generator asm_service.setCommandLineArg(userId, selected_wf, selected_job, cmd_parameter_wus_nr); // setup Best result number // at the collector job argument String best_content = vina_best_result; selected_job = job_collector; asm_service.setCommandLineArg(userId, selected_wf, selected_job, best_content); asm_service.submit(userId, selected_wf, "", ""); throwMessage("Task successfully submitted! Docking_type:" + docking_type + " submitted", 1); userMessage += throwMessage("Task successfully submitted! Wait for run, and check eventually!", 1); response.setRenderParameter("userMessage", userMessage); } catch (Exception ex) { errorMessage += throwError( Thread.currentThread().getStackTrace()[1].getMethodName() + " " + ex.getMessage(), 1); } request.setAttribute("nextJSP", DISPLAY_PAGE); request.setAttribute("selected_wf", selected_wf); request.setAttribute("docking_type", docking_type); response.setRenderParameter("docking_type", "" + docking_type); response.setRenderParameter("errorMessage", errorMessage); }
From source file:fr.ippon.wip.portlet.WIPConfigurationPortlet.java
@Override public void init(PortletConfig config) throws PortletException { super.init(config); String confDirPath = config.getInitParameter("CONF_DIRECTORY_LOCATION"); String deployDirPath = config.getInitParameter("DEPLOY_DIRECTORY_LOCATION"); ConfigurationDAOFactory.INSTANCE.setPortletContext(config.getPortletContext()); ConfigurationDAOFactory.INSTANCE.setConfDirectoryLocation(confDirPath); ConfigurationDAOFactory.INSTANCE.setDeployDirectoryLocation(deployDirPath); configurationDAO = ConfigurationDAOFactory.INSTANCE.getXMLDAOInstance(); File deployFile = new File(ConfigurationDAOFactory.INSTANCE.getDeployDirectoryLocation()); deployPath = deployFile.getAbsolutePath(); DiskFileItemFactory factory = new DiskFileItemFactory(0, deployFile); fileUploadPortlet = new PortletFileUpload(factory); }
From source file:hu.sztaki.lpds.pgportal.portlets.credential.MyProxyPortlet.java
/** * Depending on user's choice calls proper functions for uploading PEM * or SAML file(s)./*from w w w . j a va 2s . c o m*/ * The parameters are filled in by the user on the upload.jsp page. * @param request ActionRequest * @param response ActionResponse */ public synchronized void doUpload(ActionRequest request, ActionResponse response) { response.setRenderParameter("nextJSP", "upload.jsp"); FileItem samlFile = null; FileItem p12File = null; String p12FilePass = null; String host = null; String portS = null; String login = null; String pass = null; String lifetimeS = null; String keyPass = null; boolean RFCEnabled = false; FileItem kf = null, cf = null; boolean useDN = false; Boolean samlUsed = false, p12Used = false, pemUsed = false; try { DiskFileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload pfu = new PortletFileUpload(factory); pfu.setSizeMax(1048576); // Maximum upload size 1Mb Iterator iter = pfu.parseRequest(request).iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) {// retrieve parameters if item is a form field if ("auth".equals(item.getFieldName())) { if ("SAML".equals(item.getString())) { samlUsed = true; } else if ("P12".equals(item.getString())) { p12Used = true; } else if ("PEM".equals(item.getString())) { pemUsed = true; } } else if ("P12".equals(item.getFieldName())) { p12Used = true; } else if ("P12".equals(item.getFieldName())) { pemUsed = true; } else if ("host".equals(item.getFieldName())) { host = item.getString(); } else if ("port".equals(item.getFieldName())) { portS = item.getString(); } else if ("login".equals(item.getFieldName())) { login = item.getString(); } else if ("pass".equals(item.getFieldName())) { pass = item.getString(); } else if ("lifetime".equals(item.getFieldName())) { lifetimeS = item.getString(); } else if ("keyFilePass".equals(item.getFieldName())) { keyPass = item.getString(); } else if ("dnlogin".equals(item.getFieldName())) { useDN = true; } else if ("p12FilePass".equals(item.getFieldName())) { p12FilePass = item.getString(); } else if ("RFCEnabled".equals(item.getFieldName())) { RFCEnabled = true; } } else { if ("samlFile".equals(item.getFieldName())) { samlFile = item; } else if ("p12File".equals(item.getFieldName())) { p12File = item; } if ("keyFile".equals(item.getFieldName())) { kf = item; } else if ("certFile".equals(item.getFieldName())) { cf = item; } } } if (samlUsed) { uploadSaml(request, samlFile, request.getRemoteUser()); } else if (p12Used) { uploadPem(request, p12File, p12FilePass, cf, host, portS, login, pass, lifetimeS, useDN, "p12", RFCEnabled); } else if (pemUsed) { uploadPem(request, kf, keyPass, cf, host, portS, login, pass, lifetimeS, useDN, "pem", RFCEnabled); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ibm.portal.samples.mvc.model.TemplateActions.java
/** * Returns access to the form data APIs/*from w w w. j av a 2 s .c om*/ * * @return the the APIs * @throws IOException */ private final PortletFileUpload getPortletFileUpload() throws IOException { // logging support final String LOG_METHOD = "getPortletFileUpload()"; // access the data stream if (portletFileUpload == null) { // file handling final FileItemFactory itemFactory = new DiskFileItemFactory(); // fetch the stream portletFileUpload = new PortletFileUpload(itemFactory); // log this if (bIsLogging) { LOGGER.logp(LOG_LEVEL, LOG_CLASS, LOG_METHOD, "Accessing the input stream ..."); } } // ok return portletFileUpload; }
From source file:it.infn.ct.chipster.Chipster.java
public String[] uploadChipsterSettings(ActionRequest actionRequest, ActionResponse actionResponse, String username) {/*from w w w .jav a2s .c o m*/ String[] CHIPSTER_Parameters = new String[4]; boolean status; // Check that we have a file upload request boolean isMultipart = PortletFileUpload.isMultipartContent(actionRequest); if (isMultipart) { // Create a factory for disk-based file items. DiskFileItemFactory factory = new DiskFileItemFactory(); // Set factory constrains File CHIPSTER_Repository = new File("/tmp"); if (!CHIPSTER_Repository.exists()) status = CHIPSTER_Repository.mkdirs(); factory.setRepository(CHIPSTER_Repository); // Create a new file upload handler. PortletFileUpload upload = new PortletFileUpload(factory); try { // Parse the request List items = upload.parseRequest(actionRequest); // Processing items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String fieldName = item.getFieldName(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //String timeStamp = dateFormat.format(Calendar.getInstance().getTime()); // Processing a regular form field if (item.isFormField()) { //if (fieldName.equals("chipster_login")) // CHIPSTER_Parameters[0]=item.getString(); if (fieldName.equals("chipster_password1")) CHIPSTER_Parameters[1] = item.getString(); } if (fieldName.equals("EnableNotification")) CHIPSTER_Parameters[2] = item.getString(); if (fieldName.equals("chipster_alias")) CHIPSTER_Parameters[3] = item.getString(); } // end while } catch (FileUploadException ex) { Logger.getLogger(Chipster.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(Chipster.class.getName()).log(Level.SEVERE, null, ex); } } return CHIPSTER_Parameters; }
From source file:it.eng.spago.dispatching.httpchannel.AdapterPortlet.java
/** * Handle multipart form./*from ww w . j a v a2 s. c om*/ * * @param request the request * @param requestContext the request context * * @throws Exception the exception */ private void handleMultipartForm(ActionRequest request, RequestContextIFace requestContext) throws Exception { SourceBean serviceRequest = requestContext.getServiceRequest(); // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler PortletFileUpload upload = new PortletFileUpload(factory); // Parse the request List fileItems = upload.parseRequest(request); Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { String name = item.getFieldName(); String value = item.getString(); serviceRequest.setAttribute(name, value); } else { processFileField(item, requestContext); } } }
From source file:it.infn.ct.mpi_portlet.java
public void getInputForm(ActionRequest request) { if (PortletFileUpload.isMultipartContent(request)) try {/*from w ww . j av a2 s. 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(); logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'"; switch (inputControlsIds.valueOf(fieldName)) { case file_inputFile: inputFileName = item.getString(); processInputFile(item); break; case inputFile: inputFileText = item.getString(); break; case JobIdentifier: jobIdentifier = item.getString(); break; case cpunumber: cpunumber = item.getString(); break; default: _log.info("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'"); } // switch fieldName } // while iter.hasNext() _log.info(LS + "Reporting" + LS + "---------" + LS + logstring); } 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 inputFileName = (String) request.getParameter("file_inputFile"); inputFileText = (String) request.getParameter("inputFile"); jobIdentifier = (String) request.getParameter("JobIdentifier"); cpunumber = (String) request.getParameter("cpunumber"); } // ! isMultipartContent // Show into the log the taken inputs _log.info(LS + "Taken input parameters:" + LS + "inputFileName: '" + inputFileName + "'" + LS + "inputFileText: '" + inputFileText + "'" + LS + "jobIdentifier: '" + jobIdentifier + "'" + LS + "cpunumber: '" + cpunumber + "'"); }