svn-gvsig-desktop / trunk / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / catalog / loaders / WCSLayerLoader.java @ 15557
History | View | Annotate | Download (4.03 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 es.gva.cit.gvsig.catalog.loaders; |
42 |
|
43 |
import java.io.IOException; |
44 |
import java.util.Map; |
45 |
import java.util.TreeMap; |
46 |
|
47 |
import org.gvsig.i18n.Messages; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
50 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
51 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
52 |
|
53 |
import es.gva.cit.catalog.schemas.Resource; |
54 |
|
55 |
/**
|
56 |
* This class is used to load a WCS layer in gvSIG
|
57 |
*
|
58 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
59 |
*/
|
60 |
public class WCSLayerLoader extends LayerLoader{ |
61 |
|
62 |
|
63 |
public WCSLayerLoader(Resource resource) {
|
64 |
super(resource);
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* This method loads a WSC layer from a full URL
|
69 |
* @param link
|
70 |
* @throws LayerLoaderException
|
71 |
*/
|
72 |
public void loadLayer() throws LayerLoaderException { |
73 |
String link = getResource().getLinkage();
|
74 |
String name = getResource().getName();
|
75 |
try {
|
76 |
FLayer flayer = createWCSLayer(link,name); |
77 |
addLayerToView(flayer); |
78 |
} catch (IOException e) { |
79 |
throw new LayerLoaderException(e.getMessage(),getWindowMessage()); |
80 |
} |
81 |
} |
82 |
|
83 |
private FLayer createWCSLayer(String link,String name) throws IOException, LayerLoaderException { |
84 |
Map args = initFromQueryString(link,name);
|
85 |
ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
|
86 |
try {
|
87 |
return (FLayer)extensionPoint.create("OGC:WCS", args ); |
88 |
} catch(Exception e) { |
89 |
throw new LayerLoaderException(getErrorMessage(),getWindowMessage()); |
90 |
} |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Builds a coverage starting from a full GetCoverage URL.
|
95 |
* (Using this is not a regular function)
|
96 |
*/
|
97 |
private TreeMap initFromQueryString(String link,String name){ |
98 |
String host = null; |
99 |
String queryString = null; |
100 |
if (link.compareTo("?")==0){ |
101 |
host = link.substring(0,link.indexOf('?')); |
102 |
queryString = link.substring(link.indexOf('?')+1); |
103 |
}else{
|
104 |
host = link; |
105 |
queryString = "";
|
106 |
} |
107 |
queryString = link.substring(link.indexOf('?')+1); |
108 |
|
109 |
TreeMap map = new TreeMap(); |
110 |
String[] params = queryString.split("&"); |
111 |
for (int i = 0; i < params.length; i++) { |
112 |
if (params[i]!= null){ |
113 |
String[] nameValue = params[i].split("="); |
114 |
if (nameValue.length == 1){ |
115 |
map.put(nameValue[0].toUpperCase(), ""); |
116 |
}else if(nameValue.length == 2){ |
117 |
map.put(nameValue[0].toUpperCase(), nameValue[1]); |
118 |
} |
119 |
} |
120 |
} |
121 |
map.put("HOST",link);
|
122 |
if ((name != null) && (!name.equals(""))){ |
123 |
map.put("COVERAGE",name);
|
124 |
} |
125 |
return map;
|
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
|
131 |
*/
|
132 |
protected String getErrorMessage() { |
133 |
return Messages.getText("wcsError") + ".\n" + |
134 |
Messages.getText("link") + ": " + |
135 |
getResource().getLinkage(); |
136 |
} |
137 |
|
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
|
141 |
*/
|
142 |
protected String getWindowMessage() { |
143 |
return Messages.getText("wcsLoad"); |
144 |
} |
145 |
|
146 |
|
147 |
|
148 |
} |