root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / parsers / csw / CswCapabilitiesParser.java @ 3108
History | View | Annotate | Download (11.5 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.catalogClient.parsers.csw; |
42 |
|
43 |
import java.util.Vector; |
44 |
|
45 |
import es.gva.cit.catalogClient.drivers.CSWCatalogServiceDriver; |
46 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
47 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
48 |
import es.gva.cit.catalogClient.parsers.SOAPMessageParser; |
49 |
import es.gva.cit.catalogClient.utils.Strings; |
50 |
|
51 |
|
52 |
|
53 |
/**
|
54 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
55 |
*/
|
56 |
public class CswCapabilitiesParser { |
57 |
CSWCatalogServiceDriver driver; |
58 |
|
59 |
public CswCapabilitiesParser(CSWCatalogServiceDriver driver) {
|
60 |
this.driver = driver;
|
61 |
} |
62 |
|
63 |
public boolean parse(XMLNode node) { |
64 |
String prefix = ""; |
65 |
XMLNode[] operations = null; |
66 |
|
67 |
if (node.getName().equals("ows:ServiceExceptionReport")){ |
68 |
driver.setServerAnswerReady("El servidor ha devuelto una excepci?n");
|
69 |
return false; |
70 |
} |
71 |
|
72 |
|
73 |
//Vamos a recorrer todas las operaciones. Para cada una de ellas
|
74 |
//tomaremos las acciones correspondientes
|
75 |
operations = XMLTree.searchMultipleNode(node, |
76 |
"ows:OperationsMetadata->ows:Operation");
|
77 |
|
78 |
if (!(operations.length == 0)) { |
79 |
prefix = "ows:";
|
80 |
} else {
|
81 |
operations = XMLTree.searchMultipleNode(node, |
82 |
"OperationsMetadata->Operation");
|
83 |
} |
84 |
|
85 |
if (operations == null) { |
86 |
driver.setServerAnswerReady( |
87 |
"Se ha encontrado el servidor, pero parece ser " +
|
88 |
"que no soporta el protocolo CS-W");
|
89 |
|
90 |
return false; |
91 |
} |
92 |
|
93 |
if (this.driver.getCommunicationProtocol().equals("GET") && |
94 |
getHTTPExceptions(node)) { |
95 |
return false; |
96 |
} |
97 |
|
98 |
if (this.driver.getCommunicationProtocol().equals("SOAP") && |
99 |
getSOAPExceptions(node)) { |
100 |
return false; |
101 |
} |
102 |
|
103 |
//To save the protocols supported by each operation
|
104 |
this.driver.setOperations(new CswSupportedProtocolOperations()); |
105 |
|
106 |
//Operations name
|
107 |
String sOperation;
|
108 |
|
109 |
for (int i = 0; i < operations.length; i++) { |
110 |
sOperation = XMLTree.searchAtribute(operations[i], "name");
|
111 |
|
112 |
//////////////////Get Capabilities////////////////////
|
113 |
if (sOperation.equals("GetCapabilities") || |
114 |
sOperation.equals("CSW-Discovery.getCapabilities")) {
|
115 |
parseCapabilities(operations[i], prefix); |
116 |
} |
117 |
|
118 |
////////////////////DescribeRecord//////////////////
|
119 |
if (sOperation.equals("DescribeRecord")) { |
120 |
parseDescribeRecord(operations[i], prefix); |
121 |
} |
122 |
|
123 |
////////////////////GetDomain//////////////////
|
124 |
if (sOperation.equals("GetDomain")) { |
125 |
parseGetDomain(operations[i], prefix); |
126 |
} |
127 |
|
128 |
////////////////////GetRecords//////////////////
|
129 |
if (sOperation.equals("GetRecords") || |
130 |
sOperation.equals("CSW-Discovery.getRecords")) {
|
131 |
if (!(parseGetRecords(operations[i], prefix))) {
|
132 |
return false; |
133 |
} |
134 |
} |
135 |
|
136 |
////////////////////GetRecordsById//////////////////
|
137 |
if (sOperation.equals("GetRecordsById") || |
138 |
sOperation.equals("CSW-Discovery.getRecordById")) {
|
139 |
parseGetRecordsByID(operations[i], prefix); |
140 |
} |
141 |
|
142 |
////////////////////Transaction//////////////////
|
143 |
if (sOperation.equals("Transaction") || |
144 |
sOperation.equals("CSW-Publication.transaction")) {
|
145 |
parseTransaction(operations[i], prefix); |
146 |
} |
147 |
|
148 |
////////////////////Harvest//////////////////
|
149 |
if (sOperation.equals("Harvest") || |
150 |
sOperation.equals("CSW-Publication.harvest")) {
|
151 |
parseHarvest(operations[i], prefix); |
152 |
} |
153 |
} |
154 |
|
155 |
//Escribimos el mensaje de BienVenida
|
156 |
driver.setServerAnswerReady(XMLTree.searchNodeValue(node, |
157 |
prefix + "ServiceIdentification->" + prefix + "Title") + "\n" + |
158 |
XMLTree.searchNodeValue(node, |
159 |
prefix + "ServiceIdentification->" + prefix + "Abstract")); |
160 |
|
161 |
configureConstants(); |
162 |
|
163 |
return true; |
164 |
} |
165 |
|
166 |
public void configureConstants() { |
167 |
driver.setSortBy("true");
|
168 |
driver.setStartPosition("1");
|
169 |
driver.setMaxRecords("10");
|
170 |
} |
171 |
|
172 |
public void parseCapabilities(XMLNode node, String prefix) { |
173 |
driver.getOperations().setGetCapabilities(setSupportedProtocols(node,prefix)); |
174 |
} |
175 |
|
176 |
public void parseDescribeRecord(XMLNode node, String prefix) { |
177 |
driver.getOperations().setDescribeRecords(setSupportedProtocols(node,prefix)); |
178 |
} |
179 |
|
180 |
public void parseGetRecordsByID(XMLNode node, String prefix) { |
181 |
driver.getOperations().setGetRecordsById(setSupportedProtocols(node,prefix)); |
182 |
} |
183 |
|
184 |
public void parseGetDomain(XMLNode node, String prefix) { |
185 |
driver.getOperations().setGetDomain(setSupportedProtocols(node,prefix)); |
186 |
} |
187 |
|
188 |
public boolean parseGetRecords(XMLNode node, String prefix) { |
189 |
driver.getOperations().setGetRecords(setSupportedProtocols(node,prefix)); |
190 |
|
191 |
XMLNode[] parameters;
|
192 |
|
193 |
//Alamacenamos los parametros y los escribimos
|
194 |
parameters = XMLTree.searchMultipleNode(node, prefix + "Parameter");
|
195 |
|
196 |
for (int j = 0; j < parameters.length; j++) { |
197 |
String sParameter = XMLTree.searchAtribute(parameters[j], "name"); |
198 |
|
199 |
String[] values = XMLTree.searchMultipleNodeValue(parameters[j], |
200 |
prefix + "Value");
|
201 |
|
202 |
String[] defaultValue = XMLTree.searchMultipleNodeValue(parameters[j], |
203 |
prefix + "DefaultValue");
|
204 |
|
205 |
if (sParameter.equals("TypeName")) { |
206 |
driver.setTypeNames(Strings.join(defaultValue, values)); |
207 |
} |
208 |
|
209 |
if (sParameter.equals("outputFormat")) { |
210 |
if (!(Strings.find("text/xml", defaultValue) || |
211 |
Strings.find("text/xml", values))) {
|
212 |
if (!(Strings.find("application/xml", defaultValue) || |
213 |
Strings.find("application/xml", values))) {
|
214 |
driver.setServerAnswerReady("El servidor no devuelve " +
|
215 |
"texto en formato XML");
|
216 |
|
217 |
return false; |
218 |
} |
219 |
} |
220 |
} |
221 |
|
222 |
driver.setOutputFormat("text/xml");
|
223 |
|
224 |
if (sParameter.equals("outputSchema")) { |
225 |
driver.setOutputSchema(Strings.join(defaultValue, values)); |
226 |
} |
227 |
|
228 |
if (sParameter.equals("resultType")) { |
229 |
driver.setResultType(Strings.join(defaultValue, values)); |
230 |
} |
231 |
|
232 |
if (sParameter.equals("ElementSetName")) { |
233 |
driver.setElementSetName(Strings.join(defaultValue, values)); |
234 |
} |
235 |
|
236 |
if (sParameter.equals("CONSTRAINTLANGUAGE")) { |
237 |
driver.setCONSTRAINTLANGUAGE(Strings.join(defaultValue, values)); |
238 |
|
239 |
for (int i = 0; i < driver.getCONSTRAINTLANGUAGE().length; |
240 |
i++) { |
241 |
if (driver.getCONSTRAINTLANGUAGE()[i].toUpperCase().equals("FILTER")) { |
242 |
break;
|
243 |
} else {
|
244 |
driver.setServerAnswerReady( |
245 |
"De momento solo se pueden hacer querys " +
|
246 |
"usando la codificaci?n FILTER ENCODING que no est?" +
|
247 |
"soportada por el servidor");
|
248 |
} |
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
return true; |
254 |
} |
255 |
|
256 |
public void parseTransaction(XMLNode node, String prefix) { |
257 |
driver.getOperations().setTransaction(setSupportedProtocols(node,prefix)); |
258 |
} |
259 |
|
260 |
public void parseHarvest(XMLNode node, String prefix) { |
261 |
driver.getOperations().setHarvest(setSupportedProtocols(node,prefix)); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* This function returns the supported protocols of an operation
|
266 |
* defined by node.
|
267 |
* @param node
|
268 |
* Node that contains the operation information
|
269 |
* @param prefix
|
270 |
* getCapabilities tag prefix
|
271 |
*/
|
272 |
public String[] setSupportedProtocols(XMLNode node,String prefix){ |
273 |
Vector operations = new Vector(); |
274 |
|
275 |
XMLNode protocols = XMLTree.searchNode(node, prefix + "DCP");
|
276 |
|
277 |
XMLNode HTTPoperations = XMLTree.searchNode(protocols, prefix + "HTTP");
|
278 |
XMLNode[] childNodes = HTTPoperations.getSubnodes();
|
279 |
|
280 |
for (int i=0 ; i<childNodes.length ; i++){ |
281 |
if ((childNodes[i].getName().equals("Get")) || |
282 |
(childNodes[i].getName().equals(prefix + "Get"))){
|
283 |
operations.add(new String("GET")); |
284 |
} |
285 |
if ((childNodes[i].getName().equals("Post")) || |
286 |
(childNodes[i].getName().equals(prefix + "Post"))){
|
287 |
operations.add(new String("POST")); |
288 |
} |
289 |
|
290 |
} |
291 |
|
292 |
String[] output = new String[operations.size()]; |
293 |
for (int i=0 ; i<operations.size() ; i++) |
294 |
output[i] = (String) operations.get(i);
|
295 |
|
296 |
return output;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Parses the HTTP-CSW Exceptions
|
301 |
* @param node
|
302 |
* @return
|
303 |
*/
|
304 |
public boolean getHTTPExceptions(XMLNode node) { |
305 |
if (node.getName().equals("ServiceExceptionReport")) { |
306 |
driver.setServerAnswerReady(XMLTree.searchNodeValue(node, |
307 |
"ServiceException"));
|
308 |
|
309 |
return true; |
310 |
} |
311 |
|
312 |
return false; |
313 |
} |
314 |
|
315 |
/**
|
316 |
* It returns the exception code
|
317 |
* @param node
|
318 |
* Returned node.
|
319 |
* @return
|
320 |
*/
|
321 |
public String getExceptionCode(XMLNode node){ |
322 |
String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","code"); |
323 |
if (code == null) |
324 |
return "0"; |
325 |
return code;
|
326 |
} |
327 |
|
328 |
/**
|
329 |
* It returns the exception Subcode
|
330 |
* @param node
|
331 |
* Returned node.
|
332 |
* @return
|
333 |
*/
|
334 |
public String getExceptionSubCode(XMLNode node){ |
335 |
String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","subcode"); |
336 |
if (code == null) |
337 |
return "0"; |
338 |
return code;
|
339 |
|
340 |
} |
341 |
|
342 |
|
343 |
|
344 |
/**
|
345 |
* Parses the SOAP-CSW Exceptions
|
346 |
* @param node
|
347 |
* @return
|
348 |
*/
|
349 |
public boolean getSOAPExceptions(XMLNode node) { |
350 |
String msg = SOAPMessageParser.getFault(node);
|
351 |
|
352 |
if (msg != null) { |
353 |
driver.setServerAnswerReady(msg); |
354 |
|
355 |
return true; |
356 |
} |
357 |
|
358 |
return false; |
359 |
} |
360 |
|
361 |
} |