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