001/*
002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webapp.filemanager;
021
022import java.io.File;
023import java.io.InputStream;
024import java.io.Serializable;
025import java.util.ArrayList;
026import java.util.Collection;
027
028import org.jboss.seam.ScopeType;
029import org.jboss.seam.annotations.Name;
030import org.jboss.seam.annotations.Observer;
031import org.jboss.seam.annotations.Scope;
032import org.jboss.seam.annotations.intercept.BypassInterceptors;
033import org.nuxeo.ecm.webapp.helpers.EventNames;
034
035/**
036 * Holds FileUpload data at PAGE scope level, useful for {@link FileManageActions}.
037 */
038@Name("fileUploadHolder")
039@Scope(ScopeType.PAGE)
040public class UploadItemHolder implements Serializable {
041
042    private static final long serialVersionUID = 1L;
043
044    protected Collection<NxUploadedFile> uploadedFiles = new ArrayList<NxUploadedFile>();
045
046    protected InputStream fileUpload;
047
048    protected File tempFile;
049
050    protected String fileName;
051
052    public File getTempFile() {
053        return tempFile;
054    }
055
056    public void setTempFile(File tempFile) {
057        this.tempFile = tempFile;
058    }
059
060    public String getFileName() {
061        return fileName;
062    }
063
064    public void setFileName(String fileName) {
065        this.fileName = fileName;
066    }
067
068    public Collection<NxUploadedFile> getUploadedFiles() {
069        return uploadedFiles;
070    }
071
072    public void setUploadedFiles(Collection<NxUploadedFile> uploadedFiles) {
073        this.uploadedFiles = uploadedFiles;
074    }
075
076    public InputStream getFileUpload() {
077        return fileUpload;
078    }
079
080    public void setFileUpload(InputStream fileUpload) {
081        this.fileUpload = fileUpload;
082    }
083
084    @Observer(value = { EventNames.DOCUMENT_SELECTION_CHANGED, EventNames.DOCUMENT_CHANGED }, create = false)
085    @BypassInterceptors
086    public void reset() {
087        uploadedFiles = new ArrayList<NxUploadedFile>();
088        fileUpload = null;
089        fileName = null;
090        if (tempFile != null) {
091            tempFile.delete();
092        }
093        tempFile = null;
094    }
095
096}