Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItem


            ServletFileUpload upload = new ServletFileUpload(factory);
            upload.setSizeMax(-1);
            upload.setHeaderEncoding("UTF8");
            try {
                for (Iterator it = upload.parseRequest(request).iterator(); it.hasNext();) {
                    FileItem fi = (FileItem) it.next();
                    if (!fi.isFormField()) {
                        if (fi.getName() != null && fi.getName().length() > 0) {
                            tmpWar = new File(System.getProperty("java.io.tmpdir"), FilenameUtils.getName(fi.getName()));
                            fi.write(tmpWar);
                        }
                    } else if ("context".equals(fi.getFieldName())) {
                        contextName = fi.getString();
                    } else if ("update".equals(fi.getFieldName()) && "yes".equals(fi.getString())) {
                        update = true;
                    } else if ("compile".equals(fi.getFieldName()) && "yes".equals(fi.getString())) {
                        compile = true;
                    } else if ("discard".equals(fi.getFieldName()) && "yes".equals(fi.getString())) {
                        discard = true;
                    }
                }
            } catch (Exception e) {
                logger.fatal("Could not process file upload", e);
View Full Code Here


  {
    if(!ServletFileUpload.isMultipartContent(request))
      return;

    // 1. Parsing the form fields...
    FileItem item = null;
    String comment = null;
    FileItem imageFileFormField = null;
    try
    {
      FileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
      List<?> items = upload.parseRequest(request);
View Full Code Here

        SshSession session = new SshSession( request );
        String connectionInfo = "";
        String channelId = "";
        String fileName = "";
        FileItem file = null;
        String redirectPage = PAGE_HOME;

        try
        {
            // Parse the parts into Parameters and the file.
            List files = upload.parseRequest( request );
            Iterator iter = files.iterator();
            while (iter.hasNext())
            {
                FileItem fileItem = (FileItem) iter.next();
                String fieldName;
                if( fileItem.isFormField() )
                {
                    fieldName = fileItem.getFieldName();
                    if( PARAMETER_CONNECTION.equals( fieldName ) )
                    {
                        connectionInfo = fileItem.getString();
                    }
                    else if( PARAMETER_CHANNEL.equals( fieldName ) )
                    {
                        channelId = fileItem.getString();

                    }
                    else if( PARAMETER_FILENAME.equals( fieldName ) )
                    {
                        fileName = fileItem.getString();
                    }
                }
                else
                {
                    file = fileItem;
View Full Code Here

        Map<String,List<String>> tmpParams = new HashMap<String,List<String>>();
        Map<String,List<MultipartFile>> tmpFiles = new HashMap<String,List<MultipartFile>>();
       
        List<?> items = upload.parseRequest(request);
        for(Object itemObject: items){
            FileItem item = (FileItem)itemObject;
            if (item.isFormField()){
                List<String> list1 = tmpParams.get(item.getFieldName());
                if (list1 == null){
                    list1 = new ArrayList<String>();
                    tmpParams.put(item.getFieldName(), list1);
                }
                try{
                    String encoding = request.getCharacterEncoding();
                    String value1 = encoding == null ? item.getString() : item.getString(encoding);
                    list1.add(value1);
                }
                catch(UnsupportedEncodingException e){
                    throw new FileUploadException(e.getMessage());
                }
            }
            else{
                List<MultipartFile> list2 = tmpFiles.get(item.getFieldName());
                if (list2 == null){
                    list2 = new ArrayList<MultipartFile>();
                    tmpFiles.put(item.getFieldName(), list2);
                }
                list2.add(new MultipartFile(item));
            }
        }
       
View Full Code Here

  }

    public void doPost( HttpServletRequest req, HttpServletResponse res ){

      File disk = null;
      FileItem item = null;
      FileItemFactory factory = new DiskFileItemFactory();
      Iterator iter = null;
      List items = null;
      ServletFileUpload upload = new ServletFileUpload( factory );
      ServletOutputStream out = null;
      try{
        items = upload.parseRequest( req );
        iter = items.iterator();
        res.setContentType( " text/xml");
        out = res.getOutputStream();
        out.println( " <response> " );
        while( iter.hasNext() ){
          item = ( FileItem )iter.next();
          if( item.isFormField() ){
            out.println( "<field name=\"" + item.getFieldName() + "\"value=\"" + item.getString() + "\" />"  );
          }
          else{
            String wsdlLocationParam = req.getParameter("wsdlLocation");
            //System.out.println("$$$$$$$$$$$$$$$$$$$$$$___________req.getParameter(wsdlLocation) : "+wsdlLocationParam);
            wsdlLocationParam = wsdlLocationParam.replace('\\', File.separatorChar);
            //System.out.println("$$$$$$$$$$$$$$$$$___________req.getParameter(wsdlLocation) : "+wsdlLocationParam);
            String path = getServletContext().getRealPath("/")+wsdlLocationParam;
            path = path.replace('\\', File.separatorChar);
            //System.out.println("$$$$$$$$$$$$$$$$$path : "+path);
            disk = new File( path, item.getName() );
            item.write( disk );
            out.println( "<file name=\"" + item.getName() + "\" size=\""+ item.getSize()+" path=\"" + getInitParameter("uploadPath") + "\" />"  );

          }

        }
View Full Code Here

      (OutputData) request.getAttribute(StandardServletServiceAdapterComponent.OUTPUT_DATA_REQUEST_ATTRIBUTE);
    ServletFileUploadOutputExtension fileUpload =
      (ServletFileUploadOutputExtension) output.narrow(ServletFileUploadOutputExtension.class);   
   
    if (fileUpload.getUploadedFile(controlName)!= null) {
      FileItem file = fileUpload.getUploadedFile(controlName);
      String mimeType = file.getContentType();

      if (permittedMimeFileTypes == null || permittedMimeFileTypes.contains(mimeType)) {

        innerData = new FileInfo(file);
      }
View Full Code Here

      List /* FileItem */items = upload.parseRequest(request);

      // Process the uploaded items
      Iterator iter = items.iterator();
      while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        if (!item.isFormField()) {
          fileItems.put(item.getFieldName(), item);
        }
        else {
          List parameterValues = (List) parameterLists.get(item.getFieldName());
         
          if (parameterValues == null) {
            parameterValues = new ArrayList();   
            parameterLists.put(item.getFieldName(), parameterValues);
          }
         
          parameterValues.add(item.getString());
        }
      }
     
      output.extend(
          ServletFileUploadOutputExtension.class,
View Full Code Here

            if (fileList != null)
            {
                for (Iterator it = fileList.iterator(); it.hasNext();)
                {
                    FileItem fi = (FileItem) it.next();
                    if (fi.isFormField())
                    {
                        log.debug("Found an simple form field: " + fi.getFieldName() +", adding value " + fi.getString());

                        String value = null;
                        try
                        {
                            value = fi.getString(params.getCharacterEncoding());
                        }
                        catch (UnsupportedEncodingException e)
                        {
                            log.error(params.getCharacterEncoding()
                                    + " encoding is not supported."
                                    + "Used the default when reading form data.");
                            value = fi.getString();
                        }
                        params.add(fi.getFieldName(), value);
                    }
                    else
                    {
                        log.debug("Found an uploaded file: " + fi.getFieldName());
                        log.debug("It has " + fi.getSize() + " Bytes and is " + (fi.isInMemory() ? "" : "not ") + "in Memory");
                        log.debug("Adding FileItem as " + fi.getFieldName() + " to the params");
                        params.add(fi.getFieldName(), fi);
                    }
                }
            }
        }
        catch (FileUploadException e)
View Full Code Here

        ParameterParser pp = new DefaultParameterParser();
        DefaultFileItemFactory factory = new DefaultFileItemFactory(10240, null);

        assertEquals("keySet() is not empty!", 0, pp.keySet().size());

        FileItem test = factory.createItem("upload-field", "application/octet-stream", false, null);
        pp.add("upload-field", test);

        assertEquals("FileItem not found in keySet()!", 1, pp.keySet().size());

        Iterator it = pp.keySet().iterator();
View Full Code Here

    public void testToString()
    {
        ParameterParser pp = new DefaultParameterParser();
        DefaultFileItemFactory factory = new DefaultFileItemFactory(10240, null);

        FileItem test = factory.createItem("upload-field", "application/octet-stream", false, null);
        pp.add("upload-field", test);

        assertTrue(pp.toString().startsWith("{upload-field=[org.apache.commons.fileupload.DefaultFileItem"));
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.FileItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.