2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package de.todesbaum.jsite.gui;
23 import java.io.FileFilter;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
29 import de.todesbaum.jsite.application.Project;
30 import de.todesbaum.jsite.i18n.I18n;
32 public class FileScanner implements Runnable {
34 private final List<FileScannerListener> fileScannerListeners = new ArrayList<FileScannerListener>();
35 private final Project project;
36 private List<String> files;
37 private boolean error = false;
39 public FileScanner(Project project) {
40 this.project = project;
43 public void addFileScannerListener(FileScannerListener fileScannerListener) {
44 fileScannerListeners.add(fileScannerListener);
47 public void removeFileScannerListener(FileScannerListener fileScannerListener) {
48 fileScannerListeners.remove(fileScannerListener);
51 protected void fireFileScannerFinished() {
52 for (FileScannerListener fileScannerListener: new ArrayList<FileScannerListener>(fileScannerListeners)) {
53 fileScannerListener.fileScannerFinished(this);
58 files = new ArrayList<String>();
61 scanFiles(new File(project.getLocalPath()), files);
62 Collections.sort(files);
63 } catch (IOException ioe1) {
66 fireFileScannerFinished();
69 public boolean isError() {
73 public List<String> getFiles() {
77 private void scanFiles(File rootDir, List<String> fileList) throws IOException {
78 File[] files = rootDir.listFiles(new FileFilter() {
80 public boolean accept(File file) {
81 return !file.isHidden();
85 throw new IOException(I18n.getMessage("jsite.file-scanner.can-not-read-directory"));
87 for (File file: files) {
88 if (file.isDirectory()) {
89 scanFiles(file, fileList);
92 String filename = project.shortenFilename(file);
93 filename = filename.replace('\\', '/');
94 fileList.add(filename);