gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.gdal / org.gvsig.raster.gdal.provider / src / main / java / org / gvsig / raster / gdal / provider / RasterGdalFileSystemServerProvider.java @ 6317
History | View | Annotate | Download (4.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.raster.gdal.provider; |
24 |
|
25 |
import java.io.File; |
26 |
import java.io.FileInputStream; |
27 |
import java.io.IOException; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Iterator; |
30 |
import java.util.Vector; |
31 |
|
32 |
import org.apache.commons.lang3.StringUtils; |
33 |
import org.gdal.gdal.Driver; |
34 |
import org.gdal.gdal.gdal; |
35 |
import org.gdal.gdalconst.gdalconstConstants; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.fmap.dal.DataServerExplorer; |
40 |
import org.gvsig.fmap.dal.DataStoreParameters; |
41 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
42 |
import org.gvsig.fmap.dal.exception.CreateException; |
43 |
import org.gvsig.fmap.dal.exception.DataException; |
44 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
45 |
import org.gvsig.fmap.dal.exception.RemoveException; |
46 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
47 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
48 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
49 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
50 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
51 |
|
52 |
/**
|
53 |
* Filesystem Provider for Raster GDAL.
|
54 |
* @author dmartinezizquierdo
|
55 |
*
|
56 |
*/
|
57 |
public class RasterGdalFileSystemServerProvider extends AbstractFilesystemServerExplorerProvider |
58 |
implements FilesystemServerExplorerProvider, ResourceConsumer{
|
59 |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(RasterGdalFileSystemServerProvider.class); |
61 |
protected FilesystemServerExplorerProviderServices serverExplorer;
|
62 |
private ArrayList<String> acceptedExtensions; |
63 |
|
64 |
public int getMode() { |
65 |
return DataServerExplorer.MODE_RASTER;
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
public boolean canCreate() { |
70 |
return false; |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public boolean canCreate(NewDataStoreParameters arg0) { |
75 |
return false; |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void create(NewDataStoreParameters arg0, boolean arg1) |
80 |
throws CreateException {
|
81 |
//TODO: Parece que el antiguo raster si que lo soporta para geoprocesos. Ver como lo hace
|
82 |
throw new UnsupportedOperationException(); |
83 |
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
88 |
//TODO: Parece que el antiguo raster si que lo soporta para geoprocesos. Ver como lo hace
|
89 |
throw new UnsupportedOperationException(); |
90 |
} |
91 |
|
92 |
@Override
|
93 |
public void initialize(FilesystemServerExplorerProviderServices serverExplorer) { |
94 |
this.serverExplorer = serverExplorer;
|
95 |
this.acceptedExtensions=new ArrayList<>(); |
96 |
for (int i=0;i<gdal.GetDriverCount(); i++){ |
97 |
Driver drv = gdal.GetDriver(i);
|
98 |
String extension=drv.GetMetadataItem(gdalconstConstants.GDAL_DMD_EXTENSION);
|
99 |
if (StringUtils.isNotEmpty(extension)){
|
100 |
acceptedExtensions.add(extension); |
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
107 |
RasterGdalStoreProviderParameters params = (RasterGdalStoreProviderParameters) parameters; |
108 |
File file = params.getFile();
|
109 |
if (!file.exists()) {
|
110 |
throw new RemoveException(this.getDataStoreProviderName(), |
111 |
new FileNotFoundException(params.getFile())); |
112 |
} |
113 |
if (!file.delete()) {
|
114 |
throw new RemoveException(this.getDataStoreProviderName(), |
115 |
new IOException("Error deleting file: "+file.getName())); |
116 |
} |
117 |
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public String getDataStoreProviderName() { |
122 |
return RasterGdalStoreProvider.NAME;
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public String getDescription() { |
127 |
return RasterGdalStoreProvider.DESCRIPTION;
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public boolean accept(File pathname) { |
132 |
return gdal.IdentifyDriver(pathname.getAbsolutePath())!=null; |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public boolean closeResourceRequested(ResourceProvider resource) { |
137 |
return !(this.equals(resource)); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void resourceChanged(ResourceProvider resource) { |
142 |
//Do nothing
|
143 |
} |
144 |
|
145 |
} |