root / tags / v1_1_Build_914 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / csw / parsers / CswCapabilitiesParser.java @ 11873
History | View | Annotate | Download (14.5 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package es.gva.cit.catalogClient.csw.parsers; |
43 |
import es.gva.cit.catalogClient.csw.drivers.CSWCatalogServiceDriver; |
44 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
45 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
46 |
import es.gva.cit.catalogClient.schemas.Schemas; |
47 |
import es.gva.cit.catalogClient.schemas.discoverer.SOAPMessageParser; |
48 |
import es.gva.cit.catalogClient.utils.Strings; |
49 |
import java.net.URL; |
50 |
import java.util.Vector; |
51 |
|
52 |
/**
|
53 |
*
|
54 |
*
|
55 |
*
|
56 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
57 |
*/
|
58 |
public class CswCapabilitiesParser { |
59 |
/**
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
private CSWCatalogServiceDriver driver;
|
64 |
|
65 |
/**
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
private URL url; |
70 |
/**
|
71 |
*
|
72 |
*
|
73 |
*/
|
74 |
private XMLNode rootNode;
|
75 |
|
76 |
/**
|
77 |
*
|
78 |
*
|
79 |
*
|
80 |
* @param driver Protocol Driver
|
81 |
* @param url Server Protocol
|
82 |
*/
|
83 |
public CswCapabilitiesParser(CSWCatalogServiceDriver driver, URL url) { |
84 |
this.driver = driver;
|
85 |
this.url = url;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
*
|
90 |
*
|
91 |
*
|
92 |
* @return
|
93 |
* @param node
|
94 |
*/
|
95 |
public boolean parse(XMLNode node) { |
96 |
rootNode = node; |
97 |
|
98 |
String prefix = ""; |
99 |
XMLNode[] operations = null; |
100 |
if (httpServerIsReady() == false){ |
101 |
return false; |
102 |
} |
103 |
|
104 |
if (soapServerIsReady() == false){ |
105 |
return false; |
106 |
} |
107 |
|
108 |
|
109 |
discoverServerProfile(node); |
110 |
|
111 |
if (driver.getServerProfile().equals(Schemas.EBRIM)){
|
112 |
boolean b = new CswIDECCapabilitiesParser(driver).parse(); |
113 |
if (b){
|
114 |
setWelcomeMessage(node,"");
|
115 |
} |
116 |
return b;
|
117 |
} |
118 |
|
119 |
//Vamos a recorrer todas las operaciones. Para cada una de ellas
|
120 |
//tomaremos las acciones correspondientes
|
121 |
operations = XMLTree.searchMultipleNode(node, |
122 |
"ows:OperationsMetadata->ows:Operation");
|
123 |
if (!(operations.length == 0)) { |
124 |
prefix = "ows:";
|
125 |
} else {
|
126 |
operations = XMLTree.searchMultipleNode(node, |
127 |
"OperationsMetadata->Operation");
|
128 |
} |
129 |
if ((operations == null) || (operations.length == 0)) { |
130 |
driver.setServerAnswerReady("errorNotCSWSupportedProtocol");
|
131 |
|
132 |
return false; |
133 |
} |
134 |
if (this.driver.getCommunicationProtocol().equals("GET") && |
135 |
getHTTPExceptions(node)) { |
136 |
return false; |
137 |
} |
138 |
if (this.driver.getCommunicationProtocol().equals("SOAP") && |
139 |
getSOAPExceptions(node)) { |
140 |
return false; |
141 |
} |
142 |
|
143 |
//To save the protocols supported by each operation
|
144 |
driver.setOperations(new CswSupportedProtocolOperations());
|
145 |
|
146 |
//Operations name
|
147 |
String sOperation;
|
148 |
|
149 |
for (int i = 0; i < operations.length; i++) { |
150 |
sOperation = XMLTree.searchAtribute(operations[i], "name");
|
151 |
//////////////////Get Capabilities////////////////////
|
152 |
if (sOperation.equals("GetCapabilities") || |
153 |
sOperation.equals("CSW-Discovery.getCapabilities")) {
|
154 |
parseCapabilities(operations[i], prefix); |
155 |
} |
156 |
////////////////////DescribeRecord//////////////////
|
157 |
if (sOperation.equals("DescribeRecord")) { |
158 |
parseDescribeRecord(operations[i], prefix); |
159 |
} |
160 |
////////////////////GetDomain//////////////////
|
161 |
if (sOperation.equals("GetDomain")) { |
162 |
parseGetDomain(operations[i], prefix); |
163 |
} |
164 |
////////////////////GetRecords//////////////////
|
165 |
if (sOperation.equals("GetRecords") || |
166 |
sOperation.equals("CSW-Discovery.getRecords")) {
|
167 |
if (!(parseGetRecords(operations[i], prefix))) {
|
168 |
return false; |
169 |
} |
170 |
} |
171 |
////////////////////GetRecordsById//////////////////
|
172 |
if (sOperation.equals("GetRecordsById") || |
173 |
sOperation.equals("CSW-Discovery.getRecordById")) {
|
174 |
parseGetRecordsByID(operations[i], prefix); |
175 |
} |
176 |
////////////////////Transaction//////////////////
|
177 |
if (sOperation.equals("Transaction") || |
178 |
sOperation.equals("CSW-Publication.transaction")) {
|
179 |
parseTransaction(operations[i], prefix); |
180 |
} |
181 |
////////////////////Harvest//////////////////
|
182 |
if (sOperation.equals("Harvest") || |
183 |
sOperation.equals("CSW-Publication.harvest")) {
|
184 |
parseHarvest(operations[i], prefix); |
185 |
} |
186 |
} |
187 |
setWelcomeMessage(node,prefix); |
188 |
setConstantValues(); |
189 |
return true; |
190 |
} |
191 |
|
192 |
/**
|
193 |
* This method is used to detect some common problems when the
|
194 |
* used protocol has been HTTP
|
195 |
*
|
196 |
*
|
197 |
* @return true if all is OK
|
198 |
*/
|
199 |
private boolean httpServerIsReady() { |
200 |
if (rootNode == null){ |
201 |
driver.setServerAnswerReady("errorNotSupportedProtocol");
|
202 |
return false; |
203 |
} |
204 |
|
205 |
if (rootNode.getName().equals("SRW:explainResponse")){ |
206 |
driver.setServerAnswerReady("errorIsASRWServer");
|
207 |
return false; |
208 |
} |
209 |
|
210 |
if (rootNode.getName().equals("ows:ServiceExceptionReport")){ |
211 |
driver.setServerAnswerReady("errorServerException");
|
212 |
return false; |
213 |
} |
214 |
return true; |
215 |
} |
216 |
|
217 |
/**
|
218 |
* This method is used to detect some common problems when the
|
219 |
* used protocol has been SOAP
|
220 |
*
|
221 |
*
|
222 |
* @return true if all is OK
|
223 |
*/
|
224 |
private boolean soapServerIsReady() { |
225 |
if (XMLTree.searchNode(rootNode,"SOAP-ENV:Body->SOAP-ENV:Fault") != null){ |
226 |
driver.setServerAnswerReady("errorSOAPProtocol");
|
227 |
return false; |
228 |
} |
229 |
return true; |
230 |
} |
231 |
|
232 |
/**
|
233 |
* This method is used to discover the CSW server profile. The value
|
234 |
* can be ebRIM or ISO19115
|
235 |
*
|
236 |
*
|
237 |
* @param node
|
238 |
*/
|
239 |
private void discoverServerProfile(XMLNode node) { |
240 |
if ((url.getHost().equals("delta.icc.es")) || |
241 |
(url.getHost().equals("indicio.demo.galdosinc.com")) ||
|
242 |
(url.getHost().equals("laits.gmu.edu"))){
|
243 |
driver.setServerProfile(Schemas.EBRIM); |
244 |
}else{
|
245 |
driver.setServerProfile(Schemas.ISO19115); |
246 |
} |
247 |
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* Sets the welcome message
|
252 |
*
|
253 |
*
|
254 |
* @param node
|
255 |
* @param prefix
|
256 |
*/
|
257 |
private void setWelcomeMessage(XMLNode node, String prefix) { |
258 |
//Escribimos el mensaje de BienVenida
|
259 |
driver.setServerAnswerReady(XMLTree.searchNodeValue(node, |
260 |
prefix + "ServiceIdentification->" + prefix + "Title") + "\n" + |
261 |
XMLTree.searchNodeValue(node, |
262 |
prefix + "ServiceIdentification->" + prefix + "Abstract")); |
263 |
} |
264 |
|
265 |
/**
|
266 |
* Sets some constant values
|
267 |
*
|
268 |
*/
|
269 |
private void setConstantValues() { |
270 |
driver.setSortBy("true");
|
271 |
driver.setStartPosition("1");
|
272 |
driver.setMaxRecords("10");
|
273 |
} |
274 |
|
275 |
/**
|
276 |
*
|
277 |
*
|
278 |
*
|
279 |
* @param node
|
280 |
* @param prefix
|
281 |
*/
|
282 |
private void parseCapabilities(XMLNode node, String prefix) { |
283 |
driver.getOperations().setGetCapabilities(setSupportedProtocols(node,prefix)); |
284 |
|
285 |
} |
286 |
|
287 |
/**
|
288 |
*
|
289 |
*
|
290 |
*
|
291 |
* @param node
|
292 |
* @param prefix
|
293 |
*/
|
294 |
private void parseDescribeRecord(XMLNode node, String prefix) { |
295 |
driver.getOperations().setDescribeRecords(setSupportedProtocols(node,prefix)); |
296 |
} |
297 |
|
298 |
/**
|
299 |
*
|
300 |
*
|
301 |
*
|
302 |
* @param node
|
303 |
* @param prefix
|
304 |
*/
|
305 |
private void parseGetRecordsByID(XMLNode node, String prefix) { |
306 |
driver.getOperations().setGetRecordsById(setSupportedProtocols(node,prefix)); |
307 |
} |
308 |
|
309 |
/**
|
310 |
*
|
311 |
*
|
312 |
*
|
313 |
* @param node
|
314 |
* @param prefix
|
315 |
*/
|
316 |
private void parseGetDomain(XMLNode node, String prefix) { |
317 |
driver.getOperations().setGetDomain(setSupportedProtocols(node,prefix)); |
318 |
} |
319 |
|
320 |
/**
|
321 |
*
|
322 |
*
|
323 |
*
|
324 |
* @return
|
325 |
* @param node
|
326 |
* @param prefix
|
327 |
*/
|
328 |
private boolean parseGetRecords(XMLNode node, String prefix) { |
329 |
driver.getOperations().setGetRecords(setSupportedProtocols(node,prefix)); |
330 |
|
331 |
XMLNode[] parameters;
|
332 |
//Alamacenamos los parametros y los escribimos
|
333 |
parameters = XMLTree.searchMultipleNode(node, prefix + "Parameter");
|
334 |
for (int j = 0; j < parameters.length; j++) { |
335 |
String sParameter = XMLTree.searchAtribute(parameters[j], "name"); |
336 |
String[] values = XMLTree.searchMultipleNodeValue(parameters[j], |
337 |
prefix + "Value");
|
338 |
String[] defaultValue = XMLTree.searchMultipleNodeValue(parameters[j], |
339 |
prefix + "DefaultValue");
|
340 |
if (sParameter.equals("TypeName")) { |
341 |
driver.setTypeNames(Strings.join(defaultValue, values)); |
342 |
} |
343 |
if (sParameter.equals("outputFormat")) { |
344 |
if (!(Strings.find("text/xml", defaultValue) || |
345 |
Strings.find("text/xml", values))) {
|
346 |
if (!(Strings.find("application/xml", defaultValue) || |
347 |
Strings.find("application/xml", values))) {
|
348 |
driver.setServerAnswerReady("El servidor no devuelve " +
|
349 |
"texto en formato XML");
|
350 |
return false; |
351 |
} |
352 |
} |
353 |
} |
354 |
driver.setOutputFormat("text/xml");
|
355 |
if (sParameter.equals("outputSchema")) { |
356 |
driver.setOutputSchema(Strings.join(defaultValue, values)); |
357 |
driver.setServerProfile(Schemas.DUBLINCORE); |
358 |
for (int i=0 ; i<driver.getOutputSchema().length ; i++){ |
359 |
if (driver.getOutputSchema()[i].equals(Schemas.ISO19115))
|
360 |
driver.setServerProfile(Schemas.ISO19115); |
361 |
break;
|
362 |
} |
363 |
} |
364 |
|
365 |
|
366 |
if (sParameter.equals("resultType")) { |
367 |
driver.setResultType(Strings.join(defaultValue, values)); |
368 |
} |
369 |
if (sParameter.equals("ElementSetName")) { |
370 |
driver.setElementSetName(Strings.join(defaultValue, values)); |
371 |
} |
372 |
if (sParameter.equals("CONSTRAINTLANGUAGE")) { |
373 |
driver.setCONSTRAINTLANGUAGE(Strings.join(defaultValue, values)); |
374 |
for (int i = 0; i < driver.getCONSTRAINTLANGUAGE().length; |
375 |
i++) { |
376 |
if (driver.getCONSTRAINTLANGUAGE()[i].toUpperCase().equals("FILTER")) { |
377 |
break;
|
378 |
} else {
|
379 |
driver.setServerAnswerReady("errorFENotSupported");
|
380 |
|
381 |
} |
382 |
} |
383 |
} |
384 |
} |
385 |
return true; |
386 |
} |
387 |
|
388 |
/**
|
389 |
*
|
390 |
*
|
391 |
*
|
392 |
* @param node
|
393 |
* @param prefix
|
394 |
*/
|
395 |
private void parseTransaction(XMLNode node, String prefix) { |
396 |
driver.getOperations().setTransaction(setSupportedProtocols(node,prefix)); |
397 |
} |
398 |
|
399 |
/**
|
400 |
*
|
401 |
*
|
402 |
*
|
403 |
* @param node
|
404 |
* @param prefix
|
405 |
*/
|
406 |
private void parseHarvest(XMLNode node, String prefix) { |
407 |
driver.getOperations().setHarvest(setSupportedProtocols(node,prefix)); |
408 |
} |
409 |
|
410 |
/**
|
411 |
* This function returns the supported protocols of an operation
|
412 |
* defined by node.
|
413 |
*
|
414 |
*
|
415 |
* @return
|
416 |
* @param node Node that contains the operation information
|
417 |
* @param prefix getCapabilities tag prefix
|
418 |
*/
|
419 |
private String[] setSupportedProtocols(XMLNode node, String prefix) { |
420 |
Vector operations = new Vector(); |
421 |
|
422 |
XMLNode protocols = XMLTree.searchNode(node, prefix + "DCP");
|
423 |
|
424 |
XMLNode HTTPoperations = XMLTree.searchNode(protocols, prefix + "HTTP");
|
425 |
XMLNode[] childNodes = HTTPoperations.getSubnodes();
|
426 |
|
427 |
for (int i=0 ; i<childNodes.length ; i++){ |
428 |
if ((childNodes[i].getName().equals("Get")) || |
429 |
(childNodes[i].getName().equals(prefix + "Get"))){
|
430 |
operations.add(new String("GET")); |
431 |
} |
432 |
if ((childNodes[i].getName().equals("Post")) || |
433 |
(childNodes[i].getName().equals(prefix + "Post"))){
|
434 |
operations.add(new String("POST")); |
435 |
} |
436 |
|
437 |
} |
438 |
|
439 |
String[] output = new String[operations.size()]; |
440 |
for (int i=0 ; i<operations.size() ; i++) |
441 |
output[i] = (String) operations.get(i);
|
442 |
|
443 |
return output;
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* Parses the HTTP-CSW Exceptions
|
448 |
*
|
449 |
*
|
450 |
* @return
|
451 |
* @param node
|
452 |
*/
|
453 |
private boolean getHTTPExceptions(XMLNode node) { |
454 |
if (node.getName().equals("ServiceExceptionReport")) { |
455 |
driver.setServerAnswerReady(XMLTree.searchNodeValue(node, |
456 |
"ServiceException"));
|
457 |
return true; |
458 |
} |
459 |
return false; |
460 |
} |
461 |
|
462 |
/**
|
463 |
* It returns the exception code
|
464 |
*
|
465 |
*
|
466 |
* @return
|
467 |
* @param node Returned node.
|
468 |
*/
|
469 |
public String getExceptionCode(XMLNode node) { |
470 |
String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","code"); |
471 |
if (code == null) |
472 |
return "0"; |
473 |
return code;
|
474 |
} |
475 |
|
476 |
/**
|
477 |
* It returns the exception Subcode
|
478 |
*
|
479 |
*
|
480 |
* @return
|
481 |
* @param node Returned node.
|
482 |
*/
|
483 |
public String getExceptionSubCode(XMLNode node) { |
484 |
String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","subcode"); |
485 |
if (code == null) |
486 |
return "0"; |
487 |
return code;
|
488 |
|
489 |
} |
490 |
|
491 |
/**
|
492 |
* Parses the SOAP-CSW Exceptions
|
493 |
*
|
494 |
*
|
495 |
* @return
|
496 |
* @param node
|
497 |
*/
|
498 |
private boolean getSOAPExceptions(XMLNode node) { |
499 |
String msg = SOAPMessageParser.getFault(node);
|
500 |
if (msg != null) { |
501 |
driver.setServerAnswerReady(msg); |
502 |
return true; |
503 |
} |
504 |
return false; |
505 |
} |
506 |
} |