Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.io / src / main / java / org / gvsig / raster / tilecache / io / TileServerExplorer.java @ 5981

History | View | Annotate | Download (6.39 KB)

1 2477 nbrodin
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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 2
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
*/
22
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27
28
package org.gvsig.raster.tilecache.io;
29
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.util.List;
33
34 5980 fdiaz
import org.apache.commons.io.FilenameUtils;
35
36 2477 nbrodin
import org.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.DataManager;
38
import org.gvsig.fmap.dal.DataServerExplorer;
39
import org.gvsig.fmap.dal.DataServerExplorerParameters;
40 5980 fdiaz
import org.gvsig.fmap.dal.DataStore;
41 2477 nbrodin
import org.gvsig.fmap.dal.DataStoreParameters;
42
import org.gvsig.fmap.dal.NewDataStoreParameters;
43
import org.gvsig.fmap.dal.coverage.RasterLocator;
44
import org.gvsig.fmap.dal.exception.CreateException;
45
import org.gvsig.fmap.dal.exception.DataException;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.RemoveException;
48
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
49
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
50
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
51
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
52
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
53
54
public class TileServerExplorer extends AbstractFilesystemServerExplorerProvider implements DataServerExplorerProvider {
55
        public static final String               NAME                     = "TileServerExplorer";
56 5554 fdiaz
57 2477 nbrodin
        public TileServerExplorer() {
58 5554 fdiaz
59 2477 nbrodin
        }
60 5554 fdiaz
61 2477 nbrodin
        public TileServerExplorer(
62
                        TileServerExplorerParameters parameters,
63
                        DataServerExplorerProviderServices services)
64
                        throws InitializeException {
65
        }
66 5554 fdiaz
67 2477 nbrodin
        public boolean canCreate() {
68
                return false;
69
        }
70
71
        public boolean canCreate(NewDataStoreParameters parameters) {
72
                return false;
73
        }
74
75
        public void create(NewDataStoreParameters parameters, boolean overwrite)
76
                        throws CreateException {
77
                throw new UnsupportedOperationException();
78
        }
79
80
        public NewDataStoreParameters getCreateParameters() throws DataException {
81
                return null;
82
        }
83
84
        public void initialize(
85
                        FilesystemServerExplorerProviderServices serverExplorer) {
86
        }
87 5554 fdiaz
88 2477 nbrodin
        public void remove(DataStoreParameters parameters) throws RemoveException {
89
                throw new UnsupportedOperationException();
90
        }
91
92
        public String getDataStoreProviderName() {
93
                return TileProvider.NAME;
94
        }
95
96
        /**
97 5554 fdiaz
         * When the source is a file then this method will check if exists a
98 2477 nbrodin
         * provider that can manage it
99
         */
100
        public boolean accept(File pathname) {
101 5554 fdiaz
                if (pathname.getParentFile() != null &&
102 2477 nbrodin
                                pathname.getParentFile().getName().equals("cellhd")) {
103
                        if (pathname.getName().endsWith(".rmf")
104
                                        || pathname.getName().endsWith(".rmf~")) {
105
                                return false;
106
                        }
107
                        return true;
108
                }
109
110
                // Comprobamos que no sea un rmf propio, osea, que contenga xml
111
                if (pathname.getName().toLowerCase().endsWith(".rmf")) {
112
                        FileInputStream reader = null;
113
                        try {
114
                                reader = new FileInputStream(pathname);
115
                                String xml = "";
116
                                for (int i = 0; i < 6; i++) {
117
                                        xml += (char) reader.read();
118
                                }
119
                                if (xml.equals("<?xml ")) {
120
                                        return false;
121
                                }
122
                        } catch (Exception e) {
123
                        } finally {
124
                                try {
125
                                        reader.close();
126
                                } catch (Exception e) {
127
                                }
128
                        }
129
                }
130
131
                //The formats will be registered if it hasn't been done yet
132
                RasterLocator.getManager().getProviderServices().registerTileProviderFormats(TileProvider.class);
133 5554 fdiaz
134 2477 nbrodin
                return RasterLocator.getManager().getProviderServices().isExtensionSupported(
135 5554 fdiaz
                                pathname.getName(),
136 2477 nbrodin
                                TileProvider.class);
137
        }
138
139
        public String getDescription() {
140
                return TileProvider.DESCRIPTION;
141
        }
142
143
        public DataStoreParameters getParameters(File file) throws DataException {
144
                DataManager manager = DALLocator.getDataManager();
145
                AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager
146
                                .createStoreParameters(this.getDataStoreProviderName());
147
                params.setFile(file);
148
                return params;
149
        }
150 5554 fdiaz
151 2477 nbrodin
        public DataServerExplorerParameters getParameters() {
152
                return null;
153
        }
154 5554 fdiaz
155 2477 nbrodin
        public int getMode() {
156
                return DataServerExplorer.MODE_RASTER;
157
        }
158
159
        public DataServerExplorerProviderServices getServerExplorerProviderServices() {
160
                return null;
161
        }
162
163
        public boolean add(String provider, NewDataStoreParameters parameters,
164
                        boolean overwrite) throws DataException {
165
                return false;
166
        }
167
168
        public boolean canAdd() {
169
                return false;
170
        }
171
172
        public boolean canAdd(String storeName) throws DataException {
173
                return false;
174
        }
175
176
        public NewDataStoreParameters getAddParameters(String storeName)
177
                        throws DataException {
178
                return null;
179
        }
180
181
        @SuppressWarnings("unchecked")
182
        public List getDataStoreProviderNames() {
183
                return null;
184
        }
185
186
        public String getProviderName() {
187
                return null;
188
        }
189
190
        @SuppressWarnings("unchecked")
191
        public List list() throws DataException {
192
                return null;
193
        }
194
195
        @SuppressWarnings("unchecked")
196
        public List list(int mode) throws DataException {
197
                return null;
198
        }
199
200
        public void dispose() {
201 5554 fdiaz
202 2477 nbrodin
        }
203
204 5554 fdiaz
    @Override
205
    public DataStoreParameters get(String name) throws DataException {
206
        File theFile = new File(name);
207
        DataStoreParameters dsp = this.getParameters(theFile);
208
        return dsp;
209
210
    }
211
212 5980 fdiaz
    /* (non-Javadoc)
213
     * @see org.gvsig.fmap.dal.DataServerExplorer#getResourcePath(org.gvsig.fmap.dal.DataStore, java.lang.String)
214
     */
215
    @Override
216
    public File getResourcePath(DataStore dataStore, String resourceName) throws DataException {
217
        String rootPathName = getResourceRootPathName(dataStore);
218
        if (rootPathName == null) {
219
            return null;
220
        }
221
        File f = new File(FilenameUtils.getPathNoEndSeparator(rootPathName),resourceName);
222
        if( f.exists() ) {
223
            return f;
224
        }
225
        return new File(rootPathName + "." + resourceName);
226
    }
227
228 2477 nbrodin
}