List of usage examples for org.apache.commons.fileupload FileItem getFieldName
String getFieldName();
From source file:juzu.plugin.upload.FileUploadUnmarshaller.java
@Override public void unmarshall(String mediaType, final ClientContext context, Iterable<Map.Entry<ContextualParameter, Object>> contextualArguments, Map<String, RequestParameter> parameterArguments) throws IOException { org.apache.commons.fileupload.RequestContext ctx = new org.apache.commons.fileupload.RequestContext() { public String getCharacterEncoding() { return context.getCharacterEncoding(); }//from w w w .j ava 2s. c o m public String getContentType() { return context.getContentType(); } public int getContentLength() { return context.getContentLenth(); } public InputStream getInputStream() throws IOException { return context.getInputStream(); } }; // FileUpload upload = new FileUpload(new DiskFileItemFactory()); try { List<FileItem> list = (List<FileItem>) upload.parseRequest(ctx); HashMap<String, FileItem> files = new HashMap<String, FileItem>(); for (FileItem file : list) { String name = file.getFieldName(); if (file.isFormField()) { RequestParameter parameterArg = parameterArguments.get(name); if (parameterArg == null) { parameterArguments.put(name, RequestParameter.create(name, file.getString())); } else { parameterArguments.put(name, parameterArg.append(new String[] { file.getString() })); } } else { files.put(name, file); } } for (Map.Entry<ContextualParameter, Object> argument : contextualArguments) { ContextualParameter contextualParam = argument.getKey(); FileItem file = files.get(contextualParam.getName()); if (file != null && FileItem.class.isAssignableFrom(contextualParam.getType())) { argument.setValue(file); } } } catch (FileUploadException e) { throw new IOException(e); } }
From source file:com.softwarementors.extjs.djn.router.processor.standard.form.upload.UploadFormPostRequestProcessorTest.java
private FileItem mockFileItem(String name, String value) { FileItem fileItem = mock(FileItem.class); when(fileItem.isFormField()).thenReturn(true); when(fileItem.getFieldName()).thenReturn(name); when(fileItem.getString()).thenReturn(value); return fileItem; }
From source file:attila.core.MultipartRequest.java
private void readBinaryParameter(FileItem item) { getBinaryParameters().put(item.getFieldName(), item); }
From source file:br.com.caelum.vraptor.interceptor.multipart.MultipartItemsProcessor.java
public void process() { Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { if (item.isFormField()) { params.put(item.getFieldName(), getValue(item)); continue; }//from w ww. j a va2 s . c o m if (notEmpty(item)) { try { UploadedFile fileInformation = new DefaultUploadedFile(item.getInputStream(), item.getName(), item.getContentType()); parameters.setParameter(item.getFieldName(), item.getName()); request.setAttribute(item.getName(), fileInformation); logger.debug("Uploaded file: {} with {}", item.getFieldName(), fileInformation); } catch (Exception e) { throw new InvalidParameterException("Cant parse uploaded file " + item.getName(), e); } } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } }
From source file:com.cyclopsgroup.waterview.impl.servlet.MultipartServletRequestParameters.java
/** * Constructor for class MultipartServletRequestValueParser * * @param request Http request object/*from w w w.ja va2 s .c om*/ * @param fileUpload File upload object * @throws FileUploadException Throw it out */ public MultipartServletRequestParameters(HttpServletRequest request, FileUploadBase fileUpload) throws FileUploadException { for (Object item : fileUpload.parseRequest(request)) { FileItem fileItem = (FileItem) item; if (fileItem.isFormField()) { add(fileItem.getFieldName(), fileItem.getString()); } else { List<FileItem> list = fileItems.get(fileItem.getFieldName()); if (list == null) { list = new ArrayList<FileItem>(); fileItems.put(fileItem.getFieldName(), list); } list.add(fileItem); } } }
From source file:com.krawler.esp.servlets.deskeramob.java
public static String createProject(Connection conn, HttpServletRequest request, String companyid, String subdomain, String userid) throws ServiceException { String status = ""; DiskFileUpload fu = new DiskFileUpload(); java.util.List fileItems = null; PreparedStatement pstmt = null; String imageName = ""; try {/*www .j a v a2 s . co m*/ fileItems = fu.parseRequest(request); } catch (FileUploadException e) { throw ServiceException.FAILURE("Admin.createProject", e); } java.util.HashMap arrParam = new java.util.HashMap(); java.util.Iterator k = null; for (k = fileItems.iterator(); k.hasNext();) { FileItem fi1 = (FileItem) k.next(); arrParam.put(fi1.getFieldName(), fi1.getString()); } try { pstmt = conn .prepareStatement("select count(projectid) from project where companyid =? AND archived = 0"); pstmt.setString(1, companyid); ResultSet rs = pstmt.executeQuery(); int noProjects = 0; int maxProjects = 0; if (rs.next()) { noProjects = rs.getInt(1); } pstmt = conn.prepareStatement("select maxprojects from company where companyid =?"); pstmt.setString(1, companyid); rs = pstmt.executeQuery(); if (rs.next()) { maxProjects = rs.getInt(1); } if (noProjects == maxProjects) { return "The maximum limit for projects for this company has already reached"; } } catch (SQLException e) { throw ServiceException.FAILURE("ProfileHandler.getPersonalInfo", e); } try { String projectid = UUID.randomUUID().toString(); String projName = StringUtil.serverHTMLStripper(arrParam.get("projectname").toString() .replaceAll("[^\\w|\\s|'|\\-|\\[|\\]|\\(|\\)]", "").trim()); String nickName = AdminServlet.makeNickName(conn, projName, 1); if (StringUtil.isNullOrEmpty(projName)) { status = "failure"; } else { String qry = "INSERT INTO project (projectid,projectname,description,image,companyid, nickname) VALUES (?,?,?,?,?,?)"; pstmt = conn.prepareStatement(qry); pstmt.setString(1, projectid); pstmt.setString(2, projName); pstmt.setString(3, arrParam.get("aboutproject").toString()); pstmt.setString(4, imageName); pstmt.setString(5, companyid); pstmt.setString(6, nickName); int df = pstmt.executeUpdate(); if (df != 0) { pstmt = conn.prepareStatement( "INSERT INTO projectmembers (projectid, userid, status, inuseflag, planpermission) " + "VALUES (?, ?, ?, ?, ?)"); pstmt.setString(1, projectid); pstmt.setString(2, userid); pstmt.setInt(3, 4); pstmt.setBoolean(4, true); pstmt.setInt(5, 0); pstmt.executeUpdate(); } // /DbUtil.executeUpdate(conn,qry,new Object[] { projectid,projName,arrParam.get("aboutproject"), imageName,companyid, nickName}); if (arrParam.get("image").toString().length() != 0) { genericFileUpload uploader = new genericFileUpload(); uploader.doPost(fileItems, projectid, StorageHandler.GetProfileImgStorePath()); if (uploader.isUploaded()) { pstmt = null; // DbUtil.executeUpdate(conn, // "update project set image=? where projectid = ?", // new Object[] { // ProfileImageServlet.ImgBasePath + projectid // + uploader.getExt(), projectid }); pstmt = conn.prepareStatement("update project set image=? where projectid = ?"); pstmt.setString(1, ProfileImageServlet.ImgBasePath + projectid + uploader.getExt()); pstmt.setString(2, projectid); pstmt.executeUpdate(); imageName = projectid + uploader.getExt(); } } com.krawler.esp.handlers.Forum.setStatusProject(conn, userid, projectid, 4, 0, "", subdomain); status = "success"; AdminServlet.setDefaultWorkWeek(conn, projectid); conn.commit(); } } catch (ConfigurationException e) { status = "failure"; throw ServiceException.FAILURE("Admin.createProject", e); } catch (SQLException e) { status = "failure"; throw ServiceException.FAILURE("Admin.createProject", e); } return status; }
From source file:br.com.SGIURD.utils.FileUploadWrapper.java
private boolean alreadyHasValue(FileItem aItem) { return fRegularParams.get(aItem.getFieldName()) != null; }
From source file:controller.editGames.java
private void processFormField(FileItem item) { if (item.getFieldName().equals("RecRam")) { String a = item.getString(); RecRam = Integer.parseInt(a); } else if (item.getFieldName().equals("Code")) { Code = item.getString();/* w ww . ja v a 2 s . c o m*/ } else if (item.getFieldName().equals("MinCpu")) { MinCpu = item.getString(); } else if (item.getFieldName().equals("RecCpu")) { RecCpu = item.getString(); } else if (item.getFieldName().equals("MinGpu")) { MinGpu = item.getString(); } else if (item.getFieldName().equals("RecGpu")) { RecGpu = item.getString(); } else if (item.getFieldName().equals("MinCpuLvl")) { String a = item.getString(); MinCpuLvl = Integer.parseInt(a); } else if (item.getFieldName().equals("RecCpuLvl")) { String a = item.getString(); RecCpuLvl = Integer.parseInt(a); } else if (item.getFieldName().equals("MinGpuLvl")) { String a = item.getString(); MinGpuLvl = Integer.parseInt(a); } else if (item.getFieldName().equals("RecGpuLvl")) { String a = item.getString(); RecGpuLvl = Integer.parseInt(a); } else if (item.getFieldName().equals("MinRam")) { String a = item.getString(); MinRam = Integer.parseInt(a); } }
From source file:com.jyhon.servlet.audit.AuditUserServlet.java
private UserEntity getUserEntity(List<FileItem> items) { UserEntity userEntity = new UserEntity(); for (FileItem item : items) { if (item.isFormField()) { String fileName = item.getFieldName(); if (fileName.equals("name")) { userEntity.setUserName(item.getString()); } else if (fileName.equals("psw")) { userEntity.setPassword(item.getString()); } else if (fileName.equals("userID")) { userEntity.setUserID(Integer.valueOf(item.getString())); } else if (fileName.equals("tel")) { userEntity.setTel(item.getString()); } else if (fileName.equals("idCard")) { userEntity.setIdCard(item.getString()); } else if (fileName.equals("License")) { userEntity.setLicense(item.getString()); } else if (fileName.equals("type")) { userEntity.setStatusId(Integer.valueOf(item.getString())); }/*w w w . ja v a2 s .c om*/ System.out.print(item.getFieldName() + ":"); System.out.println(item.getString()); } else { String pic = item.getFieldName(); userEntity.setLicense(item.getName()); System.out.println(item.getName()); } } return userEntity; }
From source file:com.cyclopsgroup.waterview.servlet.MultipartServletRequestValueParser.java
/** * Constructor for class MultipartServletRequestValueParser * * @param request Http request object//w w w . j ava 2 s. c o m * @param fileUpload File upload object * @throws FileUploadException Throw it out */ public MultipartServletRequestValueParser(HttpServletRequest request, FileUploadBase fileUpload) throws FileUploadException { List files = fileUpload.parseRequest(request); for (Iterator i = files.iterator(); i.hasNext();) { FileItem fileItem = (FileItem) i.next(); if (fileItem.isFormField()) { add(fileItem.getFieldName(), fileItem.getString()); } else { fileItems.put(fileItem.getFieldName(), fileItem); } } }