Package org.dspace.app.webui.util

Examples of org.dspace.app.webui.util.FileUploadRequest


            // if not already wrapped
            if (!Class.forName("org.dspace.app.webui.util.FileUploadRequest")
                    .isInstance(request))
            {
                // Wrap multipart request
                wrappedRequest = new FileUploadRequest(request);

                return (HttpServletRequest) wrappedRequest;
            }
            else
            { // already wrapped
View Full Code Here


     *            current servlet request object
     */
    public void uploadFiles(Context context, HttpServletRequest request)
            throws ServletException
    {
        FileUploadRequest wrapper = null;
        String filePath = null;
        InputStream fileInputStream = null;

        try
        {
            // if we already have a FileUploadRequest, use it
            if (Class.forName("org.dspace.app.webui.util.FileUploadRequest")
                    .isInstance(request))
            {
                wrapper = (FileUploadRequest) request;
            }
            else
            {
                // Wrap multipart request to get the submission info
                wrapper = new FileUploadRequest(request);
            }
           
            log.debug("Did not recoginze resumable upload, falling back to "
                    + "simple upload.");
            Enumeration fileParams = wrapper.getFileParameterNames();
            while (fileParams.hasMoreElements())
            {
                String fileName = (String) fileParams.nextElement();

                File temp = wrapper.getFile(fileName);

                //if file exists and has a size greater than zero
                if (temp != null && temp.length() > 0)
                {
                    // Read the temp file into an inputstream
                    fileInputStream = new BufferedInputStream(
                            new FileInputStream(temp));

                    filePath = wrapper.getFilesystemName(fileName);

                    // cleanup our temp file
                    if (!temp.delete())
                    {
                        log.error("Unable to delete temporary file");
                    }

                    //save this file's info to request (for UploadStep class)
                    request.setAttribute(fileName + "-path", filePath);
                    request.setAttribute(fileName + "-inputstream", fileInputStream);
                    request.setAttribute(fileName + "-description", wrapper.getParameter("description"));
                }
            }
        }
        catch (Exception e)
        {
View Full Code Here

    // return it. If other chunks are missing, we just return null.
    protected File doPostResumable(HttpServletRequest request)
            throws FileSizeLimitExceededException, IOException, ServletException
    {
        File completedFile = null;
        FileUploadRequest wrapper = null;
       
        if (ConfigurationManager.getProperty("upload.temp.dir") != null)
        {
            tempDir = ConfigurationManager.getProperty("upload.temp.dir");
        }
        else {
            tempDir = System.getProperty("java.io.tmpdir");
        }
       
        try
        {
            // if we already have a FileUploadRequest, use it
            if (Class.forName("org.dspace.app.webui.util.FileUploadRequest").isInstance(request))
            {
                wrapper = (FileUploadRequest) request;
            }
            else // if not wrap the mulitpart request to get the submission info
            {
                wrapper = new FileUploadRequest(request);
            }
        }
        catch (ClassNotFoundException ex)
        {
            // Cannot find a class that is part of the JSPUI?
            log.fatal("Cannot find class org.dspace.app.webui.util.FileUploadRequest");
            throw new ServletException("Cannot find class org.dspace.app.webui.util.FileUploadRequest.", ex);
        }

        String resumableIdentifier = wrapper.getParameter("resumableIdentifier");
        long resumableTotalSize = Long.valueOf(wrapper.getParameter("resumableTotalSize"));
        int resumableTotalChunks = Integer.valueOf(wrapper.getParameter("resumableTotalChunks"));

        String chunkDirPath = tempDir + File.separator + resumableIdentifier;
        File chunkDirPathFile = new File(chunkDirPath);
        boolean foundAll = true;
        long currentSize = 0l;
View Full Code Here

            throws ServletException, IOException, SQLException,
            AuthorizeException
    {
        try {
            // Wrap multipart request to get the submission info
            FileUploadRequest wrapper = new FileUploadRequest(request);
            Bitstream b = null;
            Item item = Item.find(context, UIUtil.getIntParameter(wrapper, "item_id"));
            File temp = wrapper.getFile("file");

            // Read the temp file as logo
            InputStream is = new BufferedInputStream(new FileInputStream(temp));

            // now check to see if person can edit item
            checkEditAuthorization(context, item);

            // do we already have an ORIGINAL bundle?
            Bundle[] bundles = item.getBundles("ORIGINAL");

            if (bundles.length < 1)
            {
                // set bundle's name to ORIGINAL
                b = item.createSingleBitstream(is, "ORIGINAL");

                // set the permission as defined in the owning collection
                Collection owningCollection = item.getOwningCollection();
                if (owningCollection != null)
                {
                    Bundle bnd = b.getBundles()[0];
                    bnd.inheritCollectionDefaultPolicies(owningCollection);
                }
            }
            else
            {
                // we have a bundle already, just add bitstream
                b = bundles[0].createBitstream(is);
            }

            // Strip all but the last filename. It would be nice
            // to know which OS the file came from.
            String noPath = wrapper.getFilesystemName("file");

            while (noPath.indexOf('/') > -1)
            {
                noPath = noPath.substring(noPath.indexOf('/') + 1);
            }

            while (noPath.indexOf('\\') > -1)
            {
                noPath = noPath.substring(noPath.indexOf('\\') + 1);
            }

            b.setName(noPath);
            b.setSource(wrapper.getFilesystemName("file"));

            // Identify the format
            BitstreamFormat bf = FormatIdentifier.guessFormat(context, b);
            b.setFormat(bf);
            b.update();
View Full Code Here

            HttpServletResponse response) throws SQLException,
            ServletException, IOException, AuthorizeException
    {
        try {
            // Wrap multipart request to get the submission info
            FileUploadRequest wrapper = new FileUploadRequest(request);
            Collection collection = Collection.find(context, UIUtil.getIntParameter(wrapper, "collection_id"));
            if (collection == null)
            {
                log.warn(LogManager.getHeader(context, "integrity_error", UIUtil.getRequestLogInfo(wrapper)));
                JSPManager.showIntegrityError(request, response);

                return;
            }

            // Get metadata
            collection.setMetadata("name", wrapper.getParameter("name"));
            collection.setMetadata("short_description", wrapper.getParameter("short_description"));
            collection.setMetadata("introductory_text", wrapper.getParameter("introductory_text"));
            collection.setMetadata("copyright_text", wrapper.getParameter("copyright_text"));
            collection.setMetadata("side_bar_text", wrapper.getParameter("side_bar_text"));
            collection.setMetadata("provenance_description", wrapper.getParameter("provenance_description"));
            // Need to be more careful about license -- make sure it's null if
            // nothing was entered
            String license = wrapper.getParameter("license");

            if (!StringUtils.isEmpty(license))
            {
                collection.setLicense(license);
            }

            File temp = wrapper.getFile("file");

            if (temp != null)
            {
                // Read the temp file as logo
                InputStream is = new BufferedInputStream(new FileInputStream(temp));
                Bitstream logoBS = collection.setLogo(is);

                // Strip all but the last filename. It would be nice
                // to know which OS the file came from.
                String noPath = wrapper.getFilesystemName("file");

                while (noPath.indexOf('/') > -1)
                {
                    noPath = noPath.substring(noPath.indexOf('/') + 1);
                }

                while (noPath.indexOf('\\') > -1)
                {
                    noPath = noPath.substring(noPath.indexOf('\\') + 1);
                }

                logoBS.setName(noPath);
                logoBS.setSource(wrapper.getFilesystemName("file"));

                // Identify the format
                BitstreamFormat bf = FormatIdentifier.guessFormat(context, logoBS);
                logoBS.setFormat(bf);
                AuthorizeManager.addPolicy(context, logoBS, Constants.WRITE, context.getCurrentUser());
View Full Code Here

        String message = null;

        // Process the file uploaded
        try {
          // Wrap multipart request to get the submission info
          FileUploadRequest wrapper = new FileUploadRequest(request);

          String inputType = wrapper.getParameter("inputType");
          List<String> reqCollectionsTmp = getRepeatedParameter(wrapper, "collections", "collections");
          String[] reqCollections = new String[reqCollectionsTmp.size()];
          reqCollectionsTmp.toArray(reqCollections);
         
          //Get all collections
            List<Collection> collections = null;
            String colIdS = wrapper.getParameter("colId");
            if (colIdS!=null){
              collections = new ArrayList<Collection>();
              collections.add(Collection.find(context, Integer.parseInt(colIdS)));

            }
            else {
              collections = Arrays.asList(Collection.findAll(context));
            }
            request.setAttribute("collections", collections);
           
           
            Collection owningCollection = null;
          if (wrapper.getParameter("collection") != null) {
            int colId = Integer.parseInt(wrapper.getParameter("collection"));
            if (colId > 0)
              owningCollection = Collection.find(context, colId);
          }
         
            //Get all the possible data loaders from the Spring configuration
            BTEBatchImportService dls  = new DSpace().getSingletonService(BTEBatchImportService.class);
            List<String> inputTypes =dls.getFileDataLoaders();
            request.setAttribute("input-types", inputTypes);
           
            File f = null;
          String zipurl = null;

          if (inputType.equals("saf")){
            zipurl = wrapper.getParameter("zipurl");
            if (StringUtils.isEmpty(zipurl)) {
              request.setAttribute("has-error", "true");
              Locale locale = request.getLocale();
              ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale);
              try {
                message = msgs.getString("jsp.layout.navbar-admin.batchimport.fileurlempty");
              } catch (Exception e) {
                message = "???jsp.layout.navbar-admin.batchimport.fileurlempty???";
              }
             
              request.setAttribute("message", message);

                JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp");

                return;
            }
          }
          else {
            f = wrapper.getFile("file");
            if (f == null) {
              request.setAttribute("has-error", "true");
              Locale locale = request.getLocale();
              ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale);
              try {
                message = msgs.getString("jsp.layout.navbar-admin.batchimport.fileempty");
              } catch (Exception e) {
                message = "???jsp.layout.navbar-admin.batchimport.fileempty???";
              }
             
              request.setAttribute("message", message);

                JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp");

                return;
            }
            else if (owningCollection==null){
              request.setAttribute("has-error", "true");
              Locale locale = request.getLocale();
              ResourceBundle msgs = ResourceBundle.getBundle("Messages", locale);
              try {
                message = msgs.getString("jsp.layout.navbar-admin.batchimport.owningcollectionempty");
              } catch (Exception e) {
                message = "???jsp.layout.navbar-admin.batchimport.owningcollectionempty???";
              }
             
              request.setAttribute("message", message);

                JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp");

                return;
            }
          }

          String uploadId = wrapper.getParameter("uploadId");
          if (uploadId != null){
            request.setAttribute("uploadId", uploadId);
          }

          if (owningCollection==null && reqCollections != null && reqCollections.length > 0){
View Full Code Here

TOP

Related Classes of org.dspace.app.webui.util.FileUploadRequest

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.