Package org.richfaces.model

Examples of org.richfaces.model.UploadItem


  }
 
  public List<UploadItem> getUploadItems () {
    List <UploadItem> uploadItems = new ArrayList<UploadItem>();
    for (String k : keys) {
      uploadItems.add(new UploadItem(getFileName(k), getFileSize(k), getFileContentType(k), getFile(k)));
    }
    return uploadItems;
  }
View Full Code Here


       
        boolean formUpload = multipartRequest.isFormUpload();
       
        if (isFlash && !formUpload && fileList.size() > 0) {
          try {
            UploadItem item = fileList.get(0);
            int actualSize = item.getFileSize();
            int clientSize = Integer.parseInt(requestParameterMap.get("_richfaces_size"));
           
            if (actualSize != clientSize) {
              return; // File uploading has been stopped on the client side
            }
View Full Code Here

       
        boolean formUpload = multipartRequest.isFormUpload();
       
        if (isFlash && !formUpload && fileList.size() > 0) {
          try {
            UploadItem item = fileList.get(0);
            int actualSize = item.getFileSize();
            int clientSize = Integer.parseInt(requestParameterMap.get("_richfaces_size"));
           
            if (actualSize != clientSize) {
              return; // File uploading has been stopped on the client side
            }
View Full Code Here

     
      boolean formUpload = multipartRequest.isFormUpload();
     
      if (isFlash && !formUpload && fileList.size() > 0) {
        try {
          UploadItem item = fileList.get(0);
          int actualSize = item.getFileSize();
          int clientSize = Integer.parseInt(requestParameterMap.get("_richfaces_size"));
         
          if (actualSize != clientSize) {
            return; // File uploading has been stopped on the client side
          }
View Full Code Here

        HttpServletRequest request = FacesContextUtility.getRequest();
        UploadNewPackageUIBean uploadUIBean = FacesContextUtility.getManagedBean(UploadNewPackageUIBean.class);

        String repoOption = request.getParameter("repoOption");
        UploadItem fileItem = uploadUIBean.getFileItem();
        boolean usingARepo = true;

        // Validate
        if (packageName == null || packageName.trim().equals("")) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Package name must be specified");
            return null;
        }

        if (repoOption == null) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
                "A repository deployment option must be specified");
            return null;
        }

        if (repoOption.equals(REPO_OPTION_NEW) && (newRepoName == null || newRepoName.trim().equals(""))) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
                "When creating a new repo, the name of the repository to be created must be specified");
            return null;
        }

        if ((fileItem == null) || fileItem.getFile() == null) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "A package file must be uploaded");
            return null;
        }

        if (repoOption.equalsIgnoreCase(REPO_OPTION_NONE)) {
            usingARepo = false;
        }

        // Determine which repo the package will go into
        String repoId = null;
        if (usingARepo) {
            if (resource != null) {
                try {
                    repoId = determineRepo(repoOption, subject, resource.getId());
                } catch (ContentException ce) {
                    String errorMessages = ThrowableUtil.getAllMessages(ce);
                    FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
                        "Failed to determine repository. Cause: " + errorMessages);
                    return "failure";
                }
            } else {
                //we're creating a package directly inside a repo. The repo id
                //will be in the request params.
                repoId = FacesContextUtility.getRequiredRequestParameter("id");
            }
        }

        try {
            PackageVersion packageVersion = null;
            try {
                log.debug("Streaming new package bits from uploaded file: " + fileItem.getFile());

                // Grab a stream for the file being uploaded
                InputStream packageStream = new FileInputStream(fileItem.getFile());
                try {
                    // Ask the bean to create the package

                    /* Currently, this is just used in the workflow for deploying a new package. This will probably get
                       refactored in the future for a general way of adding packages to the repo as its own operation. For
                       now, don't worry about that. The rest of this will be written assuming it's part of the deploy
                       workflow and we'll deal with the refactoring later.
                       jdobies, Feb 27, 2008
                     */
                    try {
                        ContentManagerLocal contentManager = LookupUtil.getContentManager();

                        //store information about uploaded file for packageDetails as most of it is already available
                        Map<String, String> packageUploadDetails = new HashMap<String, String>();
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE,
                            String.valueOf(fileItem.getFileSize()));
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
                            String.valueOf(System.currentTimeMillis()));
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER, subject.getName());
                        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME, fileItem.getFileName());

                        String sha = null;
                        String md5 = null;
                        try {//Easier to implement here than in server side bean. Shouldn't affect performance too much.
                            md5 = new MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(fileItem
                                .getFile());
                            sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(fileItem
                                .getFile());
                        } catch (IOException e1) {
                            log.warn("Error calculating file digest(s)", e1);
                        }

View Full Code Here

        if (packageName != null) {
            return packageName;
        }

        UploadNewPackageUIBean uploadUIBean = FacesContextUtility.getManagedBean(UploadNewPackageUIBean.class);
        UploadItem fileItem = uploadUIBean.getFileItem();

        return fileItem == null ? null : fileItem.getFileName();
    }
View Full Code Here

    public String createResource() {
        Subject user = EnterpriseFacesContextUtility.getSubject();

        UploadNewChildPackageUIBean uploadUIBean;
        uploadUIBean = FacesContextUtility.getManagedBean(UploadNewChildPackageUIBean.class);
        UploadItem fileItem = uploadUIBean.getFileItem();

        //store information about uploaded file for packageDetails as most of it is already available
        Map<String, String> packageUploadDetails = new HashMap<String, String>();
        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE, String.valueOf(fileItem.getFileSize()));
        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE, String.valueOf(System
            .currentTimeMillis()));
        packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER, user.getName());
        packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME, fileItem.getFileName());

        try {//Easier to implement here than in server side bean. Shouldn't affect performance too much.
            packageUploadDetails.put(ContentManagerLocal.UPLOAD_MD5, new MessageDigestGenerator(
                MessageDigestGenerator.MD5).calcDigestString(fileItem.getFile()));
            packageUploadDetails.put(ContentManagerLocal.UPLOAD_SHA256, new MessageDigestGenerator(
                MessageDigestGenerator.SHA_256).calcDigestString(fileItem.getFile()));
        } catch (IOException e1) {
            log.warn("Error calculating file digest(s) : " + e1.getMessage());
            e1.printStackTrace();
        }

        // Validate
        if ((fileItem == null) || fileItem.getFile() == null) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "A package file must be uploaded");
            return null;
        }
        if ((getVersion() == null) || (getVersion().trim().length() == 0)) {
            FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "A package version must be specified.");
            return null;
        }

        ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager();
        ConfigurationDefinition pluginConfigurationDefinition = configurationManager
            .getPluginConfigurationDefinitionForResourceType(user, resourceType.getId());

        Configuration pluginConfiguration = null;
        if (pluginConfigurationDefinition != null) {
            pluginConfiguration = pluginConfigurationDefinition.getDefaultTemplate().getConfiguration();
        }

        try {
            try {
                log.debug("Streaming new package bits from uploaded file: " + fileItem.getFile());
                InputStream packageContentStream = new FileInputStream(fileItem.getFile());
                try {
                    if (isSupportsArchitecture()) {
                        // pull in architecture selection
                        selectedArchitectureId = getSelectedArchitectureId();
                    }

                    // Collect data for create call
                    Resource parentResource = EnterpriseFacesContextUtility.getResource();
                    Configuration deployTimeConfiguration = getConfiguration();
                    String packageName = fileItem.getFileName();

                    // some browsers (IE in particular) passes an absolute filename, we just want the name of the file, no paths
                    if (packageName != null) {
                        packageName = packageName.replace('\\', '/');
                        if (packageName.length() > 2 && packageName.charAt(1) == ':') {
View Full Code Here

    }

    public String completeUpload() {
        try {
            if (fileUploader.getFileItem() != null) {
                UploadItem fileItem = fileUploader.getFileItem();
                if (fileItem.isTempFile()) {
                    setCurrentContents(FileUtils.readFileToString(fileItem.getFile()));
                } else {
                    setCurrentContents(new String(fileItem.getData()));
                }
                fileUploader.clear();
            }

            return null;
View Full Code Here

     * file.
     */
    public void completeUpload() {
        try {
            if (uploadBean.getFileItem() != null) {
                UploadItem fileItem = uploadBean.getFileItem();
                if (fileItem.isTempFile()) {
                    selectedRawUIBean.setContents(FileUtils.readFileToString(fileItem.getFile()));
                } else {
                    selectedRawUIBean.setContents(new String(fileItem.getData()));
                }
                uploadBean.clear();
            }
        }
        catch (IOException e) {
View Full Code Here

    stream.write(getFiles().get((Integer)object).getData());
  }

  }
  public void listener(UploadEvent event) throws IOException{
      UploadItem item = event.getUploadItem();
       File file = new File(); // Caution: NOT a java.io.File

       try{

       file.setName(item.getFileName());
       file.setMime(item.getContentType());

       /*Get File Data*/
       if (item.isTempFile()) {

       byte[] fileInBytes = new byte[(int)item.getFile().length()]; //* TODO: Avoid loss of data in casting 'long' to 'int'
       java.io.File tempFile = item.getFile();
       FileInputStream fileInputStream = new FileInputStream(tempFile);
       fileInputStream.read(fileInBytes);
       fileInputStream.close();

       file.setData(fileInBytes); //

       } else {
       file.setData(item.getData());
       System.out.println("STATUS: "+"Not a temp File!");
       }

       file.setLength(file.getData().length);
       System.out.println("FILE LENGTH: "+file.getData().length/1024+"kb");
View Full Code Here

TOP

Related Classes of org.richfaces.model.UploadItem

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.