svn-gvsig-desktop / tags / v1_1_Build_1012 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / csw / parsers / CswCapabilitiesParser.java @ 12987
History | View | Annotate | Download (14.5 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 3593 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | 3213 | jorpiell | *
|
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 | 3593 | jorpiell | * Av. Blasco Ib??ez, 50
|
25 | 3213 | jorpiell | * 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 | 3509 | jorpiell | import es.gva.cit.catalogClient.schemas.Schemas; |
47 | import es.gva.cit.catalogClient.schemas.discoverer.SOAPMessageParser; |
||
48 | 3213 | jorpiell | import es.gva.cit.catalogClient.utils.Strings; |
49 | 3613 | jorpiell | import java.net.URL; |
50 | import java.util.Vector; |
||
51 | 3213 | jorpiell | |
52 | /**
|
||
53 | 3566 | jorpiell | *
|
54 | *
|
||
55 | *
|
||
56 | 3213 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
57 | */
|
||
58 | public class CswCapabilitiesParser { |
||
59 | 3566 | jorpiell | /**
|
60 | *
|
||
61 | *
|
||
62 | */
|
||
63 | 3213 | jorpiell | private CSWCatalogServiceDriver driver;
|
64 | 3566 | jorpiell | |
65 | /**
|
||
66 | *
|
||
67 | *
|
||
68 | */
|
||
69 | 3213 | jorpiell | private URL url; |
70 | 3566 | jorpiell | /**
|
71 | *
|
||
72 | *
|
||
73 | */
|
||
74 | 3454 | jorpiell | private XMLNode rootNode;
|
75 | 3566 | jorpiell | |
76 | /**
|
||
77 | *
|
||
78 | *
|
||
79 | *
|
||
80 | * @param driver Protocol Driver
|
||
81 | * @param url Server Protocol
|
||
82 | */
|
||
83 | public CswCapabilitiesParser(CSWCatalogServiceDriver driver, URL url) { |
||
84 | 3213 | jorpiell | this.driver = driver;
|
85 | 3463 | jorpiell | this.url = url;
|
86 | 3566 | jorpiell | } |
87 | 3213 | jorpiell | |
88 | 3566 | jorpiell | /**
|
89 | *
|
||
90 | *
|
||
91 | *
|
||
92 | * @return
|
||
93 | * @param node
|
||
94 | */
|
||
95 | public boolean parse(XMLNode node) { |
||
96 | 3454 | jorpiell | rootNode = node; |
97 | |||
98 | 3213 | jorpiell | String prefix = ""; |
99 | XMLNode[] operations = null; |
||
100 | 3454 | jorpiell | if (httpServerIsReady() == false){ |
101 | 3213 | jorpiell | return false; |
102 | 3454 | jorpiell | } |
103 | 3213 | jorpiell | |
104 | 3454 | jorpiell | if (soapServerIsReady() == false){ |
105 | return false; |
||
106 | } |
||
107 | |||
108 | |||
109 | discoverServerProfile(node); |
||
110 | |||
111 | 3509 | jorpiell | if (driver.getServerProfile().equals(Schemas.EBRIM)){
|
112 | 3213 | jorpiell | boolean b = new CswIDECCapabilitiesParser(driver).parse(); |
113 | if (b){
|
||
114 | setWelcomeMessage(node,"");
|
||
115 | } |
||
116 | return b;
|
||
117 | 3454 | jorpiell | } |
118 | 3311 | jorpiell | |
119 | 3213 | jorpiell | //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 | 6081 | jorpiell | if ((operations == null) || (operations.length == 0)) { |
130 | 3463 | jorpiell | driver.setServerAnswerReady("errorNotCSWSupportedProtocol");
|
131 | |||
132 | 3213 | jorpiell | 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 | 3566 | jorpiell | return true; |
190 | } |
||
191 | 3213 | jorpiell | |
192 | 3566 | jorpiell | /**
|
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 | 3454 | jorpiell | if (rootNode == null){ |
201 | 3463 | jorpiell | driver.setServerAnswerReady("errorNotSupportedProtocol");
|
202 | 3454 | jorpiell | return false; |
203 | } |
||
204 | |||
205 | if (rootNode.getName().equals("SRW:explainResponse")){ |
||
206 | 3463 | jorpiell | driver.setServerAnswerReady("errorIsASRWServer");
|
207 | 3454 | jorpiell | return false; |
208 | } |
||
209 | |||
210 | if (rootNode.getName().equals("ows:ServiceExceptionReport")){ |
||
211 | 3463 | jorpiell | driver.setServerAnswerReady("errorServerException");
|
212 | 3454 | jorpiell | return false; |
213 | } |
||
214 | return true; |
||
215 | 3566 | jorpiell | } |
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 | 3454 | jorpiell | if (XMLTree.searchNode(rootNode,"SOAP-ENV:Body->SOAP-ENV:Fault") != null){ |
226 | 3463 | jorpiell | driver.setServerAnswerReady("errorSOAPProtocol");
|
227 | 3454 | jorpiell | return false; |
228 | } |
||
229 | return true; |
||
230 | 3566 | jorpiell | } |
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 | 8765 | jjdelcerro | if ((url.getHost().equals("delta.icc.es")) || |
241 | 8604 | jorpiell | (url.getHost().equals("indicio.demo.galdosinc.com")) ||
|
242 | (url.getHost().equals("laits.gmu.edu"))){
|
||
243 | 3509 | jorpiell | driver.setServerProfile(Schemas.EBRIM); |
244 | 3454 | jorpiell | }else{
|
245 | 3509 | jorpiell | driver.setServerProfile(Schemas.ISO19115); |
246 | 3454 | jorpiell | } |
247 | 3456 | jorpiell | |
248 | 3566 | jorpiell | } |
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 | 3213 | jorpiell | //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 | 3566 | jorpiell | } |
264 | |||
265 | /**
|
||
266 | * Sets some constant values
|
||
267 | *
|
||
268 | */
|
||
269 | private void setConstantValues() { |
||
270 | 3213 | jorpiell | driver.setSortBy("true");
|
271 | driver.setStartPosition("1");
|
||
272 | driver.setMaxRecords("10");
|
||
273 | 3566 | jorpiell | } |
274 | 3213 | jorpiell | |
275 | 3566 | jorpiell | /**
|
276 | *
|
||
277 | *
|
||
278 | *
|
||
279 | * @param node
|
||
280 | * @param prefix
|
||
281 | */
|
||
282 | private void parseCapabilities(XMLNode node, String prefix) { |
||
283 | 3213 | jorpiell | driver.getOperations().setGetCapabilities(setSupportedProtocols(node,prefix)); |
284 | 4837 | jorpiell | |
285 | 3566 | jorpiell | } |
286 | 3213 | jorpiell | |
287 | 3566 | jorpiell | /**
|
288 | *
|
||
289 | *
|
||
290 | *
|
||
291 | * @param node
|
||
292 | * @param prefix
|
||
293 | */
|
||
294 | private void parseDescribeRecord(XMLNode node, String prefix) { |
||
295 | 3213 | jorpiell | driver.getOperations().setDescribeRecords(setSupportedProtocols(node,prefix)); |
296 | 3566 | jorpiell | } |
297 | 3213 | jorpiell | |
298 | 3566 | jorpiell | /**
|
299 | *
|
||
300 | *
|
||
301 | *
|
||
302 | * @param node
|
||
303 | * @param prefix
|
||
304 | */
|
||
305 | private void parseGetRecordsByID(XMLNode node, String prefix) { |
||
306 | 3213 | jorpiell | driver.getOperations().setGetRecordsById(setSupportedProtocols(node,prefix)); |
307 | 3566 | jorpiell | } |
308 | 3213 | jorpiell | |
309 | 3566 | jorpiell | /**
|
310 | *
|
||
311 | *
|
||
312 | *
|
||
313 | * @param node
|
||
314 | * @param prefix
|
||
315 | */
|
||
316 | private void parseGetDomain(XMLNode node, String prefix) { |
||
317 | 3213 | jorpiell | driver.getOperations().setGetDomain(setSupportedProtocols(node,prefix)); |
318 | 3566 | jorpiell | } |
319 | 3213 | jorpiell | |
320 | 3566 | jorpiell | /**
|
321 | *
|
||
322 | *
|
||
323 | *
|
||
324 | * @return
|
||
325 | * @param node
|
||
326 | * @param prefix
|
||
327 | */
|
||
328 | private boolean parseGetRecords(XMLNode node, String prefix) { |
||
329 | 3213 | jorpiell | 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 | 3509 | jorpiell | driver.setServerProfile(Schemas.DUBLINCORE); |
358 | 3311 | jorpiell | for (int i=0 ; i<driver.getOutputSchema().length ; i++){ |
359 | 3509 | jorpiell | if (driver.getOutputSchema()[i].equals(Schemas.ISO19115))
|
360 | driver.setServerProfile(Schemas.ISO19115); |
||
361 | 3311 | jorpiell | break;
|
362 | } |
||
363 | 3213 | jorpiell | } |
364 | 3311 | jorpiell | |
365 | |||
366 | 3213 | jorpiell | 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 | 3463 | jorpiell | driver.setServerAnswerReady("errorFENotSupported");
|
380 | |||
381 | 3213 | jorpiell | } |
382 | } |
||
383 | } |
||
384 | } |
||
385 | return true; |
||
386 | 3566 | jorpiell | } |
387 | 3213 | jorpiell | |
388 | 3566 | jorpiell | /**
|
389 | *
|
||
390 | *
|
||
391 | *
|
||
392 | * @param node
|
||
393 | * @param prefix
|
||
394 | */
|
||
395 | private void parseTransaction(XMLNode node, String prefix) { |
||
396 | 3213 | jorpiell | driver.getOperations().setTransaction(setSupportedProtocols(node,prefix)); |
397 | 3566 | jorpiell | } |
398 | 3213 | jorpiell | |
399 | 3566 | jorpiell | /**
|
400 | *
|
||
401 | *
|
||
402 | *
|
||
403 | * @param node
|
||
404 | * @param prefix
|
||
405 | */
|
||
406 | private void parseHarvest(XMLNode node, String prefix) { |
||
407 | 3213 | jorpiell | driver.getOperations().setHarvest(setSupportedProtocols(node,prefix)); |
408 | 3566 | jorpiell | } |
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 | 3213 | jorpiell | 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 | 3566 | jorpiell | } |
445 | 3213 | jorpiell | |
446 | 3566 | jorpiell | /**
|
447 | * Parses the HTTP-CSW Exceptions
|
||
448 | *
|
||
449 | *
|
||
450 | * @return
|
||
451 | * @param node
|
||
452 | */
|
||
453 | private boolean getHTTPExceptions(XMLNode node) { |
||
454 | 3213 | jorpiell | if (node.getName().equals("ServiceExceptionReport")) { |
455 | driver.setServerAnswerReady(XMLTree.searchNodeValue(node, |
||
456 | "ServiceException"));
|
||
457 | return true; |
||
458 | } |
||
459 | 3566 | jorpiell | return false; |
460 | } |
||
461 | 3213 | jorpiell | |
462 | 3566 | jorpiell | /**
|
463 | * It returns the exception code
|
||
464 | *
|
||
465 | *
|
||
466 | * @return
|
||
467 | * @param node Returned node.
|
||
468 | */
|
||
469 | public String getExceptionCode(XMLNode node) { |
||
470 | 3213 | jorpiell | String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","code"); |
471 | if (code == null) |
||
472 | return "0"; |
||
473 | return code;
|
||
474 | 3566 | jorpiell | } |
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 | 3213 | jorpiell | String code = XMLTree.searchNodeAtribute(node,"ows:OWSException","subcode"); |
485 | if (code == null) |
||
486 | return "0"; |
||
487 | return code;
|
||
488 | |||
489 | 3566 | jorpiell | } |
490 | 3213 | jorpiell | |
491 | 3566 | jorpiell | /**
|
492 | * Parses the SOAP-CSW Exceptions
|
||
493 | *
|
||
494 | *
|
||
495 | * @return
|
||
496 | * @param node
|
||
497 | */
|
||
498 | private boolean getSOAPExceptions(XMLNode node) { |
||
499 | 3213 | jorpiell | String msg = SOAPMessageParser.getFault(node);
|
500 | if (msg != null) { |
||
501 | driver.setServerAnswerReady(msg); |
||
502 | return true; |
||
503 | } |
||
504 | return false; |
||
505 | 3566 | jorpiell | } |
506 | } |