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