Revision 43400 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
AbstractFilesystemServerExplorerProvider.java | ||
---|---|---|
25 | 25 |
* AUTHORS (In addition to CIT): |
26 | 26 |
* 2010 {Prodevelop} {Task} |
27 | 27 |
*/ |
28 |
|
|
29 | 28 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl; |
30 | 29 |
|
31 | 30 |
import java.io.File; |
32 | 31 |
import org.apache.commons.io.FilenameUtils; |
32 |
import org.gvsig.fmap.dal.DALLocator; |
|
33 |
import org.gvsig.fmap.dal.DataManager; |
|
33 | 34 |
|
34 | 35 |
import org.gvsig.fmap.dal.DataServerExplorer; |
35 | 36 |
import org.gvsig.fmap.dal.DataStore; |
36 | 37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
39 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
40 |
import org.gvsig.fmap.dal.exception.DataException; |
|
41 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
|
42 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
37 | 43 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
44 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
38 | 45 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
39 | 46 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
47 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
40 | 48 |
|
41 | 49 |
/** |
42 | 50 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
43 | 51 |
*/ |
44 | 52 |
public abstract class AbstractFilesystemServerExplorerProvider implements FilesystemServerExplorerProvider { |
45 | 53 |
|
46 |
@Override |
|
47 |
public String getResourceRootPathName(DataStore dataStore) { |
|
48 |
DataStoreParameters parameters = dataStore.getParameters(); |
|
49 |
if (parameters instanceof FilesystemStoreParameters) { |
|
50 |
File f = ((FilesystemStoreParameters) parameters).getFile(); |
|
51 |
if (f != null) { |
|
52 |
return FilenameUtils.removeExtension(f.getAbsolutePath()); |
|
53 |
} |
|
54 |
@Override |
|
55 |
public String getResourceRootPathName(DataStore dataStore) { |
|
56 |
DataStoreParameters parameters = dataStore.getParameters(); |
|
57 |
if( parameters instanceof FilesystemStoreParameters ) { |
|
58 |
File f = ((FilesystemStoreParameters) parameters).getFile(); |
|
59 |
if( f != null ) { |
|
60 |
return FilenameUtils.removeExtension(f.getAbsolutePath()); |
|
54 | 61 |
} |
55 |
if (dataStore.getParameters().hasDynValue(FileResource.NAME)) {
|
|
56 |
Object obj = (dataStore.getParameters().getDynValue(FileResource.NAME));
|
|
57 |
if (obj != null) {
|
|
58 |
return removeFileExtension(new File(obj.toString()));
|
|
59 |
}
|
|
62 |
}
|
|
63 |
if( dataStore.getParameters().hasDynValue(FileResource.NAME) ) {
|
|
64 |
Object obj = (dataStore.getParameters().getDynValue(FileResource.NAME));
|
|
65 |
if( obj != null ) {
|
|
66 |
return removeFileExtension(new File(obj.toString()));
|
|
60 | 67 |
} |
61 |
return null; |
|
62 | 68 |
} |
69 |
return null; |
|
70 |
} |
|
63 | 71 |
|
64 |
protected String removeFileExtension(File file){ |
|
65 |
int whereDot = file.getName().lastIndexOf("."); |
|
66 |
if ((0 < whereDot) && (whereDot <= file.getName().length() - 2)) { |
|
67 |
whereDot = file.getAbsolutePath().lastIndexOf("."); |
|
68 |
return file.getAbsolutePath().substring(0, whereDot); |
|
69 |
} |
|
70 |
return file.getAbsolutePath(); |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public int getMode() { |
|
75 |
return DataServerExplorer.MODE_ALL; |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public boolean isMode(int mode) { |
|
80 |
if( mode == DataServerExplorer.MODE_ALL ) { |
|
81 |
return true; |
|
82 |
} |
|
83 |
return (this.getMode() & mode) != 0; |
|
84 |
} |
|
72 |
protected String removeFileExtension(File file) { |
|
73 |
int whereDot = file.getName().lastIndexOf("."); |
|
74 |
if( (0 < whereDot) && (whereDot <= file.getName().length() - 2) ) { |
|
75 |
whereDot = file.getAbsolutePath().lastIndexOf("."); |
|
76 |
return file.getAbsolutePath().substring(0, whereDot); |
|
77 |
} |
|
78 |
return file.getAbsolutePath(); |
|
79 |
} |
|
85 | 80 |
|
81 |
@Override |
|
82 |
public int getMode() { |
|
83 |
return DataServerExplorer.MODE_ALL; |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public boolean isMode(int mode) { |
|
88 |
if( mode == DataServerExplorer.MODE_ALL ) { |
|
89 |
return true; |
|
90 |
} |
|
91 |
return (this.getMode() & mode) != 0; |
|
92 |
} |
|
93 |
|
|
94 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
95 |
DataManager manager = DALLocator.getDataManager(); |
|
96 |
DataStoreParameters params = manager.createStoreParameters(this.getDataStoreProviderName()); |
|
97 |
((FilesystemStoreParameters) params).setFile(file); |
|
98 |
return params; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public boolean canCreate() { |
|
103 |
return false; |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
108 |
throw new UnsupportedOperationException(); |
|
109 |
} |
|
110 |
|
|
111 |
@Override |
|
112 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
113 |
throws CreateException { |
|
114 |
throw new UnsupportedOperationException(); |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
119 |
throw new UnsupportedOperationException(); |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
124 |
File file = ((FilesystemStoreParameters) parameters).getFile(); |
|
125 |
if( !file.exists() ) { |
|
126 |
throw new RemoveException(this.getDataStoreProviderName(), |
|
127 |
new FileNotFoundException(file)); |
|
128 |
} |
|
129 |
if( !file.delete() ) { |
|
130 |
// FIXME throws ??? |
|
131 |
} |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
136 |
// while it is using a resource anyone can't close it |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
public void resourceChanged(ResourceProvider resource) { |
|
141 |
//Do nothing |
|
142 |
|
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public void initialize(FilesystemServerExplorerProviderServices serverExplorer) { |
|
147 |
|
|
148 |
} |
|
86 | 149 |
} |
87 |
|
Also available in: Unified diff