svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / explorer / filesystem / FilesystemExplorer.java @ 24164
History | View | Annotate | Download (4.63 KB)
1 |
package org.gvsig.fmap.data.explorer.filesystem; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileFilter; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.util.ArrayList; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
import java.util.Map; |
10 |
|
11 |
import org.gvsig.fmap.data.DataExplorerParameters; |
12 |
import org.gvsig.fmap.data.DataExplorerType; |
13 |
import org.gvsig.fmap.data.DataStoreParameters; |
14 |
import org.gvsig.fmap.data.exceptions.DataException; |
15 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
16 |
import org.gvsig.fmap.data.exceptions.ReadException; |
17 |
import org.gvsig.fmap.data.spi.DataExplorerProvider; |
18 |
import org.gvsig.tools.extensionPoint.ExtensionPoint; |
19 |
import org.gvsig.tools.extensionPoint.ExtensionPoints; |
20 |
import org.gvsig.tools.extensionPoint.ExtensionPointsSingleton; |
21 |
|
22 |
|
23 |
public class FilesystemExplorer implements DataExplorerProvider { |
24 |
// FIXME: , IPersistence{
|
25 |
|
26 |
public static final String NAME = "FilesystemExplorer"; |
27 |
|
28 |
final private static String FILE_FILTER_EPSNAME = "FilesystemExplorerFilters"; |
29 |
final private static String FILE_FILTER_EPSDESCRIPTION = "Registro de filtros asociados al explorador del sistema de ficheros."; |
30 |
|
31 |
FilesystemExplorerParameters parameters; |
32 |
private File path; |
33 |
|
34 |
public static class FilterWraper { |
35 |
|
36 |
private FileFilter filter; |
37 |
|
38 |
public FilterWraper(FileFilter filter) { |
39 |
this.filter = filter;
|
40 |
} |
41 |
|
42 |
public Object create() { |
43 |
return filter;
|
44 |
} |
45 |
|
46 |
public Object create(Object[] args) { |
47 |
return filter;
|
48 |
} |
49 |
|
50 |
public Object create(Map args) { |
51 |
return filter;
|
52 |
} |
53 |
|
54 |
} |
55 |
|
56 |
public static class FilterWraperIterator implements Iterator { |
57 |
private Iterator it; |
58 |
|
59 |
public FilterWraperIterator(Iterator it) { |
60 |
this.it = it;
|
61 |
} |
62 |
|
63 |
public boolean hasNext() { |
64 |
return this.it.hasNext(); |
65 |
} |
66 |
|
67 |
public Object next() { |
68 |
return ((FilterWraper) this.it.next()).create(); |
69 |
} |
70 |
|
71 |
public void remove() { |
72 |
throw new UnsupportedOperationException(); |
73 |
} |
74 |
|
75 |
} |
76 |
|
77 |
public static void registerFilter(FilesystemFileFilter filter) { |
78 |
ExtensionPoints eps = ExtensionPointsSingleton.getInstance(); |
79 |
ExtensionPoint ep = (ExtensionPoint) eps.get(FILE_FILTER_EPSNAME); |
80 |
if (ep == null) { |
81 |
ep = new ExtensionPoint(FILE_FILTER_EPSNAME,
|
82 |
FILE_FILTER_EPSDESCRIPTION); |
83 |
eps.put(ep); |
84 |
} |
85 |
FilterWraper filterWraper = new FilterWraper(filter);
|
86 |
ep.put(filter.getDataStoreProviderName(), filter.getDescription(),filterWraper); |
87 |
} |
88 |
|
89 |
public static Iterator getFilters() { |
90 |
ExtensionPoints eps = ExtensionPointsSingleton.getInstance(); |
91 |
ExtensionPoint ep = (ExtensionPoint) eps.get(FILE_FILTER_EPSNAME); |
92 |
Iterator it = new FilterWraperIterator(ep.values().iterator()); |
93 |
return it;
|
94 |
} |
95 |
|
96 |
public void init(DataExplorerParameters parameters) |
97 |
throws InitializeException {
|
98 |
this.parameters = (FilesystemExplorerParameters) parameters;
|
99 |
this.path = new File(this.parameters.getPath()); |
100 |
} |
101 |
|
102 |
public DataExplorerType getType() {
|
103 |
return parameters.getType();
|
104 |
} |
105 |
|
106 |
public DataExplorerParameters getParameters() {
|
107 |
return parameters;
|
108 |
} |
109 |
|
110 |
public void dispose() throws DataException { |
111 |
|
112 |
} |
113 |
|
114 |
public List list() throws DataException { |
115 |
if (!this.path.exists()) { |
116 |
//TODO crear excepcion de Data??
|
117 |
new FileNotFoundException(this.getName() + ": Path not found '" |
118 |
+ this.path + "'"); |
119 |
} |
120 |
// DataManager dsm=DataManager.getManager();
|
121 |
|
122 |
String files[] = this.path.list(); |
123 |
int i;
|
124 |
File theFile;
|
125 |
ArrayList fileList = new ArrayList(); |
126 |
DataStoreParameters dsp = null;
|
127 |
|
128 |
for (i = 0; i < files.length; i++) { |
129 |
theFile = new File(this.path, files[i]); |
130 |
if (this.accept(theFile)) { |
131 |
fileList.add(theFile); |
132 |
} |
133 |
|
134 |
} |
135 |
return fileList;
|
136 |
} |
137 |
|
138 |
private boolean accept(File file) { |
139 |
if (!file.exists()) {
|
140 |
return false; |
141 |
} |
142 |
if (!file.isFile()) {
|
143 |
return false; |
144 |
} |
145 |
if (!file.canRead()) {
|
146 |
return false; |
147 |
} |
148 |
if (file.isHidden()) {
|
149 |
return false; |
150 |
} |
151 |
Iterator filters = getFilters();
|
152 |
while (filters.hasNext()) {
|
153 |
FileFilter filter = (FileFilter) filters.next(); |
154 |
if (filter.accept(file)) {
|
155 |
return true; |
156 |
} |
157 |
} |
158 |
return false; |
159 |
} |
160 |
|
161 |
public void remove(DataStoreParameters dsp) throws ReadException { |
162 |
// TODO Auto-generated method stub
|
163 |
|
164 |
} |
165 |
|
166 |
public boolean add(DataStoreParameters ndsp) throws DataException { |
167 |
// TODO Auto-generated method stub
|
168 |
return false; |
169 |
} |
170 |
|
171 |
public boolean canCreate() { |
172 |
return this.path.canWrite(); |
173 |
} |
174 |
|
175 |
public String getName() { |
176 |
// TODO Auto-generated method stub
|
177 |
return null; |
178 |
} |
179 |
|
180 |
public DataStoreParameters getCreationParameters(String storeName) { |
181 |
// TODO Auto-generated method stub
|
182 |
return null; |
183 |
} |
184 |
|
185 |
// ==========================================
|
186 |
|
187 |
|
188 |
} |