Statistics
| Revision:

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 @ 44259

History | View | Annotate | Download (5.11 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.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34

    
35
import org.gvsig.fmap.dal.DataServerExplorer;
36
import org.gvsig.fmap.dal.DataStore;
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;
43
import org.gvsig.fmap.dal.resource.file.FileResource;
44
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
46
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
47
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
48

    
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
51
 */
52
public abstract class AbstractFilesystemServerExplorerProvider implements FilesystemServerExplorerProvider {
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());
61
            }
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()));
67
            }
68
        }
69
        return null;
70
    }
71

    
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
    }
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
        }    
149
}