svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.lib / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / impl / DefaultFilesystemServerExplorer.java @ 44259
History | View | Annotate | Download (21 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 42775 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40559 | jjdelcerro | *
|
11 | 42775 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40559 | jjdelcerro | *
|
16 | 42775 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40559 | jjdelcerro | *
|
20 | 42775 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40559 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.serverexplorer.filesystem.impl; |
24 | |||
25 | import java.io.File; |
||
26 | 44160 | jjdelcerro | import java.io.FileInputStream; |
27 | import java.io.FileOutputStream; |
||
28 | import java.io.InputStream; |
||
29 | import java.io.OutputStream; |
||
30 | 44189 | jjdelcerro | import java.net.MalformedURLException; |
31 | import java.net.URL; |
||
32 | 40435 | jjdelcerro | import java.util.ArrayList; |
33 | import java.util.HashSet; |
||
34 | import java.util.Iterator; |
||
35 | import java.util.List; |
||
36 | import java.util.Set; |
||
37 | 44189 | jjdelcerro | import java.util.logging.Level; |
38 | import java.util.logging.Logger; |
||
39 | 42879 | jjdelcerro | import org.apache.commons.io.FilenameUtils; |
40 | 44160 | jjdelcerro | import org.apache.commons.io.IOUtils; |
41 | 44189 | jjdelcerro | import org.gvsig.fmap.dal.AbstractDataResource; |
42 | 40435 | jjdelcerro | |
43 | import org.gvsig.fmap.dal.DALFileLocator; |
||
44 | import org.gvsig.fmap.dal.DALLocator; |
||
45 | import org.gvsig.fmap.dal.DataManager; |
||
46 | import org.gvsig.fmap.dal.DataStore; |
||
47 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
48 | import org.gvsig.fmap.dal.NewDataStoreParameters; |
||
49 | import org.gvsig.fmap.dal.exception.DataException; |
||
50 | import org.gvsig.fmap.dal.exception.FileNotFoundException; |
||
51 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
52 | import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
||
53 | import org.gvsig.fmap.dal.exception.RemoveException; |
||
54 | import org.gvsig.fmap.dal.exception.ServerExplorerAddException; |
||
55 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
56 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter; |
||
57 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
58 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
59 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
||
60 | import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
||
61 | 43019 | fdiaz | import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderFactory; |
62 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
63 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
64 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
65 | import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
||
66 | 44253 | jjdelcerro | import org.gvsig.fmap.dal.spi.FileMultiResource; |
67 | 40435 | jjdelcerro | import org.gvsig.tools.exception.BaseException; |
68 | import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
||
69 | |||
70 | 44160 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
71 | 42775 | jjdelcerro | public class DefaultFilesystemServerExplorer extends AbstractDataServerExplorer |
72 | implements FilesystemServerExplorerProviderServices,
|
||
73 | FilesystemFileFilter { |
||
74 | 40435 | jjdelcerro | |
75 | 44189 | jjdelcerro | private class FileResource |
76 | extends AbstractDataResource
|
||
77 | implements DataResource
|
||
78 | { |
||
79 | 44160 | jjdelcerro | |
80 | private final File f; |
||
81 | private FileInputStream in; |
||
82 | private FileOutputStream out; |
||
83 | |||
84 | public FileResource(File f) { |
||
85 | this.f = f;
|
||
86 | } |
||
87 | |||
88 | 44189 | jjdelcerro | public URL getURL() { |
89 | try {
|
||
90 | return this.f.toURI().toURL(); |
||
91 | } catch (MalformedURLException ex) { |
||
92 | return null; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | 44160 | jjdelcerro | public File getFile() { |
97 | return this.f; |
||
98 | } |
||
99 | |||
100 | @Override
|
||
101 | public boolean exists() { |
||
102 | return this.f.exists(); |
||
103 | } |
||
104 | |||
105 | @Override
|
||
106 | public InputStream asInputStream() throws java.io.FileNotFoundException { |
||
107 | if( this.out != null || this.in!=null ) { |
||
108 | throw new IllegalStateException("Input already open"); |
||
109 | } |
||
110 | this.in = new FileInputStream(this.f); |
||
111 | return this.in; |
||
112 | } |
||
113 | |||
114 | @Override
|
||
115 | public OutputStream asOutputStream() throws java.io.FileNotFoundException { |
||
116 | if( this.out != null || this.in!=null ) { |
||
117 | throw new IllegalStateException("Input already open"); |
||
118 | } |
||
119 | this.out = new FileOutputStream(this.f); |
||
120 | return this.out; |
||
121 | } |
||
122 | |||
123 | @Override
|
||
124 | public void close() { |
||
125 | IOUtils.closeQuietly(out); |
||
126 | IOUtils.closeQuietly(in); |
||
127 | this.in = null; |
||
128 | this.out = null; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | 42775 | jjdelcerro | private File root; |
133 | private File current; // Current path |
||
134 | 43055 | jjdelcerro | private List<FilesystemServerExplorerProvider> serverProviders; |
135 | 40435 | jjdelcerro | |
136 | 42775 | jjdelcerro | public DefaultFilesystemServerExplorer(
|
137 | FilesystemServerExplorerParameters parameters, |
||
138 | DataServerExplorerProviderServices services) |
||
139 | throws InitializeException {
|
||
140 | super(parameters, services);
|
||
141 | if (this.getFSParameters().getRoot() != null) { |
||
142 | this.root = new File(this.getFSParameters().getRoot()); |
||
143 | } |
||
144 | if (this.getFSParameters().getInitialpath() != null) { |
||
145 | this.current = new File(this.getFSParameters().getInitialpath()); |
||
146 | } |
||
147 | if (this.root == null && this.current == null) { |
||
148 | // throw new InitializeException(this.getName(),
|
||
149 | // new IllegalArgumentException());
|
||
150 | } else if (this.current == null) { |
||
151 | this.current = new File(this.getFSParameters().getRoot()); |
||
152 | } |
||
153 | } |
||
154 | 40435 | jjdelcerro | |
155 | 42775 | jjdelcerro | private FilesystemServerExplorerParameters getFSParameters() {
|
156 | return (FilesystemServerExplorerParameters) this.getParameters(); |
||
157 | } |
||
158 | 40435 | jjdelcerro | |
159 | 42775 | jjdelcerro | @Override
|
160 | protected void doDispose() throws BaseException { |
||
161 | this.root = null; |
||
162 | super.doDispose();
|
||
163 | } |
||
164 | 40435 | jjdelcerro | |
165 | 42775 | jjdelcerro | @Override
|
166 | public List list(int mode) throws DataException { |
||
167 | if (this.current == null) { |
||
168 | throw new IllegalStateException(); |
||
169 | } |
||
170 | if (!this.current.exists()) { |
||
171 | throw new org.gvsig.fmap.dal.exception.FileNotFoundException(this.current); |
||
172 | } |
||
173 | 40435 | jjdelcerro | |
174 | 42775 | jjdelcerro | if (!this.current.isDirectory()) { |
175 | throw new IllegalArgumentException(this.getProviderName() |
||
176 | + ": Path not a directory '" + this.current + "'"); |
||
177 | } |
||
178 | 40435 | jjdelcerro | |
179 | 42775 | jjdelcerro | List files = new ArrayList(); // return files |
180 | List providers = this.getProviders(mode); |
||
181 | String allfiles[] = this.current.list(); |
||
182 | 40435 | jjdelcerro | |
183 | 44160 | jjdelcerro | for (String f : allfiles) { |
184 | File file = new File(this.root, f); |
||
185 | 42775 | jjdelcerro | Iterator providersit = providers.iterator();
|
186 | while (providersit.hasNext()) {
|
||
187 | FilesystemServerExplorerProvider provider = (FilesystemServerExplorerProvider) providersit |
||
188 | .next(); |
||
189 | if (provider.accept(file)) {
|
||
190 | DataStoreParameters dsp = this.createStoreParameters(file);
|
||
191 | if (dsp != null) { |
||
192 | files.add(dsp); |
||
193 | } |
||
194 | break;
|
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | return files;
|
||
199 | } |
||
200 | 40435 | jjdelcerro | |
201 | 42775 | jjdelcerro | public List list() throws DataException { |
202 | if (this.current == null) { |
||
203 | throw new IllegalStateException(); // FIXME |
||
204 | } |
||
205 | if (!this.current.exists()) { |
||
206 | 44160 | jjdelcerro | throw new FileNotFoundException(this.current); |
207 | 42775 | jjdelcerro | } |
208 | 40435 | jjdelcerro | |
209 | 42775 | jjdelcerro | if (!this.current.isDirectory()) { |
210 | 44160 | jjdelcerro | throw new IllegalArgumentException(this.getProviderName() |
211 | 42775 | jjdelcerro | + ": Path not a directory '" + this.current + "'"); |
212 | } |
||
213 | 40435 | jjdelcerro | |
214 | 42775 | jjdelcerro | String files[] = this.current.list(); |
215 | int i;
|
||
216 | File theFile;
|
||
217 | ArrayList list = new ArrayList(); |
||
218 | 44160 | jjdelcerro | DataStoreParameters dsp; |
219 | 40435 | jjdelcerro | |
220 | 42775 | jjdelcerro | for (i = 0; i < files.length; i++) { |
221 | theFile = new File(this.root, files[i]); |
||
222 | dsp = this.createStoreParameters(theFile);
|
||
223 | if (dsp != null) { |
||
224 | list.add(dsp); |
||
225 | } |
||
226 | } |
||
227 | return list;
|
||
228 | } |
||
229 | 40435 | jjdelcerro | |
230 | 42775 | jjdelcerro | public void setCurrentPath(File path) throws FileNotFoundException { |
231 | // FIXME Comprobar si es un directorio existente
|
||
232 | if (!path.exists()) {
|
||
233 | throw new FileNotFoundException(path); |
||
234 | } |
||
235 | if (!path.isDirectory()) {
|
||
236 | throw new IllegalArgumentException(path.getPath() |
||
237 | + " is not a directory");
|
||
238 | } |
||
239 | if (!isFromRoot(path)) {
|
||
240 | throw new IllegalArgumentException(path.getPath() |
||
241 | + " is not from root");
|
||
242 | 40435 | jjdelcerro | |
243 | 42775 | jjdelcerro | } |
244 | 40435 | jjdelcerro | |
245 | 42775 | jjdelcerro | this.current = path;
|
246 | } |
||
247 | 40435 | jjdelcerro | |
248 | 42775 | jjdelcerro | public File getCurrentPath() { |
249 | return this.current; |
||
250 | } |
||
251 | 40435 | jjdelcerro | |
252 | 42775 | jjdelcerro | public File getRoot() { |
253 | return this.root; |
||
254 | } |
||
255 | 40435 | jjdelcerro | |
256 | 42775 | jjdelcerro | public void remove(DataStoreParameters dsp) throws RemoveException { |
257 | String providerName = dsp.getDataStoreName();
|
||
258 | try {
|
||
259 | this.checkIsMine(dsp);
|
||
260 | FilesystemServerExplorerProvider provider = this
|
||
261 | .getProvider(providerName); |
||
262 | 40435 | jjdelcerro | |
263 | 42775 | jjdelcerro | provider.remove(dsp); |
264 | } catch (DataException e) {
|
||
265 | throw new RemoveException(this.getProviderName(), e); |
||
266 | } |
||
267 | } |
||
268 | 40435 | jjdelcerro | |
269 | 42775 | jjdelcerro | public boolean add(String providerName, NewDataStoreParameters ndsp, |
270 | boolean overwrite) throws DataException { |
||
271 | 40435 | jjdelcerro | |
272 | 42775 | jjdelcerro | try {
|
273 | this.checkIsMine(ndsp);
|
||
274 | FilesystemServerExplorerProvider provider = this
|
||
275 | .getProvider(providerName); |
||
276 | 40435 | jjdelcerro | |
277 | 42775 | jjdelcerro | ndsp.validate(); |
278 | provider.create(ndsp, overwrite); |
||
279 | return true; |
||
280 | 44160 | jjdelcerro | } catch (DataException | ValidateDataParametersException e) {
|
281 | 42775 | jjdelcerro | throw new ServerExplorerAddException(this.getProviderName(), e); |
282 | } |
||
283 | } |
||
284 | 40435 | jjdelcerro | |
285 | 42775 | jjdelcerro | public boolean canAdd() { |
286 | return this.root.canWrite(); |
||
287 | } |
||
288 | 40435 | jjdelcerro | |
289 | 42775 | jjdelcerro | public String getProviderName() { |
290 | return FilesystemServerExplorer.NAME;
|
||
291 | } |
||
292 | 40435 | jjdelcerro | |
293 | 42775 | jjdelcerro | public NewDataStoreParameters getAddParameters(String storeName) |
294 | throws DataException {
|
||
295 | FilesystemServerExplorerProvider provider = this.getProvider(storeName);
|
||
296 | if (provider == null) { |
||
297 | throw new IllegalArgumentException( |
||
298 | "Not registered in this explorer"); // FIXME |
||
299 | } |
||
300 | 40435 | jjdelcerro | |
301 | 42775 | jjdelcerro | NewDataStoreParameters nParams = provider.getCreateParameters(); |
302 | // nParams.setAttribute("path", this.getCurrentPath().getPath());
|
||
303 | return nParams;
|
||
304 | } |
||
305 | 40435 | jjdelcerro | |
306 | 42775 | jjdelcerro | public boolean canAdd(String storeName) throws DataException { |
307 | if (storeName == null) { |
||
308 | return false;// CanAdd with genericFilter |
||
309 | } |
||
310 | FilesystemServerExplorerProvider provider = this.getProvider(storeName);
|
||
311 | if (provider == null) { |
||
312 | throw new IllegalArgumentException( |
||
313 | "Not registered in this explorer"); // FIXME |
||
314 | } |
||
315 | 40435 | jjdelcerro | |
316 | 42775 | jjdelcerro | return provider.canCreate();
|
317 | 40435 | jjdelcerro | |
318 | 42775 | jjdelcerro | } |
319 | 40435 | jjdelcerro | |
320 | 42775 | jjdelcerro | // ==========================================
|
321 | private FilesystemServerExplorerProvider getProvider(String storeName) |
||
322 | throws InitializeException, ProviderNotRegisteredException {
|
||
323 | Iterator providers = getProviders(FilesystemServerExplorer.MODE_ALL).iterator();
|
||
324 | FilesystemServerExplorerProvider provider; |
||
325 | while (providers.hasNext()) {
|
||
326 | provider = (FilesystemServerExplorerProvider) providers.next(); |
||
327 | if (provider.getDataStoreProviderName().equals(storeName)) {
|
||
328 | return provider;
|
||
329 | } |
||
330 | } |
||
331 | return null; |
||
332 | } |
||
333 | 40435 | jjdelcerro | |
334 | 42775 | jjdelcerro | private DataManagerProviderServices getManager() {
|
335 | return (DataManagerProviderServices) DALLocator.getDataManager();
|
||
336 | } |
||
337 | 40435 | jjdelcerro | |
338 | 42775 | jjdelcerro | public DataStoreParameters createStoreParameters(File file, String providerName) throws DataException { |
339 | 40435 | jjdelcerro | |
340 | 42775 | jjdelcerro | return this.getParametersFor(file, providerName, true); |
341 | } |
||
342 | 40435 | jjdelcerro | |
343 | 42775 | jjdelcerro | public DataStoreParameters createStoreParameters(File file) throws DataException { |
344 | 40435 | jjdelcerro | |
345 | 42775 | jjdelcerro | return this.getParametersFor(file, null, true); |
346 | } |
||
347 | 40435 | jjdelcerro | |
348 | 42775 | jjdelcerro | public DataStoreParameters getParametersFor(File file, String providerName, boolean checksExist) throws DataException { |
349 | 40435 | jjdelcerro | |
350 | 42775 | jjdelcerro | if (checksExist) {
|
351 | if (!file.exists()) {
|
||
352 | return null; |
||
353 | } |
||
354 | if (!file.isFile()) {
|
||
355 | return null; |
||
356 | } |
||
357 | if (!file.canRead()) {
|
||
358 | return null; |
||
359 | } |
||
360 | if (file.isHidden()) { // XXX ??? |
||
361 | return null; |
||
362 | } |
||
363 | } |
||
364 | if (providerName == null) { |
||
365 | providerName = this.getProviderName(file);
|
||
366 | } |
||
367 | if (providerName != null) { |
||
368 | DataStoreParameters params = this.getManager()
|
||
369 | .createStoreParameters(providerName); |
||
370 | ((FilesystemStoreParameters) params).setFile(file); |
||
371 | return params;
|
||
372 | 40435 | jjdelcerro | |
373 | 42775 | jjdelcerro | } |
374 | return null; |
||
375 | } |
||
376 | 40435 | jjdelcerro | |
377 | 43055 | jjdelcerro | public List<String> getProviderNameList(File file) { |
378 | 42775 | jjdelcerro | Iterator filters = getFilters();
|
379 | List list = new ArrayList(); |
||
380 | while (filters.hasNext()) {
|
||
381 | FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
||
382 | if (filter.accept(file)) {
|
||
383 | list.add(filter.getDataStoreProviderName()); |
||
384 | } |
||
385 | } |
||
386 | return list;
|
||
387 | } |
||
388 | 40435 | jjdelcerro | |
389 | 43757 | jjdelcerro | @Override
|
390 | 42775 | jjdelcerro | public String getProviderName(File file) { |
391 | Iterator filters = getFilters();
|
||
392 | while (filters.hasNext()) {
|
||
393 | FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
||
394 | if (filter.accept(file)) {
|
||
395 | return filter.getDataStoreProviderName();
|
||
396 | } |
||
397 | } |
||
398 | return null; |
||
399 | } |
||
400 | 40435 | jjdelcerro | |
401 | 42775 | jjdelcerro | public List getDataStoreProviderNames() { |
402 | Set names = new HashSet(); |
||
403 | 40435 | jjdelcerro | |
404 | 42775 | jjdelcerro | Iterator filters = getFilters();
|
405 | while (filters.hasNext()) {
|
||
406 | FilesystemFileFilter filter = (FilesystemFileFilter) filters.next(); |
||
407 | names.add(filter.getDataStoreProviderName()); |
||
408 | } |
||
409 | return new ArrayList(names); |
||
410 | } |
||
411 | 40435 | jjdelcerro | |
412 | 42775 | jjdelcerro | private void checkIsMine(DataStoreParameters dsp) |
413 | throws IllegalArgumentException, DataException { |
||
414 | if (!(dsp instanceof FilesystemStoreParameters)) { |
||
415 | 44160 | jjdelcerro | throw new IllegalArgumentException("not instance of FilesystemStoreParameters"); |
416 | 42775 | jjdelcerro | } |
417 | Iterator filters = getFilters();
|
||
418 | File file = ((FilesystemStoreParameters) dsp).getFile();
|
||
419 | if (!this.isFromRoot(file)) { |
||
420 | throw new IllegalArgumentException("worng explorer"); |
||
421 | } |
||
422 | FilesystemFileFilter filter; |
||
423 | while (filters.hasNext()) {
|
||
424 | filter = (FilesystemFileFilter) filters.next(); |
||
425 | if (dsp.getDataStoreName()
|
||
426 | .equals(filter.getDataStoreProviderName())) { |
||
427 | return;
|
||
428 | } |
||
429 | } |
||
430 | throw new IllegalArgumentException("worng explorer"); |
||
431 | } |
||
432 | 40435 | jjdelcerro | |
433 | 42775 | jjdelcerro | private boolean isFromRoot(File file) { |
434 | if (this.root == null) { |
||
435 | return true; |
||
436 | } |
||
437 | return file.getAbsolutePath().startsWith(this.root.getAbsolutePath()); |
||
438 | } |
||
439 | 40435 | jjdelcerro | |
440 | 43055 | jjdelcerro | public List<FilesystemServerExplorerProvider> getProviders() { |
441 | 42775 | jjdelcerro | if (this.serverProviders == null) { |
442 | Iterator iter = DALFileLocator.getFilesystemServerExplorerManager()
|
||
443 | .getRegisteredProviders(); |
||
444 | this.serverProviders = new ArrayList(); |
||
445 | Extension ext; |
||
446 | FilesystemServerExplorerProvider provider; |
||
447 | 43019 | fdiaz | FilesystemServerExplorerProviderFactory factory; |
448 | 42775 | jjdelcerro | while (iter.hasNext()) {
|
449 | ext = (Extension) iter.next(); |
||
450 | try {
|
||
451 | 43019 | fdiaz | factory = (FilesystemServerExplorerProviderFactory) ext.create(); |
452 | 42775 | jjdelcerro | } catch (Exception e) { |
453 | throw new RuntimeException(e);// FIXME !!! |
||
454 | } |
||
455 | 43019 | fdiaz | try {
|
456 | provider=factory.createProvider(); |
||
457 | } catch (InitializeException e) {
|
||
458 | throw new RuntimeException(e);// FIXME !!! |
||
459 | } |
||
460 | 42775 | jjdelcerro | provider.initialize(this);
|
461 | this.serverProviders.add(provider);
|
||
462 | } |
||
463 | } |
||
464 | return this.serverProviders; |
||
465 | } |
||
466 | 40435 | jjdelcerro | |
467 | 42775 | jjdelcerro | public List getProviders(int mode) { |
468 | 43019 | fdiaz | List<FilesystemServerExplorerProvider> providers = new ArrayList(); |
469 | List<FilesystemServerExplorerProvider> allProviders = getProviders();
|
||
470 | for (FilesystemServerExplorerProvider provider:allProviders){
|
||
471 | 42775 | jjdelcerro | if (provider.isMode(mode)) {
|
472 | provider.initialize(this);
|
||
473 | providers.add(provider); |
||
474 | } |
||
475 | } |
||
476 | return providers;
|
||
477 | } |
||
478 | 40435 | jjdelcerro | |
479 | 42775 | jjdelcerro | public Iterator getFilters(int mode) { |
480 | return this.getProviders(mode).iterator(); |
||
481 | } |
||
482 | 40435 | jjdelcerro | |
483 | 43055 | jjdelcerro | public Iterator<FilesystemServerExplorerProvider> getFilters() { |
484 | 42775 | jjdelcerro | return this.getProviders().iterator(); |
485 | } |
||
486 | 40435 | jjdelcerro | |
487 | 42775 | jjdelcerro | public FilesystemFileFilter getFilter(int mode, final String description) { |
488 | 40435 | jjdelcerro | |
489 | 42775 | jjdelcerro | final List filters = new ArrayList(); |
490 | Iterator it = this.getFilters(mode); |
||
491 | while (it.hasNext()) {
|
||
492 | filters.add(it.next()); |
||
493 | } |
||
494 | FilesystemFileFilter filter = new FilesystemFileFilter() {
|
||
495 | 40435 | jjdelcerro | |
496 | 42775 | jjdelcerro | public boolean accept(File f) { |
497 | if (f.isDirectory()) {
|
||
498 | return true; |
||
499 | } |
||
500 | for (int i = 0; i < filters.size(); i++) { |
||
501 | if (((FilesystemFileFilter) filters.get(i)).accept(f)) {
|
||
502 | return true; |
||
503 | } |
||
504 | } |
||
505 | return false; |
||
506 | } |
||
507 | 40435 | jjdelcerro | |
508 | 42775 | jjdelcerro | public String getDescription() { |
509 | return description;
|
||
510 | } |
||
511 | 40435 | jjdelcerro | |
512 | 42775 | jjdelcerro | public String getDataStoreProviderName() { |
513 | return null; |
||
514 | } |
||
515 | }; |
||
516 | return filter;
|
||
517 | } |
||
518 | 40435 | jjdelcerro | |
519 | 42775 | jjdelcerro | public FilesystemFileFilter getGenericFilter() {
|
520 | // FIXME: Este metodo, getGenericFilter, no tengo claro que deba existir (jjdc)
|
||
521 | return this; |
||
522 | } |
||
523 | |||
524 | public String getDataStoreProviderName() { |
||
525 | return null; |
||
526 | } |
||
527 | |||
528 | public String getDescription() { |
||
529 | return "All supporteds"; |
||
530 | } |
||
531 | |||
532 | public boolean accept(File pathname) { |
||
533 | try {
|
||
534 | return this.createStoreParameters(pathname) != null; |
||
535 | } catch (DataException e) {
|
||
536 | throw new RuntimeException(e); // FIXME excpetion?? |
||
537 | } |
||
538 | } |
||
539 | |||
540 | public DataStore open(File file) throws DataException, |
||
541 | ValidateDataParametersException { |
||
542 | DataManager manager = DALLocator.getDataManager(); |
||
543 | String providerName = this.getProviderName(file); |
||
544 | |||
545 | 40435 | jjdelcerro | DataStoreParameters params = this.getAddParameters(file);
|
546 | 42775 | jjdelcerro | return manager.openStore(providerName, params);
|
547 | } |
||
548 | 40435 | jjdelcerro | |
549 | 42775 | jjdelcerro | public NewDataStoreParameters getAddParameters(File file) |
550 | throws DataException {
|
||
551 | DataStoreParameters params = this.getParametersFor(file, null, false); |
||
552 | NewDataStoreParameters newParams = this.getAddParameters(params
|
||
553 | .getDataStoreName()); |
||
554 | ((FilesystemStoreParameters) newParams) |
||
555 | .setFile(((FilesystemStoreParameters) params).getFile()); |
||
556 | return newParams;
|
||
557 | } |
||
558 | 40435 | jjdelcerro | |
559 | 44160 | jjdelcerro | @Deprecated
|
560 | 42879 | jjdelcerro | @Override
|
561 | 42775 | jjdelcerro | public File getResourcePath(DataStore dataStore, String resourceName) throws DataException { |
562 | 44160 | jjdelcerro | FileResource resource = (FileResource) this.getResource(dataStore, resourceName);
|
563 | if( resource==null ) { |
||
564 | return null; |
||
565 | } |
||
566 | return resource.getFile();
|
||
567 | } |
||
568 | |||
569 | @Override
|
||
570 | public DataResource getResource(DataStore dataStore, String resourceName) throws DataException { |
||
571 | FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName());
|
||
572 | 42775 | jjdelcerro | if (provider == null) { |
573 | return null; |
||
574 | } |
||
575 | 42879 | jjdelcerro | String rootPathName = provider.getResourceRootPathName(dataStore);
|
576 | if (rootPathName == null) { |
||
577 | 42775 | jjdelcerro | return null; |
578 | } |
||
579 | 44259 | jjdelcerro | if( !dataStore.getChildren().isEmpty() ) {
|
580 | 44253 | jjdelcerro | FileMultiResource res = new FileMultiResource(
|
581 | new File(rootPathName), |
||
582 | dataStore.getName(), |
||
583 | resourceName |
||
584 | ); |
||
585 | return res;
|
||
586 | } |
||
587 | 42903 | jjdelcerro | File f = new File(FilenameUtils.getFullPathNoEndSeparator(rootPathName),resourceName); |
588 | 42879 | jjdelcerro | if( f.exists() ) {
|
589 | 44160 | jjdelcerro | return new FileResource(f); |
590 | 42879 | jjdelcerro | } |
591 | 44160 | jjdelcerro | return new FileResource(new File(rootPathName + "." + resourceName)); |
592 | 42775 | jjdelcerro | } |
593 | 44160 | jjdelcerro | |
594 | 42775 | jjdelcerro | @Override
|
595 | public DataStoreParameters get(String name) throws DataException { |
||
596 | File theFile = new File(this.current,name); |
||
597 | DataStoreParameters dsp = this.createStoreParameters(theFile);
|
||
598 | return dsp;
|
||
599 | } |
||
600 | 40435 | jjdelcerro | } |