001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.webapp.filemanager; 023 024import java.io.File; 025import java.io.InputStream; 026import java.io.Serializable; 027import java.util.ArrayList; 028import java.util.Collection; 029 030import org.jboss.seam.ScopeType; 031import org.jboss.seam.annotations.Name; 032import org.jboss.seam.annotations.Observer; 033import org.jboss.seam.annotations.Scope; 034import org.jboss.seam.annotations.intercept.BypassInterceptors; 035import org.nuxeo.ecm.webapp.helpers.EventNames; 036 037/** 038 * Holds FileUpload data at PAGE scope level, useful for {@link FileManageActions}. 039 */ 040@Name("fileUploadHolder") 041@Scope(ScopeType.PAGE) 042public class UploadItemHolder implements Serializable { 043 044 private static final long serialVersionUID = 1L; 045 046 protected Collection<NxUploadedFile> uploadedFiles = new ArrayList<NxUploadedFile>(); 047 048 protected InputStream fileUpload; 049 050 protected File tempFile; 051 052 protected String fileName; 053 054 public File getTempFile() { 055 return tempFile; 056 } 057 058 public void setTempFile(File tempFile) { 059 this.tempFile = tempFile; 060 } 061 062 public String getFileName() { 063 return fileName; 064 } 065 066 public void setFileName(String fileName) { 067 this.fileName = fileName; 068 } 069 070 public Collection<NxUploadedFile> getUploadedFiles() { 071 return uploadedFiles; 072 } 073 074 public void setUploadedFiles(Collection<NxUploadedFile> uploadedFiles) { 075 this.uploadedFiles = uploadedFiles; 076 } 077 078 public InputStream getFileUpload() { 079 return fileUpload; 080 } 081 082 public void setFileUpload(InputStream fileUpload) { 083 this.fileUpload = fileUpload; 084 } 085 086 @Observer(value = { EventNames.DOCUMENT_SELECTION_CHANGED, EventNames.DOCUMENT_CHANGED }, create = false) 087 @BypassInterceptors 088 public void reset() { 089 uploadedFiles = new ArrayList<NxUploadedFile>(); 090 fileUpload = null; 091 fileName = null; 092 if (tempFile != null) { 093 tempFile.delete(); 094 } 095 tempFile = null; 096 } 097 098}