Package org.openfaces.event

Examples of org.openfaces.event.FileUploadItem


            if (allUploaded) {
                List<FileUploadItem> filesItems = new LinkedList<FileUploadItem>();
                for (int i = 0; i < files.length(); i++) {
                    JSONArray file = files.getJSONArray(i);
                    if (file.getString(3).equals("SUCCESSFUL")) {
                        FileUploadItem fileUploadItem = (FileUploadItem) sessionMap.get(file.getString(0));
                        filesItems.add(fileUploadItem);
                        sessionMap.remove(file.getString(0));

                        JSONArray jsonArray = new JSONArray();
                        jsonArray.put(file.getString(4));
                        jsonArray.put(fileUploadItem.getFile().length());
                        fileSizes.put(jsonArray);

                    } else if (file.getString(3).equals("STOPPED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.STOPPED));
                        sessionMap.remove(PROGRESS_ID + file.getString(1));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    } else if (file.getString(3).equals("FAILED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.FAILED));
                        sessionMap.remove(PROGRESS_ID + file.getString(1));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    } else if (file.getString(3).equals("SIZE_LIMIT_EXCEEDED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.SIZE_LIMIT_EXCEEDED));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    }
                }
                AbstractFileUpload fileUpload = (AbstractFileUpload) component;
                MethodExpression completionListener = fileUpload.getCompletionListener();
View Full Code Here


    private void uploadIfExistFiles(FacesContext context, AbstractFileUpload fileUpload) {
        ExternalContext extContext = context.getExternalContext();
        String clientId = fileUpload.getClientId(context);
        try {
            HttpServletRequest request = (HttpServletRequest) extContext.getRequest();
            FileUploadItem uploadedFile = (FileUploadItem) request.getAttribute(clientId + DIV_FOR_INPUTS_ID + INPUT_OF_FILE_ID);
            if (uploadedFile == null) {
                return;
            }
            String id = (String) request.getAttribute("FILE_ID");
            request.getSession().setAttribute(id, uploadedFile);
View Full Code Here

    public List<FileUploadItem> getUploadedFiles() {
        return uploadedFiles;
    }

    public String getFileSize() {
        FileUploadItem fileUploadItem = Faces.var("fileUploadItem", FileUploadItem.class);
        String result = getFileSizeStr(fileUploadItem);
        return result;
    }
View Full Code Here

    }

    public void bookImageUploaded(UploadCompletionEvent uploadCompletionEvent) {
        Book book = Faces.var("book", Book.class);
        List<FileUploadItem> files = uploadCompletionEvent.getFiles();
        FileUploadItem fileUploadItem = files.get(0);
        book.setUploadedCoverImage(fileUploadItem);
        deleteFiles(files);
    }
View Full Code Here

        deleteFiles(files);
    }

    public String getBookImageFileSize() {
        Book book = Faces.var("book", Book.class);
        FileUploadItem uploadedCoverImage = book.getUploadedCoverImage();
        if (uploadedCoverImage == null) return "N/A";
        FileUploadStatus status = uploadedCoverImage.getStatus();
        switch (status) {
            case SUCCESSFUL:
                return String.valueOf(book.getBookCoverImage().getFileSize());
            case STOPPED:
                return "<Upload stopped>";
View Full Code Here

        }
    }

    public String getBookImageFileName() {
        Book book = Faces.var("book", Book.class);
        FileUploadItem uploadedCoverImage = book.getUploadedCoverImage();
        if (uploadedCoverImage == null) return "N/A";
        return uploadedCoverImage.getFileName();
    }
View Full Code Here

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public void fileUploaded(UploadCompletionEvent event) {
        FileUploadItem item = event.getFiles().get(0);

        fileName = item.getFileName();
        if (item.getFile() != null) {
            fileSize = String.valueOf(item.getFile().length());
            item.getFile().delete();
        } else
            fileSize = item.getStatus().toString();

    }
View Full Code Here

                        if (request.getSession().getAttribute(uniqueFileId + AbstractFileUploadRenderer.TERMINATED_TEXT) == null) {
                            String correctFileName = getCorrectFileName(fileItem.getName());
                            File f = writeFile(fileItem, tempDirPath, correctFileName);
                            int index = fileItem.getFieldName().indexOf(FIELD_NAME);
                            String genericNameForFile = fileItem.getFieldName().substring(0, index + FIELD_NAME.length());
                            request.setAttribute(genericNameForFile, new FileUploadItem(correctFileName, f, FileUploadStatus.SUCCESSFUL));
                            request.setAttribute("FILE_ID", uniqueFileId);
                        } else {
                            request.getSession().removeAttribute(uniqueFileId + AbstractFileUploadRenderer.TERMINATED_TEXT);
                        }
                    } else {
View Full Code Here

TOP

Related Classes of org.openfaces.event.FileUploadItem

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.