gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.lib / src / main / java / org / gvsig / catalog / csw / parsers / CSWCapabilitiesParser.java @ 55
History | View | Annotate | Download (10.3 KB)
1 |
package org.gvsig.catalog.csw.parsers; |
---|---|
2 |
|
3 |
import java.net.MalformedURLException; |
4 |
import java.net.URL; |
5 |
import java.util.HashMap; |
6 |
|
7 |
import org.gvsig.catalog.csw.drivers.CSWCapabilities; |
8 |
import org.gvsig.catalog.csw.drivers.CSWCatalogServiceDriver; |
9 |
import org.gvsig.catalog.metadataxml.XMLNode; |
10 |
import org.gvsig.catalog.metadataxml.XMLTree; |
11 |
import org.gvsig.catalog.utils.Strings; |
12 |
|
13 |
|
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id: CSWCapabilitiesParserv2_0_1.java,v 1.1.2.1 2007/07/23 07:14:24 jorpiell Exp $
|
58 |
* $Log: CSWCapabilitiesParserv2_0_1.java,v $
|
59 |
* Revision 1.1.2.1 2007/07/23 07:14:24 jorpiell
|
60 |
* Catalog refactoring
|
61 |
*
|
62 |
*
|
63 |
*/
|
64 |
/**
|
65 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
66 |
*/
|
67 |
public class CSWCapabilitiesParser{ |
68 |
private URL url = null; |
69 |
private CSWCatalogServiceDriver driver = null; |
70 |
private CSWCapabilities capabilities = null; |
71 |
|
72 |
public CSWCapabilitiesParser(URL url, CSWCatalogServiceDriver driver) { |
73 |
this.url = url;
|
74 |
this.driver = driver;
|
75 |
} |
76 |
|
77 |
/*
|
78 |
* (non-Javadoc)
|
79 |
* @see es.gva.cit.catalogClient.csw.parsers.CSWAbstractCapabilitiesParser#parse(es.gva.cit.catalogClient.metadataxml.XMLNode)
|
80 |
*/
|
81 |
public CSWCapabilities parse(XMLNode node) {
|
82 |
capabilities = new CSWCapabilities(url);
|
83 |
if (node.getName().endsWith(CSWConstants.SERVICE_EXPECTION_REPORT)){
|
84 |
capabilities.setException(CSWExceptionParser.parse(node)); |
85 |
capabilities.setAvailable(false);
|
86 |
capabilities.setServerMessage(node.getXmlTree()); |
87 |
} |
88 |
parseHeaderAttributes(node); |
89 |
parseServiceIdentification(node.searchNode(CSWConstants.SERVICE_IDENTIFICATION)); |
90 |
parseServiceProvider(node.searchNode(CSWConstants.SERVICE_PROVIDER)); |
91 |
parseOperationsMetadata(node.searchNode(CSWConstants.OPERATIONS_METADATA)); |
92 |
return capabilities;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Parse the header attributes
|
97 |
*/
|
98 |
private void parseHeaderAttributes(XMLNode node){ |
99 |
capabilities.setVersion(node.searchAtribute(CSWConstants.VERSION)); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Parse the service identification tag
|
104 |
* @param node
|
105 |
*/
|
106 |
private void parseServiceIdentification(XMLNode node){ |
107 |
if (node != null){ |
108 |
XMLNode title = node.searchNode(CSWConstants.TITLE); |
109 |
XMLNode abstract_ = node.searchNode(CSWConstants.ABSTRACT); |
110 |
String sTitle = ""; |
111 |
if (title != null){ |
112 |
sTitle = title.getText() + "\n";
|
113 |
} |
114 |
if (abstract_ != null){ |
115 |
sTitle = sTitle + abstract_.getText(); |
116 |
} |
117 |
driver.setServerAnswerReady(sTitle); |
118 |
capabilities.setServerMessage(sTitle); |
119 |
XMLNode version = node.searchNode(CSWConstants.SERVICE_TYPE_VERSION); |
120 |
if (version != null){ |
121 |
capabilities.setVersion(version.getText()); |
122 |
} |
123 |
|
124 |
} |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Parse the service provider tag
|
129 |
* @param node
|
130 |
*/
|
131 |
private void parseServiceProvider(XMLNode node){ |
132 |
if (node != null){ |
133 |
|
134 |
} |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Parse the operations metadata tag
|
139 |
* @param node
|
140 |
*/
|
141 |
private void parseOperationsMetadata(XMLNode node){ |
142 |
if (node != null){ |
143 |
XMLNode[] operations = XMLTree.searchMultipleNode(node, CSWConstants.OPERATION);
|
144 |
for (int i = 0; i < operations.length; i++) { |
145 |
String sOperation = XMLTree.searchAtribute(operations[i], "name"); |
146 |
|
147 |
if (sOperation.equals(CSWConstants.OPERATION_GETCAPABILITIES)){
|
148 |
parseCapabilities(operations[i]); |
149 |
} |
150 |
if (sOperation.equals(CSWConstants.OPERATION_DESCRIBERECORD)){
|
151 |
parseDescribeRecord(operations[i]); |
152 |
} |
153 |
if (sOperation.equals(CSWConstants.OPERATION_GETDOMAIN)){
|
154 |
parseGetDomain(operations[i]); |
155 |
} |
156 |
if (sOperation.equals(CSWConstants.OPERATION_GETRECORDS)){
|
157 |
parseGetRecords(operations[i]); |
158 |
} |
159 |
if (sOperation.equals(CSWConstants.OPERATION_GETRECORDSBYID)){
|
160 |
parseGetRecordsByID(operations[i]); |
161 |
} |
162 |
if (sOperation.equals(CSWConstants.OPERATION_TRANSACTION)){
|
163 |
parseTransaction(operations[i]); |
164 |
} |
165 |
if (sOperation.equals(CSWConstants.OPERATION_HARVEST)){
|
166 |
parseHarvest(operations[i]); |
167 |
} |
168 |
} |
169 |
//Patch for the Galdos severs
|
170 |
if (capabilities.getVersion().equals(CSWConstants.VERSION_0_9_0)){
|
171 |
capabilities.getOperations().getGetExtrinsicContent().put( |
172 |
CSWConstants.GET,url); |
173 |
} |
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Parse the capabilitioes operation
|
179 |
* @param node
|
180 |
*/
|
181 |
private void parseCapabilities(XMLNode node) { |
182 |
capabilities.getOperations().setGetCapabilities(getSupportedProtocols(node)); |
183 |
XMLNode[] parameters = XMLTree.searchMultipleNode(node, CSWConstants.PARAMETER);
|
184 |
for (int i = 0; i < parameters.length; i++) { |
185 |
String sParameter = XMLTree.searchAtribute(parameters[i], CSWConstants.PARAMETER_NAME);
|
186 |
String[] values = XMLTree.searchMultipleNodeValue(parameters[i], CSWConstants.PARAMETER_VALUE); |
187 |
if ((sParameter.toLowerCase().equals(CSWConstants.VERSION)) &&
|
188 |
(values != null) &&
|
189 |
values.length == 1){
|
190 |
capabilities.setVersion(values[0]);
|
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
/**
|
196 |
* It parses the describe record operation
|
197 |
* @param node
|
198 |
* @param prefix
|
199 |
*/
|
200 |
private void parseDescribeRecord(XMLNode node) { |
201 |
capabilities.getOperations().setDescribeRecords(getSupportedProtocols(node)); |
202 |
XMLNode[] parameters = XMLTree.searchMultipleNode(node, CSWConstants.PARAMETER);
|
203 |
for (int i = 0; i < parameters.length; i++) { |
204 |
String sParameter = XMLTree.searchAtribute(parameters[i], CSWConstants.PARAMETER_NAME);
|
205 |
String[] values = XMLTree.searchMultipleNodeValue(parameters[i], CSWConstants.PARAMETER_VALUE); |
206 |
if ((sParameter.equals(CSWConstants.TYPENAME)) &&
|
207 |
(values != null)){
|
208 |
capabilities.setTypeNames(values); |
209 |
} |
210 |
} |
211 |
} |
212 |
|
213 |
/**
|
214 |
* It parses the getRecordsByID operation
|
215 |
* @param node
|
216 |
* @param prefix
|
217 |
*/
|
218 |
private void parseGetRecordsByID(XMLNode node) { |
219 |
capabilities.getOperations().setGetRecordsById(getSupportedProtocols(node)); |
220 |
} |
221 |
|
222 |
/**
|
223 |
* It parses the getDomain operation
|
224 |
* @param node
|
225 |
* @param prefix
|
226 |
*/
|
227 |
private void parseGetDomain(XMLNode node) { |
228 |
capabilities.getOperations().setGetDomain(getSupportedProtocols(node)); |
229 |
} |
230 |
|
231 |
/**
|
232 |
* It parses the getRecords operation
|
233 |
* @param node
|
234 |
* @param prefix
|
235 |
*/
|
236 |
private void parseGetRecords(XMLNode node){ |
237 |
capabilities.getOperations().setGetRecords(getSupportedProtocols(node)); |
238 |
XMLNode[] parameters = XMLTree.searchMultipleNode(node, CSWConstants.PARAMETER);
|
239 |
for (int i = 0; i < parameters.length; i++) { |
240 |
String sParameter = XMLTree.searchAtribute(parameters[i], CSWConstants.PARAMETER_NAME);
|
241 |
String[] values = XMLTree.searchMultipleNodeValue(parameters[i], CSWConstants.PARAMETER_VALUE); |
242 |
String[] defaultValue = XMLTree.searchMultipleNodeValue(parameters[i], CSWConstants.DEFAULTVALUE); |
243 |
if (sParameter.equals("TypeName")) { |
244 |
capabilities.setTypeNames(Strings.join(defaultValue, values)); |
245 |
} |
246 |
if (sParameter.equals(CSWConstants.OUTPUTFORMAT)) {
|
247 |
if (!(Strings.find(CSWConstants.TEXT_XML, defaultValue) ||
|
248 |
Strings.find(CSWConstants.TEXT_XML, values))) { |
249 |
if (!(Strings.find(CSWConstants.APPLICATION_XML, defaultValue) ||
|
250 |
Strings.find(CSWConstants.APPLICATION_XML, values))) { |
251 |
capabilities.setServerMessage("El servidor no devuelve " +
|
252 |
"texto en formato XML");
|
253 |
return;
|
254 |
} |
255 |
} |
256 |
} |
257 |
driver.setOutputFormat(CSWConstants.TEXT_XML); |
258 |
if (sParameter.equals(CSWConstants.OUTPUTSCHEMA)) {
|
259 |
driver.setOutputSchema(Strings.join(defaultValue, values)); |
260 |
} |
261 |
|
262 |
|
263 |
if (sParameter.equals(CSWConstants.RESULTTYPE)) {
|
264 |
capabilities.setResultType(Strings.join(defaultValue, values)); |
265 |
} |
266 |
if (sParameter.equals(CSWConstants.ELEMENTSETNAME)) {
|
267 |
capabilities.setElementSetName(Strings.join(defaultValue, values)); |
268 |
} |
269 |
if (sParameter.equals(CSWConstants.CONSTRAINTLANGUAGE)) {
|
270 |
capabilities.setCONSTRAINTLANGUAGE(Strings.join(defaultValue, values)); |
271 |
for (int j = 0; j < capabilities.getCONSTRAINTLANGUAGE().length; |
272 |
j++) { |
273 |
if (capabilities.getCONSTRAINTLANGUAGE()[j].toUpperCase().equals("FILTER")) { |
274 |
break;
|
275 |
} else {
|
276 |
capabilities.setServerMessage("errorFENotSupported");
|
277 |
|
278 |
} |
279 |
} |
280 |
} |
281 |
} |
282 |
} |
283 |
|
284 |
/**
|
285 |
* * It parses the Transaction operation
|
286 |
* @param node
|
287 |
* @param prefix
|
288 |
*/
|
289 |
private void parseTransaction(XMLNode node) { |
290 |
capabilities.getOperations().setTransaction(getSupportedProtocols(node)); |
291 |
} |
292 |
|
293 |
/**
|
294 |
* It parses the Harvest operation
|
295 |
* @param node
|
296 |
* @param prefix
|
297 |
*/
|
298 |
private void parseHarvest(XMLNode node) { |
299 |
capabilities.getOperations().setHarvest(getSupportedProtocols(node)); |
300 |
} |
301 |
|
302 |
/**
|
303 |
* This function returns the supported protocols of an operation
|
304 |
* defined by node.
|
305 |
* @return
|
306 |
* @param node Node that contains the operation information
|
307 |
*/
|
308 |
private HashMap getSupportedProtocols(XMLNode node) { |
309 |
HashMap operations = new HashMap(); |
310 |
|
311 |
XMLNode protocols = XMLTree.searchNode(node, CSWConstants.DCP); |
312 |
|
313 |
XMLNode HTTPoperations = XMLTree.searchNode(protocols,CSWConstants.HTTP); |
314 |
XMLNode[] childNodes = HTTPoperations.getSubnodes();
|
315 |
for (int i=0 ; i<childNodes.length ; i++){ |
316 |
String sUrl = XMLTree.searchAtribute(childNodes[i],CSWConstants.XLINK_HREF);
|
317 |
URL url = null; |
318 |
try {
|
319 |
url = new URL(sUrl); |
320 |
if ((childNodes[i].getName().endsWith(CSWConstants.GET))){
|
321 |
operations.put(CSWConstants.GET, |
322 |
url); |
323 |
} |
324 |
if ((childNodes[i].getName().endsWith(CSWConstants.POST))){
|
325 |
operations.put(CSWConstants.POST, |
326 |
url); |
327 |
} |
328 |
|
329 |
} catch (MalformedURLException e) { |
330 |
//The URL can be added
|
331 |
} |
332 |
} |
333 |
return operations;
|
334 |
} |
335 |
} |