Examples of FileItem


Examples of org.apache.commons.fileupload.FileItem

            PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory());
            try {
                List items = uploader.parseRequest(actionRequest);
                for (Iterator i = items.iterator(); i.hasNext();) {
                    FileItem item = (FileItem) i.next();
                    if (!item.isFormField()) {
                        String fieldName = item.getFieldName().trim();
                        name = item.getName().trim();

                        if (name.length() == 0) {
                            file = null;
                        } else {
                            // IE sends full path while Firefox sends just basename
                            // in the case of "FullName" we may be able to infer the group
                            // Note, we can't use File.separatorChar because the file separator
                            // is dependent upon the client and not the server.
                            String fileChar = "\\";
                            int fileNameIndex = name.lastIndexOf(fileChar);
                            if (fileNameIndex == -1) {
                                fileChar = "/";
                                fileNameIndex = name.lastIndexOf(fileChar);
                            }
                            if (fileNameIndex != -1) {
                                basename = name.substring(fileNameIndex + 1);
                            } else {
                                basename = name;
                            }

                            // Create the temporary file to be used for import to the server
                            file = File.createTempFile("geronimo-import", "");
                            file.deleteOnExit();
                            log.debug("Writing repository import file to " + file.getAbsolutePath());
                        }

                        if ("local".equals(fieldName)) {
                            uploadFile = file;
                        }

                        if (file != null) {
                            try {
                                item.write(file);
                            } catch (Exception e) {
                                throw new PortletException(e);
                            }
                        }
                        // This is not the file itself, but one of the form fields for the URI
                    } else {
                        String fieldName = item.getFieldName().trim();
                        if ("group".equals(fieldName)) {
                            group = item.getString().trim();
                        } else if ("artifact".equals(fieldName)) {
                            artifact = item.getString().trim();
                        } else if ("version".equals(fieldName)) {
                            version = item.getString().trim();
                        } else if ("fileType".equals(fieldName)) {
                            fileType = item.getString().trim();
                        }
                    }
                }

View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

            this.log.error("parseMultiPartPost: Error parsing request", fue);
        }

        if (items != null && items.size() > 0) {
            for (Iterator<?> ii = items.iterator(); ii.hasNext();) {
                FileItem fileItem = (FileItem) ii.next();
                RequestParameter pp = new MultipartRequestParameter(fileItem);
                parameters.addParameter(pp, false);
            }
        }
    }
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

            if (items.size() != 1) {
                logAndWriteError("Found " + items.size() + " items to process, but only updating 1 bundle is supported", resp);
                return;
            }

            FileItem item = items.get(0);

            JarInputStream jar = null;
            InputStream rawInput = null;
            try {
                jar = new JarInputStream(item.getInputStream());
                Manifest manifest = jar.getManifest();
                if (manifest == null) {
                    logAndWriteError("Uploaded jar file does not contain a manifest", resp);
                    return;
                }

                final String symbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
                if (symbolicName == null) {
                    logAndWriteError("Manifest does not have a " + Constants.BUNDLE_SYMBOLICNAME, resp);
                    return;
                }

                // the JarInputStream is used only for validation, we need a fresh input stream for updating
                rawInput = item.getInputStream();

                Bundle found = getBundle(symbolicName);
                try {
                    installOrUpdateBundle(found, rawInput, null);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

        try {
            List /* FileItem */items = upload.parseRequest(req);

            Iterator iter = items.iterator();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();

                if (!item.isFormField()) {
                    bundleStream = item.getInputStream();
                    bundleLocation = item.getName();
                } else {
                    noRedirect |= "_noredir_".equals(item.getFieldName());
                }
            }

            if (bundleStream != null && bundleLocation != null) {
                try {
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

            try
            {
                List items = upload.parseRequest( request );
                for ( Iterator fiter = items.iterator(); fiter.hasNext(); )
                {
                    FileItem fi = ( FileItem ) fiter.next();
                    FileItem[] current = ( FileItem[] ) params.get( fi.getFieldName() );
                    if ( current == null )
                    {
                        current = new FileItem[]
                            { fi };
                    }
                    else
                    {
                        FileItem[] newCurrent = new FileItem[current.length + 1];
                        System.arraycopy( current, 0, newCurrent, 0, current.length );
                        newCurrent[current.length] = fi;
                        current = newCurrent;
                    }
                    params.put( fi.getFieldName(), current );
                }
            }
            catch ( FileUploadException fue )
            {
                // TODO: log
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

        if (ACTION_DEPLOY.equals(action))
        {
            Map params = (Map) req.getAttribute(AbstractWebConsolePlugin.ATTR_FILEUPLOAD);
            if (params != null)
            {
                final FileItem pck = getFileItem(params, PARAMETER_PCK_FILE, false);
                final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
                if (admin != null)
                {
                    try
                    {
                        admin.installDeploymentPackage(pck.getInputStream());

                        final String uri = req.getRequestURI();
                        resp.sendRedirect(uri);
                        return;
                    }
                    catch ( /*Deployment*/Exception e)
                    {
                        throw new ServletException("Unable to deploy package.", e);
                    }
                }
            }
            throw new ServletException("Upload file or deployment admin missing.");
        }
        else if (ACTION_UNINSTALL.equals(action))
        {
            final String pckId = req.getPathInfo().substring(
                req.getPathInfo().lastIndexOf('/') + 1);
            if (pckId != null && pckId.length() > 0)
            {
                final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
                if (admin != null)
                {
                    try
                    {
                        final DeploymentPackage pck = admin.getDeploymentPackage(pckId);
                        if (pck != null)
                        {
                            pck.uninstall();
                        }
                    }
                    catch ( /*Deployment*/Exception e)
                    {
                        throw new ServletException("Unable to undeploy package.", e);
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

        if ( params == null )
        {
            return;
        }

        final FileItem startItem = getParameter( params, FIELD_START );
        final FileItem startLevelItem = getParameter( params, FIELD_STARTLEVEL );
        final FileItem[] bundleItems = getFileItems( params, FIELD_BUNDLEFILE );
        final FileItem refreshPackagesItem = getParameter( params, FIELD_REFRESH_PACKAGES );

        // don't care any more if no bundle item
        if ( bundleItems.length == 0 )
        {
            return;
        }

        // default values
        // it exists
        int startLevel = -1;
        String bundleLocation = "inputstream:";

        // convert the start level value
        if ( startLevelItem != null )
        {
            try
            {
                startLevel = Integer.parseInt( startLevelItem.getString() );
            }
            catch ( NumberFormatException nfe )
            {
                log( LogService.LOG_INFO, "Cannot parse start level parameter " + startLevelItem
                    + " to a number, not setting start level" );
            }
        }

        for ( int i = 0; i < bundleItems.length; i++ )
        {
            final FileItem bundleItem = bundleItems[i];
            // write the bundle data to a temporary file to ease processing
            File tmpFile = null;
            try
            {
                // copy the data to a file for better processing
                tmpFile = File.createTempFile( "install", ".tmp" );
                bundleItem.write( tmpFile );
            }
            catch ( Exception e )
            {
                log( LogService.LOG_ERROR, "Problem accessing uploaded bundle file: " + bundleItem.getName(), e );

                // remove the tmporary file
                if ( tmpFile != null )
                {
                    tmpFile.delete();
                    tmpFile = null;
                }
            }

            // install or update the bundle now
            if ( tmpFile != null )
            {
                // start, refreshPackages just needs to exist, don't care for value
                final boolean start = startItem != null;
                final boolean refreshPackages = refreshPackagesItem != null;

                bundleLocation = "inputstream:" + bundleItem.getName();
                installBundle( bundleLocation, tmpFile, startLevel, start, refreshPackages );
            }
        }
    }
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

            // Parse the request
            List<FileItem> items = upload.parseRequest(request);
            Iterator<FileItem> iter = items.iterator();
            IVResource userDirectory = user.getResource(path);
            while (iter.hasNext()) {
                FileItem item = iter.next();

                if (!item.isFormField()) {
                    String fileName = item.getName();
                    InputStream is = new BufferedInputStream(item.getInputStream());;
                    OutputStream os = null;
                    byte[] buffer = new byte[8192];

                try {
                      if(explodeZip && ("application/zip".equals(item.getContentType()) || fileName.endsWith(".zip"))){
              ZipInputStream zis = new ZipInputStream(is);
              ZipEntry entry;
                int bytesIn;
              is = zis;
           
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

    // Parse the request
    List items = upload.parseRequest(req);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        // If its a form field, put it in our parameter map
        if (item.isFormField()) {
          MultiMapSolrParams.addParam(
            item.getFieldName(),
            item.getString(), params.getMap() );
        }
        // Add the stream
        else {
            System.out.println(item.getFieldName()+"==="+item.getSize());
          streams.add( new FileItemContentStream( item ) );
        }
    }
    return params;
  }
View Full Code Here

Examples of org.apache.commons.fileupload.FileItem

        prod.setProductId("myfish");
        prod.setDescription("My fish");
        prod.setName("my fish");

        FileItem fi = createMock(FileItem.class);
        expect(fi.getName()).andReturn("c:\\test\\pic.gif");
        expect(fi.getInputStream()).andAnswer(new IAnswer<InputStream>() {
            public InputStream answer() throws Throwable {
                return new FileInputStream(srcfile);
            }
        });
        replay(fi);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.