001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.util; 013 014import java.io.File; 015import java.util.ArrayList; 016import java.util.Collection; 017import java.util.List; 018 019import org.nuxeo.ecm.automation.CleanupHandler; 020 021/** 022 * Cleanup Handler that takes a list of files and remove them after the operation chain was executed. 023 * 024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 025 */ 026public class FileCleanupHandler implements CleanupHandler { 027 028 protected List<File> files; 029 030 public FileCleanupHandler() { 031 files = new ArrayList<File>(); 032 } 033 034 public FileCleanupHandler(File file) { 035 this(); 036 files.add(file); 037 } 038 039 public FileCleanupHandler(Collection<File> files) { 040 this(); 041 this.files.addAll(files); 042 } 043 044 @Override 045 public void cleanup() { 046 for (File file : files) { 047 file.delete(); 048 } 049 } 050 051}