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 / AbstractFilesystemServerExplorerProvider.java @ 44328
History | View | Annotate | Download (5.27 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl; |
29 |
|
30 |
import java.io.File; |
31 |
import org.apache.commons.io.FilenameUtils; |
32 |
import org.apache.commons.io.IOUtils; |
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
|
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
37 |
import org.gvsig.fmap.dal.DataStore; |
38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
40 |
import org.gvsig.fmap.dal.exception.CreateException; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
43 |
import org.gvsig.fmap.dal.exception.RemoveException; |
44 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
45 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
46 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
47 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
48 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
49 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
50 |
|
51 |
/**
|
52 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
53 |
*/
|
54 |
public abstract class AbstractFilesystemServerExplorerProvider implements FilesystemServerExplorerProvider { |
55 |
|
56 |
@Override
|
57 |
public String getResourceRootPathName(DataStore dataStore) { |
58 |
return this.getResourceRootPathName(dataStore.getParameters()); |
59 |
} |
60 |
|
61 |
public String getResourceRootPathName(DataStoreParameters parameters) { |
62 |
if( parameters instanceof FilesystemStoreParameters ) { |
63 |
File f = ((FilesystemStoreParameters) parameters).getFile();
|
64 |
if( f != null ) { |
65 |
return FilenameUtils.removeExtension(f.getAbsolutePath());
|
66 |
} |
67 |
} |
68 |
if( parameters.hasDynValue(FileResource.NAME) ) {
|
69 |
Object obj = (parameters.getDynValue(FileResource.NAME));
|
70 |
if( obj != null ) { |
71 |
return removeFileExtension(new File(obj.toString())); |
72 |
} |
73 |
} |
74 |
return null; |
75 |
} |
76 |
|
77 |
protected String removeFileExtension(File file) { |
78 |
int whereDot = file.getName().lastIndexOf("."); |
79 |
if( (0 < whereDot) && (whereDot <= file.getName().length() - 2) ) { |
80 |
whereDot = file.getAbsolutePath().lastIndexOf(".");
|
81 |
return file.getAbsolutePath().substring(0, whereDot); |
82 |
} |
83 |
return file.getAbsolutePath();
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public int getMode() { |
88 |
return DataServerExplorer.MODE_ALL;
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public boolean isMode(int mode) { |
93 |
if( mode == DataServerExplorer.MODE_ALL ) {
|
94 |
return true; |
95 |
} |
96 |
return (this.getMode() & mode) != 0; |
97 |
} |
98 |
|
99 |
public DataStoreParameters getParameters(File file) throws DataException { |
100 |
DataManager manager = DALLocator.getDataManager(); |
101 |
DataStoreParameters params = manager.createStoreParameters(this.getDataStoreProviderName());
|
102 |
((FilesystemStoreParameters) params).setFile(file); |
103 |
return params;
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public boolean canCreate() { |
108 |
return false; |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public boolean canCreate(NewDataStoreParameters parameters) { |
113 |
throw new UnsupportedOperationException(); |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
118 |
throws CreateException {
|
119 |
throw new UnsupportedOperationException(); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
124 |
throw new UnsupportedOperationException(); |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
129 |
File file = ((FilesystemStoreParameters) parameters).getFile();
|
130 |
if( !file.exists() ) {
|
131 |
throw new RemoveException(this.getDataStoreProviderName(), |
132 |
new FileNotFoundException(file)); |
133 |
} |
134 |
if( !file.delete() ) {
|
135 |
// FIXME throws ???
|
136 |
} |
137 |
|
138 |
} |
139 |
|
140 |
public boolean closeResourceRequested(ResourceProvider resource) { |
141 |
// while it is using a resource anyone can't close it
|
142 |
return false; |
143 |
} |
144 |
|
145 |
public void resourceChanged(ResourceProvider resource) { |
146 |
//Do nothing
|
147 |
|
148 |
} |
149 |
|
150 |
@Override
|
151 |
public void initialize(FilesystemServerExplorerProviderServices serverExplorer) { |
152 |
|
153 |
} |
154 |
} |