1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Copyright (c) 2006 Manuel Traut and Volker Dahnke
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors: Manuel Traut and Volker Dahnke
*/
package YalpServer;
import java.util.ArrayList;
import java.io.File;
import java.io.Serializable;
import YalpInterfaces.*;
/*
* Class FileBrowser
*
* <em>each Admin Client has his own FileBrowser, to browse through the
* subDirectories of the as startDir defined Directory</em>
*
* @author Volker Dahnke / Manuel Traut
*
* @version 0.6 14-12-2005<br>
*
* @see client.GUI.Browser
*/
public class FileBrowser {
private File actualFile, startDir;
private String owner;
private String userName;
private ArrayList<YalpFile> fileList;
/* t.b.d. add some more types */
private String[] extensions = {".mp3",".mpg",".mpeg",".avi"};
/*
* Constructor starts Browsing in startDir
*
* @param startdir
* directory which could be browser recursively
* @param owner
* of the Browser (IP of the Client)
* @param userName
* of the Admin using this browser
*/
public FileBrowser(String startdir, String owner,String userName) {
this.owner = owner;
this.userName=userName;
this.actualFile = new File(startdir);
this.startDir = new File(startdir);
this.fileList = new ArrayList<YalpFile>();
}
/*
* returns owner of the browser
*
* @return String
* owner
*/
public String getOwner(){
return this.owner;
}
/*
* returns user of the browser
*
* @return String
* user
*/
public String getUserName(){
return this.userName;
}
/*
* returns list of all files in actual Folder
* (none recursive)
*
* @return ArrayList<YalpFile>
* list of all files
*/
public ArrayList<YalpFile> getFiles(){
return this.fileList;
}
/*
* returns list of all files in actual Folder
* (recursive)
*
* @return ArrayList<YalpFile>
* list of all files
*/
public ArrayList<File> findAll() {
System.out.println( "server.FileBrowser.findAll: lookin in - " +
this.actualFile.toString() );
FileFinder ff = new FileFinder(actualFile.getPath(), extensions);
return ff.getFiles();
}
/*
* change actual Folder
*
* @param dirName
* String dir to change to
*/
public void changeDir(String dirName) {
this.actualFile = new File(this.startDir+dirName);
this.fileList.clear();
if(actualFile.isDirectory()) {
for ( File aFile : this.actualFile.listFiles() ) {
/* add to fileList if extension is allowed or File is a Directory */
if (match(aFile.getName(), extensions) || aFile.isDirectory())
{
YalpFile tmp = new YalpFile();
tmp.name = aFile.getName();
tmp.isDir = aFile.isDirectory();
tmp.parent = aFile.getParent();
this.fileList.add( tmp );
}
}
}
}
/*
* prints current directory out to console
*
* (for debugging)
*/
public void printActualDir(){
for(YalpFile one : this.fileList){
if(one.isDir) System.out.print("+");
else System.out.print("|");
System.out.println(one.name);
}
}
/*
* checks if file extension matches or not
*
* @param s
* fileName including Extension
* @param suffixes
* Array of allowed Extensions
* @return boolean
* true if yalp can handle this extension, else false
*/
private static boolean match( String s, String suffixes[] ) {
for ( String suffix : suffixes ) {
int huhu = s.length();
int huhu2 = suffix.length();
int huhu3 = huhu - huhu2;
if ( s.length() >= suffix.length() &&
s.substring( huhu3, s.length()).equalsIgnoreCase(suffix) )
return true;
}
return false;
}
}
|