root / branches / v10 / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / csw / drivers / CSWebRIMCatalogServiceDriver.java @ 16004
History | View | Annotate | Download (3.88 KB)
1 |
package es.gva.cit.catalog.csw.drivers; |
---|---|
2 |
|
3 |
import java.net.MalformedURLException; |
4 |
import java.net.URL; |
5 |
|
6 |
import org.apache.commons.httpclient.NameValuePair; |
7 |
|
8 |
import es.gva.cit.catalog.csw.drivers.profiles.CSWebRIMProfile; |
9 |
import es.gva.cit.catalog.csw.parsers.CSWConstants; |
10 |
import es.gva.cit.catalog.drivers.profiles.IProfile; |
11 |
import es.gva.cit.catalog.metadataxml.XMLNode; |
12 |
import es.gva.cit.catalog.protocols.HTTPGetProtocol; |
13 |
|
14 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
15 |
*
|
16 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
17 |
*
|
18 |
* This program is free software; you can redistribute it and/or
|
19 |
* modify it under the terms of the GNU General Public License
|
20 |
* as published by the Free Software Foundation; either version 2
|
21 |
* of the License, or (at your option) any later version.
|
22 |
*
|
23 |
* This program is distributed in the hope that it will be useful,
|
24 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
26 |
* GNU General Public License for more details.
|
27 |
*
|
28 |
* You should have received a copy of the GNU General Public License
|
29 |
* along with this program; if not, write to the Free Software
|
30 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
31 |
*
|
32 |
* For more information, contact:
|
33 |
*
|
34 |
* Generalitat Valenciana
|
35 |
* Conselleria d'Infraestructures i Transport
|
36 |
* Av. Blasco Ib??ez, 50
|
37 |
* 46010 VALENCIA
|
38 |
* SPAIN
|
39 |
*
|
40 |
* +34 963862235
|
41 |
* gvsig@gva.es
|
42 |
* www.gvsig.gva.es
|
43 |
*
|
44 |
* or
|
45 |
*
|
46 |
* IVER T.I. S.A
|
47 |
* Salamanca 50
|
48 |
* 46005 Valencia
|
49 |
* Spain
|
50 |
*
|
51 |
* +34 963163400
|
52 |
* dac@iver.es
|
53 |
*/
|
54 |
/* CVS MESSAGES:
|
55 |
*
|
56 |
* $Id$
|
57 |
* $Log$
|
58 |
*
|
59 |
*/
|
60 |
/**
|
61 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
62 |
*/
|
63 |
public class CSWebRIMCatalogServiceDriver extends CSWCatalogServiceDriver{ |
64 |
public static String SERVICE_NAME = "CSW/ebRIM"; |
65 |
|
66 |
/*
|
67 |
* (non-Javadoc)
|
68 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getServiceName()
|
69 |
*/
|
70 |
public String getServiceName() { |
71 |
return SERVICE_NAME;
|
72 |
} |
73 |
|
74 |
/*
|
75 |
* (non-Javadoc)
|
76 |
* @see es.gva.cit.catalog.drivers.AbstractCatalogServiceDriver#getProfile()
|
77 |
*/
|
78 |
public IProfile getProfile() {
|
79 |
return new CSWebRIMProfile(); |
80 |
} |
81 |
|
82 |
/*
|
83 |
* (non-Javadoc)
|
84 |
* @see es.gva.cit.catalog.csw.drivers.CSWCatalogServiceDriver#retrieveResults(es.gva.cit.catalog.metadataxml.XMLNode)
|
85 |
*/
|
86 |
protected XMLNode[] retrieveResults(XMLNode root) { |
87 |
XMLNode resultNode = root.searchNode(CSWConstants.SEARCH_RESULTS); |
88 |
if (resultNode == null){ |
89 |
return new XMLNode[0]; |
90 |
} |
91 |
XMLNode[] results = new XMLNode[resultNode.getNumSubNodes()]; |
92 |
for (int i=0 ; i<resultNode.getNumSubNodes() ; i++){ |
93 |
results[i] = resultNode.getSubNode(i); |
94 |
} |
95 |
return getEbRIMNodes(results);
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* This function retrieve the nodes for one ebRIM answer
|
100 |
* @return Medatada Nodes.
|
101 |
* @param nodes Server URL
|
102 |
* @param url
|
103 |
*/
|
104 |
private XMLNode[] getEbRIMNodes(XMLNode[] nodes) { |
105 |
//if the getExtrinsincContentOperation is not supported
|
106 |
if (capabilities.getOperations().getGetExtrinsicContent().size() == 0){ |
107 |
return nodes;
|
108 |
} |
109 |
XMLNode[] auxNodes = new XMLNode[nodes.length]; |
110 |
for (int i = 0; i < nodes.length; i++) { |
111 |
String id = nodes[i].searchAtribute(CSWConstants.ID);
|
112 |
String sUrl = nodes[i].searchAtribute(CSWConstants.HOME);
|
113 |
URL url;
|
114 |
try {
|
115 |
url = new URL(sUrl); |
116 |
auxNodes[i] = (XMLNode)new HTTPGetProtocol().doQuery(url,
|
117 |
getEbRIMRequestParameters(id), 0).toArray()[0]; |
118 |
} catch (MalformedURLException e) { |
119 |
//Impossible to retrieve the record
|
120 |
} |
121 |
} |
122 |
return auxNodes;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* It Returns the parameters needed by getExtrinsicContent
|
127 |
* @return
|
128 |
* @param id Record id
|
129 |
*/
|
130 |
private NameValuePair[] getEbRIMRequestParameters(String id) { |
131 |
NameValuePair nvp1 = new NameValuePair(CSWConstants.REQUEST, CSWConstants.EXTRISIC_CONTENT);
|
132 |
NameValuePair nvp2 = new NameValuePair(CSWConstants.ID, id);
|
133 |
return new NameValuePair[] { nvp1, nvp2 }; |
134 |
} |
135 |
} |