Source code: medi/io/DirectoryScanner.java
1 /*
2 * DirectoryScanner.java
3 *
4 * Created on 22 luglio 2002, 19.57
5 Medi - A media archiver. Archives media files for easy management.
6 Copyright (C) 2002-2003 Antonio Petrelli
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23 */
24
25 package medi.io;
26
27 import java.io.*;
28 import medi.util.VolumeScanningSaver;
29 import javatools.io.FileUtils;
30 import medi.swing.frame.Volume2DbStatus;
31
32 /** It represents a class used to scan directories and to put information about
33 * files and subdirectories in a file.
34 * @author Antonio Petrelli
35 * @version 0.2.0
36 */
37 public class DirectoryScanner extends javatools.io.DirectoryGetter {
38
39 /** Creates new DirectoryScanner */
40 public DirectoryScanner() {
41 }
42
43 /** Creates new DirectoryScanner
44 * @param dirFile The file representing the directory to scan.
45 */
46 public DirectoryScanner(File dirFile) {
47 super(dirFile);
48 }
49
50 /** Creates new DirectoryScanner
51 * @param path The path of the directory to be scanned.
52 */
53 public DirectoryScanner(String path) {
54 super(path);
55 }
56
57 /** Sets the volume scanning saver.
58 * @param pVss The volume scanning saver to use.
59 */
60 public void setVolumeScanningSaver(VolumeScanningSaver pVss) {
61 vss = pVss;
62 }
63
64 /** Returns the used volume scanning saver.
65 * @return The volume scanning saver.
66 */
67 public VolumeScanningSaver getVolumeScanningSaver() {
68 return vss;
69 }
70
71 /** Sets the status frame used to display the status of the process.
72 * @param pStatus The status frame.
73 */
74 public void setStatusFrame(Volume2DbStatus pStatus) {
75 status = pStatus;
76 }
77
78 /** Returns the scanners for subdirectories as an array.
79 * @throws IOException If something goes wrong.
80 * @return The directory-scanners.
81 */
82 public DirectoryScanner[] getSubdirScanners() throws IOException {
83 int i, numDirs;
84 DirectoryScanner[] tempScanners;
85
86 if (subdirList == null)
87 scanDir();
88 numDirs = subdirList.length;
89 tempScanners = new DirectoryScanner[numDirs];
90 for (i=0; i < numDirs; i++)
91 tempScanners[i] = new DirectoryScanner(subdirList[i]);
92 return tempScanners;
93 }
94
95 /** Appends info about the directory (and subdirectories recursively) using the
96 * previously passed volume scanning saver.
97 * @param mountPointLength The length of the mount-point-path-string.
98 * @throws IOException If something goes wrong.
99 */
100 public void appendInfoToSaver(int mountPointLength) throws IOException {
101 int i, numFiles;
102 String tempPath, tempFile;
103 DirectoryScanner[] tempScanners;
104
105 if (fileList == null)
106 scanDir();
107 tempPath = dirRef.getPath().substring(mountPointLength);
108 status.setCurrentDirectory(tempPath);
109 if (tempPath.trim().equals(""))
110 tempPath = "/";
111 vss.addDirectory(tempPath);
112 numFiles = fileList.length;
113 for (i=0; i < numFiles; i++) {
114 tempFile = FileUtils.getFileName(fileList[i]);
115 status.setCurrentFile(tempFile);
116 vss.addFile(tempFile);
117 }
118 tempScanners = getSubdirScanners();
119 numFiles = tempScanners.length;
120 for (i=0; i < numFiles; i++) {
121 tempScanners[i].setVolumeScanningSaver(vss);
122 tempScanners[i].setStatusFrame(status);
123 tempScanners[i].appendInfoToSaver(mountPointLength);
124 }
125 }
126
127 private VolumeScanningSaver vss;
128 private Volume2DbStatus status;
129 }