gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.extension / src / main / java / org / gvsig / catalog / loaders / WCSLayerLoader.java @ 64
History | View | Annotate | Download (7.41 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.catalog.loaders; |
42 |
|
43 |
import java.util.HashMap; |
44 |
import java.util.HashSet; |
45 |
import java.util.List; |
46 |
import java.util.Map; |
47 |
|
48 |
import org.gvsig.app.gui.wizards.WizardListener; |
49 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
50 |
import org.gvsig.catalog.gui.LoaderWizardPanel; |
51 |
import org.gvsig.catalog.schemas.Resource; |
52 |
import org.gvsig.fmap.dal.DataStoreParameters; |
53 |
import org.gvsig.fmap.dal.coverage.exception.ConnectException; |
54 |
import org.gvsig.fmap.dal.exception.InitializeException; |
55 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
56 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
57 |
import org.gvsig.i18n.Messages; |
58 |
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.WCSParamsPanel; |
59 |
import org.gvsig.raster.wcs.io.WCSLayerNode; |
60 |
import org.gvsig.raster.wcs.io.WCSProvider; |
61 |
import org.gvsig.raster.wcs.io.WCSServerExplorer; |
62 |
import org.gvsig.raster.wcs.io.WCSServerExplorerParameters; |
63 |
import org.slf4j.Logger; |
64 |
import org.slf4j.LoggerFactory; |
65 |
|
66 |
|
67 |
/**
|
68 |
* This class is used to load a WCS layer in gvSIG
|
69 |
*
|
70 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
71 |
*/
|
72 |
public class WCSLayerLoader extends GvSigLayerLoader{ |
73 |
|
74 |
private Logger logger = LoggerFactory.getLogger(WCSLayerLoader.class); |
75 |
|
76 |
private WCSServerExplorer explorer;
|
77 |
|
78 |
private WCSParamsPanel wcsParamsPanel;
|
79 |
|
80 |
public static final String FIELD_FORMAT = "format"; |
81 |
public static final String FIELD_NAME = "name"; |
82 |
public static final String FIELD_SRSSTR = "srsstr"; |
83 |
public static final String FIELD_URI = "uri"; |
84 |
public static final String FIELD_ONLINERESOURC = "onlineresources"; |
85 |
public static final String FIELD_WIDTH = "width"; |
86 |
public static final String FIELD_HEIGHT = "height"; |
87 |
public static final String FIELD_PARAM = "parameter"; |
88 |
|
89 |
public WCSLayerLoader(Resource resource) {
|
90 |
super(resource);
|
91 |
} |
92 |
|
93 |
protected boolean hasSpecificLayer() { |
94 |
return true; |
95 |
} |
96 |
|
97 |
protected String getLayerName() { |
98 |
return getResource().getName();
|
99 |
} |
100 |
|
101 |
protected DataStoreParameters createDataStoreParameters()
|
102 |
throws InitializeException, ProviderNotRegisteredException {
|
103 |
DataStoreParameters dataStoreParameters = DATA_MANAGER.createStoreParameters("Wcs Store");
|
104 |
|
105 |
if(getResource() != null){ |
106 |
dataStoreParameters.setDynValue(FIELD_NAME, getLayerName()); |
107 |
dataStoreParameters.setDynValue(FIELD_ONLINERESOURC, createOnlineResources()); |
108 |
} |
109 |
|
110 |
if(parseQuery(dataStoreParameters, getResource().getLinkage())){
|
111 |
return dataStoreParameters;
|
112 |
} |
113 |
|
114 |
return null; |
115 |
} |
116 |
|
117 |
protected Map createOnlineResources() { |
118 |
Map args = new HashMap(); |
119 |
args.put("GepCoverage", getResource().getLinkage());
|
120 |
return args;
|
121 |
} |
122 |
|
123 |
protected String extensionPointName() { |
124 |
return "OGC:WCS"; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Builds a coverage starting from a full GetCoverage URL.
|
129 |
* (Using this is not a regular function)
|
130 |
*/
|
131 |
private boolean parseQuery(DataStoreParameters dataStoreParameters, String link){ |
132 |
|
133 |
String host = null; |
134 |
String queryString = null; |
135 |
int index = link.indexOf("?"); |
136 |
if (index > 0){ |
137 |
host = link.substring(0, index);
|
138 |
queryString = link.substring(index+1);
|
139 |
}else{
|
140 |
host = link; |
141 |
queryString = "";
|
142 |
} |
143 |
|
144 |
if(link.indexOf('?') > -1){ |
145 |
queryString = link.substring(link.indexOf('?')+1); |
146 |
dataStoreParameters.setDynValue(FIELD_URI, link.substring(0,link.indexOf('?'))); |
147 |
|
148 |
String[] params = queryString.split("&"); |
149 |
for (int i = 0; i < params.length; i++) { |
150 |
if (params[i]!= null){ |
151 |
String[] nameValue = params[i].split("="); |
152 |
if(nameValue.length == 2){ |
153 |
String param = nameValue[0].toUpperCase(); |
154 |
if (param.equals("CRS")){ |
155 |
dataStoreParameters.setDynValue(FIELD_SRSSTR, nameValue[1]);
|
156 |
}else if (param.equals("FORMAT")){ |
157 |
dataStoreParameters.setDynValue(FIELD_FORMAT, nameValue[1]);
|
158 |
}else if (param.equals("WIDTH")){ |
159 |
dataStoreParameters.setDynValue(FIELD_WIDTH, nameValue[1]);
|
160 |
}else if (param.equals("HEIGHT")){ |
161 |
dataStoreParameters.setDynValue(FIELD_HEIGHT, nameValue[1]);
|
162 |
}else if (param.equals("BANDS")){ |
163 |
dataStoreParameters.setDynValue(FIELD_PARAM, nameValue[1]);
|
164 |
} |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
}else{
|
170 |
dataStoreParameters.setDynValue(FIELD_URI, link); |
171 |
|
172 |
|
173 |
try {
|
174 |
WCSServerExplorerParameters explorerParams; |
175 |
explorerParams = (WCSServerExplorerParameters) DATA_MANAGER.createServerExplorerParameters(WCSProvider.NAME); |
176 |
explorerParams.setHost(host); |
177 |
explorer = (WCSServerExplorer) DATA_MANAGER.createServerExplorer(explorerParams); |
178 |
explorer.connect(null);
|
179 |
|
180 |
deleteRepitedValues(); |
181 |
|
182 |
if(!getParams(dataStoreParameters, link)){
|
183 |
return false; |
184 |
} |
185 |
} catch (ValidateDataParametersException e) {
|
186 |
// TODO Auto-generated catch block
|
187 |
e.printStackTrace(); |
188 |
return false; |
189 |
} catch (InitializeException e) {
|
190 |
// TODO Auto-generated catch block
|
191 |
e.printStackTrace(); |
192 |
return false; |
193 |
} catch (ProviderNotRegisteredException e) {
|
194 |
// TODO Auto-generated catch block
|
195 |
e.printStackTrace(); |
196 |
return false; |
197 |
} catch (ConnectException e) { |
198 |
// TODO Auto-generated catch block
|
199 |
e.printStackTrace(); |
200 |
} |
201 |
|
202 |
|
203 |
} |
204 |
|
205 |
return true; |
206 |
} |
207 |
|
208 |
private void deleteRepitedValues() { |
209 |
for(int i=0; i<explorer.getCoverageList().length; i++){ |
210 |
WCSLayerNode layer = explorer.getCoverageList()[i]; |
211 |
deleteDuplicatedStringsFromList(layer.getFormats()); |
212 |
deleteDuplicatedStringsFromList(layer.getInterpolationMethods()); |
213 |
deleteDuplicatedStringsFromList(layer.getSRSs()); |
214 |
} |
215 |
} |
216 |
|
217 |
private void deleteDuplicatedStringsFromList(List list){ |
218 |
HashSet hs = new HashSet(); |
219 |
hs.addAll(list); |
220 |
list.clear(); |
221 |
list.addAll(hs); |
222 |
} |
223 |
|
224 |
private boolean getParams(DataStoreParameters dataStoreParameters, String link) { |
225 |
try{
|
226 |
wcsParamsPanel = new WCSParamsPanel();
|
227 |
wcsParamsPanel.setListenerSupport(new WizardListenerSupport());
|
228 |
wcsParamsPanel.setWizardData(explorer); |
229 |
|
230 |
LoaderWizardPanel panel = new LoaderWizardPanel(wcsParamsPanel, dataStoreParameters);
|
231 |
return panel.showWizardOnDialog();
|
232 |
|
233 |
}catch(NoClassDefFoundError e1){ |
234 |
logger.info("No est? instalada la extensi?n de raster");
|
235 |
return false; |
236 |
} |
237 |
} |
238 |
|
239 |
protected String getErrorMessage() { |
240 |
return Messages.getText("wcsError") + ".\n" + |
241 |
Messages.getText("link") + ": " + |
242 |
getResource().getLinkage(); |
243 |
} |
244 |
|
245 |
protected String getWindowMessage() { |
246 |
return Messages.getText("wcsLoad"); |
247 |
} |
248 |
} |