Revision 2658 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/drivers/CSWCatalogServiceDriver.java
CSWCatalogServiceDriver.java | ||
---|---|---|
1 | 1 |
package es.gva.cit.catalogClient.drivers; |
2 | 2 |
|
3 | 3 |
import java.net.URL; |
4 |
import java.util.StringTokenizer; |
|
4 | 5 |
|
5 | 6 |
import org.apache.commons.httpclient.NameValuePair; |
6 | 7 |
import org.w3c.dom.Node; |
7 | 8 |
|
8 | 9 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
10 |
import es.gva.cit.catalogClient.metadataXML.XMLTreeNumberOfRecordsAnswer; |
|
11 |
import es.gva.cit.catalogClient.parsers.SOAPMessageParser; |
|
9 | 12 |
import es.gva.cit.catalogClient.parsers.csw.cswCapabilitiesParser; |
10 | 13 |
import es.gva.cit.catalogClient.protocols.HTTPGetProtocol; |
11 | 14 |
import es.gva.cit.catalogClient.protocols.HTTPPostProtocol; |
... | ... | |
37 | 40 |
* java.lang.String) |
38 | 41 |
*/ |
39 | 42 |
public Node[] getCapabilities(URL url) { |
40 |
return new HTTPGetProtocol().doQuery(url, getMessageCapabilities(),0); |
|
43 |
|
|
44 |
Node[] nodos = new SOAPProtocol().doQuery(url,getSOAPMessageCapabilities(),0); |
|
45 |
if (nodos != null){ |
|
46 |
setCommunicationProtocol("SOAP"); |
|
47 |
return nodos; |
|
48 |
} |
|
49 |
|
|
50 |
nodos = new HTTPGetProtocol().doQuery(url, getMessageCapabilities(),0); |
|
51 |
if (nodos != null){ |
|
52 |
setCommunicationProtocol("GET"); |
|
53 |
return nodos; |
|
54 |
} |
|
55 |
|
|
56 |
nodos = new HTTPPostProtocol().doQuery(url,getMessageCapabilities(),0); |
|
57 |
if (nodos != null){ |
|
58 |
setCommunicationProtocol("POST"); |
|
59 |
return nodos; |
|
60 |
} |
|
61 |
|
|
62 |
return nodos; |
|
41 | 63 |
} |
42 | 64 |
|
43 | 65 |
/** |
... | ... | |
59 | 81 |
*/ |
60 | 82 |
public Node[] getRecords(URL url, Query query, int firstRecord) { |
61 | 83 |
setQuery(query); |
84 |
Node[] answerNodes = null; |
|
62 | 85 |
|
63 |
Node[] nodes = describeRecords(url); |
|
86 |
Node[] nodes = new SOAPProtocol().doQuery(url,getSOAPMessageRecords(getQuery()),firstRecord); |
|
87 |
if (nodes == null){ |
|
88 |
nodes = new HTTPPostProtocol().doQuery(url, getMessageCapabilities(),firstRecord); |
|
89 |
if (nodes == null){ |
|
90 |
nodes = new HTTPGetProtocol().doQuery(url, getMessageCapabilities(),firstRecord); |
|
91 |
if (nodes == null) |
|
92 |
return null; |
|
93 |
else{ |
|
94 |
setCommunicationProtocol("GET"); |
|
95 |
} |
|
96 |
}else{ |
|
97 |
setCommunicationProtocol("POST"); |
|
98 |
} |
|
99 |
}else{ |
|
100 |
setCommunicationProtocol("SOAP"); |
|
101 |
//We must cut the SOAP Head |
|
102 |
nodes[0] = SOAPMessageParser.cutHead(nodes[0]); |
|
103 |
} |
|
104 |
|
|
64 | 105 |
|
65 |
return new HTTPPostProtocol().doQuery(url, getMessageRecords(getQuery()),firstRecord); |
|
106 |
//Hay que capturar la excepci?n. |
|
107 |
int numberOfRecords = Integer.parseInt(XMLTree.searchNodeAtribute(nodes[0],"csw:SearchResults","numberOfRecordsMatched")); |
|
108 |
|
|
109 |
if (numberOfRecords > 10) |
|
110 |
answerNodes = new Node[11]; |
|
111 |
else |
|
112 |
answerNodes = new Node[numberOfRecords + 1]; |
|
113 |
|
|
114 |
answerNodes[0] = XMLTreeNumberOfRecordsAnswer.getNode(numberOfRecords, |
|
115 |
firstRecord, |
|
116 |
firstRecord + numberOfRecords ); |
|
117 |
|
|
118 |
|
|
119 |
nodes = XMLTree.searchMultipleNode(nodes[0],"csw:SearchResults->brief:MD_Metadata"); |
|
120 |
|
|
121 |
for (int i = 1; (i <= numberOfRecords) && (i <= 10) ; i++) |
|
122 |
answerNodes[i] = nodes[i-1]; |
|
123 |
|
|
124 |
return answerNodes; |
|
125 |
|
|
66 | 126 |
} |
67 | 127 |
|
68 | 128 |
|
... | ... | |
78 | 138 |
|
79 | 139 |
return new NameValuePair[]{nvp1,nvp2, nvp3}; |
80 | 140 |
} |
81 |
|
|
141 |
|
|
82 | 142 |
/** |
83 | 143 |
* |
84 | 144 |
* @return |
... | ... | |
105 | 165 |
NameValuePair nvp2= new NameValuePair("version",this.version); |
106 | 166 |
NameValuePair nvp3= new NameValuePair("service","CSW"); |
107 | 167 |
NameValuePair nvp4= new NameValuePair("outputformat",this.getOutputFormat()); |
168 |
System.out.println(this.getOutputFormat()); |
|
108 | 169 |
NameValuePair nvp5= new NameValuePair("outputschema",this.getOutputSchema()[0]); |
109 | 170 |
//NameValuePair nvp6= new NameValuePair("resulttype",this.getResultType()[0]); |
110 | 171 |
NameValuePair nvp7= new NameValuePair("namespace","csw:http://www.opengis.org/csw"); |
... | ... | |
119 | 180 |
} |
120 | 181 |
|
121 | 182 |
public String getSOAPMessageCapabilities(){ |
122 |
String soapMessage = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" + |
|
123 |
"<SOAP:Body>" + |
|
124 |
"<GetCapabilities service=\"CSW\">" + |
|
125 |
"<AcceptVersions>" + |
|
126 |
"<Version>" + version + "</Version>" + |
|
127 |
"</AcceptVersions>" + |
|
128 |
"<AcceptFormats>" + |
|
129 |
"<OutputFormat>text/xml</OutputFormat>" + |
|
130 |
"</AcceptFormats>" + |
|
131 |
"</GetCapabilities>" + |
|
132 |
"</SOAP:Body>" + |
|
133 |
"</SOAP:Envelope>"; |
|
134 |
return soapMessage; |
|
183 |
return "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" + |
|
184 |
"<SOAP:Body>" + |
|
185 |
"<csw:GetCapabilities service=\"CSW\" version=\"2.0.0\" "+ |
|
186 |
"xmlns:csw=\"http://www.opengis.net/cat/csw\" "+ |
|
187 |
"xmlns:ogc=\"http://www.opengis.net/ogc\">" + |
|
188 |
"<AcceptVersions xmlns=\"http://www.opengis.net/ows\">" + |
|
189 |
"<Version>" + version + "</Version>" + |
|
190 |
"</AcceptVersions>" + |
|
191 |
"<AcceptFormats xmlns=\"http://www.opengis.net/ows\">" + |
|
192 |
"<OutputFormat>text/xml</OutputFormat>" + |
|
193 |
"</AcceptFormats>" + |
|
194 |
"</csw:GetCapabilities>" + |
|
195 |
"</SOAP:Body>" + |
|
196 |
"</SOAP:Envelope>"; |
|
135 | 197 |
} |
136 | 198 |
|
199 |
public String getSOAPMessageDescribeRecords() { |
|
200 |
return "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" + |
|
201 |
"<SOAP:Body>" + |
|
202 |
"<csw:DescribeRecord " + |
|
203 |
"xmlns:csw=\"http://www.opengis.net/cat/csw\" " + |
|
204 |
"xmlns:ogc=\"http://www.opengis.net/ogc\" " + |
|
205 |
"service=\"CSW\" " + |
|
206 |
"version=" + version + " " + |
|
207 |
"outputFormat=\"test/xml\" " + |
|
208 |
"schemaLanguage=\"XMLSCHEMA\">" + |
|
209 |
"<csw:TypeName>csw:record</csw:TypeName>" + |
|
210 |
"</csw:DescribeRecord>" + |
|
211 |
"</SOAP:Body>" + |
|
212 |
"</SOAP:Envelope>"; |
|
213 |
|
|
214 |
} |
|
215 |
|
|
137 | 216 |
public String getSOAPMessageRecords(Query query) { |
138 |
return "<csw:GetRecords xmlns:ogc=\"http://www.opengis.net/ogc\"" +
|
|
139 |
" xmlns:csw=\"http://www.opengis.net/csw\"" +
|
|
140 |
" version=\"2.0.0\"" +
|
|
141 |
" service=\"CSW\"" +
|
|
142 |
" resultType=\"RESULTS\"" +
|
|
143 |
" outputFormat=\"text/xml\"" +
|
|
144 |
" outputSchema=\"Metadata\"" +
|
|
145 |
" startPosition=\"1\"" +
|
|
146 |
" maxRecords=\"20\"> " +
|
|
147 |
"<csw:Query typeName=\"Data\">" +
|
|
148 |
"<csw:ElementSetName>brief</csw:ElementSetName>" + |
|
149 |
"<csw:Constraint>" +
|
|
150 |
"<ogc:Filter_Capabilities>" +
|
|
151 |
"<ogc:PropertyIsLike>" +
|
|
152 |
"<ogc:PropertyName>title</ogc:PropertyName>" +
|
|
153 |
"<ogc:Literal>A</ogc:Literal>" +
|
|
154 |
"</ogc:PropertyIsLike>" +
|
|
155 |
"</ogc:Filter_Capabilities>" +
|
|
156 |
"</csw:Constraint>" +
|
|
157 |
"</csw:Query>" +
|
|
158 |
"</csw:GetRecords>"; |
|
217 |
CSWQuery cswq = new CSWQuery(query);
|
|
218 |
String cadena = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
|
|
219 |
"<SOAP:Body>" +
|
|
220 |
"<csw:GetRecords " +
|
|
221 |
"xmlns:csw=\"http://www.opengis.net/cat/csw\" " +
|
|
222 |
"xmlns:ogc=\"http://www.opengis.net/ogc\" " +
|
|
223 |
"service=\"CSW\" " +
|
|
224 |
"version=\"2.0.0\" "+
|
|
225 |
"resultType=\"results\">" +
|
|
226 |
"<csw:Query typeNames=\"Dataset\">" +
|
|
227 |
"<csw:ElementSetName>brief</csw:ElementSetName>" +
|
|
228 |
"<csw:Constraint version=\"2.0.0\">" +
|
|
229 |
cswq.getQuery() +
|
|
230 |
"</csw:Constraint>" +
|
|
231 |
"</csw:Query>" +
|
|
232 |
"</csw:GetRecords>" +
|
|
233 |
"</SOAP:Body>" +
|
|
234 |
"</SOAP:Envelope>";
|
|
235 |
System.out.println(cadena);
|
|
236 |
return cadena;
|
|
237 |
|
|
159 | 238 |
} |
160 | 239 |
|
161 | 240 |
|
Also available in: Unified diff