Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.png / src / main / java / org / gvsig / fmap / dal / file / png / PngFileSystemServerProvider.java @ 43803

History | View | Annotate | Download (3.97 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.file.png;
24

    
25
import java.io.File;
26
import java.io.IOException;
27

    
28
import org.apache.commons.io.FilenameUtils;
29

    
30
import org.gvsig.fmap.dal.DataServerExplorer;
31
import org.gvsig.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.NewDataStoreParameters;
33
import org.gvsig.fmap.dal.exception.CreateException;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.exception.FileNotFoundException;
36
import org.gvsig.fmap.dal.exception.RemoveException;
37
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
38
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
39
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
40
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
41
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
42

    
43
/**
44
 * Filesystem Provider for Png.
45
 * @author fdiaz
46
 *
47
 */
48
public class PngFileSystemServerProvider extends AbstractFilesystemServerExplorerProvider
49
implements FilesystemServerExplorerProvider, ResourceConsumer{
50

    
51
    protected FilesystemServerExplorerProviderServices serverExplorer;
52

    
53
    @Override
54
    public int getMode() {
55
        return DataServerExplorer.MODE_RASTER;
56
    }
57

    
58
    @Override
59
    public boolean canCreate() {
60
        return false;
61
    }
62

    
63
    @Override
64
    public boolean canCreate(NewDataStoreParameters arg0) {
65
        return false;
66
    }
67

    
68
    @Override
69
    public void create(NewDataStoreParameters arg0, boolean arg1)
70
        throws CreateException {
71
        throw new UnsupportedOperationException();
72

    
73
    }
74

    
75
    @Override
76
    public NewDataStoreParameters getCreateParameters() throws DataException {
77
        throw new UnsupportedOperationException();
78
    }
79

    
80
    @Override
81
    public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
82
        this.serverExplorer = serverExplorer;
83
    }
84

    
85
    @Override
86
    public void remove(DataStoreParameters parameters) throws RemoveException {
87
        PngStoreProviderParameters params = (PngStoreProviderParameters) parameters;
88
        File file = params.getFile();
89
        if (!file.exists()) {
90
            throw new RemoveException(this.getDataStoreProviderName(),
91
                    new FileNotFoundException(params.getFile()));
92
        }
93
        if (!file.delete()) {
94
            throw new RemoveException(this.getDataStoreProviderName(),
95
                    new IOException("Error deleting file: "+file.getName()));
96
        }
97

    
98
    }
99

    
100
    @Override
101
    public String getDataStoreProviderName() {
102
        return PngStoreProvider.NAME;
103
    }
104

    
105
    @Override
106
    public String getDescription() {
107
        return PngStoreProvider.DESCRIPTION;
108
    }
109

    
110
    @Override
111
    public boolean accept(File pathname) {
112
        return FilenameUtils.isExtension(pathname.getName().toLowerCase(), "png");
113
    }
114

    
115
    @Override
116
    public boolean closeResourceRequested(ResourceProvider resource) {
117
        return !(this.equals(resource));
118
    }
119

    
120
    @Override
121
    public void resourceChanged(ResourceProvider resource) {
122
        //Do nothing
123
    }
124

    
125
}