Revision 3510 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/srw/drivers/SRWCatalogServiceDriver.java
SRWCatalogServiceDriver.java | ||
---|---|---|
47 | 47 |
import es.gva.cit.catalogClient.protocols.HTTPGetProtocol; |
48 | 48 |
import es.gva.cit.catalogClient.protocols.SOAPProtocol; |
49 | 49 |
import es.gva.cit.catalogClient.querys.Query; |
50 |
import es.gva.cit.catalogClient.srw.filters.SRWFilter; |
|
51 | 50 |
import es.gva.cit.catalogClient.srw.parsers.SrwCapabilitiesParser; |
52 | 51 |
|
53 |
import org.apache.commons.httpclient.NameValuePair; |
|
54 |
|
|
55 | 52 |
import java.net.URL; |
56 | 53 |
|
57 | 54 |
import java.util.StringTokenizer; |
... | ... | |
70 | 67 |
* @see ICatalogServerDriver#GetCapabilities(java.lang.String, java.lang.String) |
71 | 68 |
*/ |
72 | 69 |
public XMLNode[] getCapabilities(URL url) { |
70 |
SRWMessages messages = new SRWMessages(this); |
|
71 |
|
|
73 | 72 |
XMLNode[] nodos = new HTTPGetProtocol().doQuery(url, |
74 |
getMessageCapabilities(), 0);
|
|
73 |
messages.getHTTPGETCapabilities(true), 0);
|
|
75 | 74 |
|
76 | 75 |
if (nodos != null) { |
77 | 76 |
setCommunicationProtocol("GET"); |
... | ... | |
79 | 78 |
return nodos; |
80 | 79 |
} |
81 | 80 |
|
82 |
nodos = new SOAPProtocol().doQuery(url, getSOAPMessageCapabilities(), 0);
|
|
81 |
nodos = new SOAPProtocol().doQuery(url, messages.getSOAPCapabilities(), 0);
|
|
83 | 82 |
|
84 | 83 |
if (nodos != null) { |
85 | 84 |
setCommunicationProtocol("SOAP"); |
... | ... | |
93 | 92 |
*/ |
94 | 93 |
public XMLNode[] getRecords(URL url, Query query, int firstRecord) { |
95 | 94 |
setQuery(query); |
95 |
SRWMessages messages = new SRWMessages(this); |
|
96 | 96 |
|
97 | 97 |
XMLNode[] answerNodes = null; |
98 | 98 |
XMLNode[] nodes = null; |
99 | 99 |
|
100 | 100 |
if (getCommunicationProtocol().equals("GET")) { |
101 | 101 |
nodes = new HTTPGetProtocol().doQuery(url, |
102 |
getMessageRecords(getQuery(), firstRecord), firstRecord);
|
|
102 |
messages.getHTTPGETRecords(getQuery(), firstRecord), firstRecord);
|
|
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
if (getCommunicationProtocol().equals("POST") || |
106 | 106 |
getCommunicationProtocol().equals("SOAP")){ |
107 | 107 |
nodes = new SOAPProtocol().doQuery(url, |
108 |
getMessageRecords(getQuery(), firstRecord), firstRecord);
|
|
108 |
messages.getSOAPRecords(getQuery(), firstRecord), firstRecord);
|
|
109 | 109 |
} |
110 | 110 |
|
111 | 111 |
String prefix = new StringTokenizer(nodes[0].getName(), ":").nextToken(); |
... | ... | |
149 | 149 |
public XMLNode[] createAnswerTree(int numberOfRecords, int firstRecord, |
150 | 150 |
XMLNode node, URL url,String prefix) { |
151 | 151 |
XMLNode[] answerNodes = null; |
152 |
|
|
152 |
|
|
153 | 153 |
if (numberOfRecords > 10) { |
154 | 154 |
answerNodes = new XMLNode[11]; |
155 | 155 |
} else { |
... | ... | |
168 | 168 |
answerNodes[i] = auxNodes[i - 1]; |
169 | 169 |
|
170 | 170 |
return answerNodes; |
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* It creates the name-value pairs for the getCapabilities request |
|
175 |
* @return |
|
176 |
* Name-Value pair array |
|
177 |
*/ |
|
178 |
public NameValuePair[] getMessageCapabilities() { |
|
179 |
NameValuePair nvp1 = new NameValuePair("OPERATION", "explain"); |
|
180 |
NameValuePair nvp2 = new NameValuePair("VERSION", this.version); |
|
171 |
} |
|
172 |
|
|
181 | 173 |
|
182 |
return new NameValuePair[] { nvp1, nvp2 }; |
|
183 |
} |
|
184 |
|
|
185 | 174 |
/** |
186 |
* It creates the name-value pairs for the getRecords request |
|
187 |
* @return |
|
188 |
* Name-Value pair array |
|
189 |
*/ |
|
190 |
public NameValuePair[] getMessageRecords(Query query, int firstRecord) { |
|
191 |
SRWFilter qsrwd = new SRWFilter(query); |
|
192 |
|
|
193 |
NameValuePair nvp1 = new NameValuePair("operation", "searchRetrieve"); |
|
194 |
NameValuePair nvp2 = new NameValuePair("version", this.version); |
|
195 |
NameValuePair nvp3 = new NameValuePair("query", qsrwd.getQuery(null)); |
|
196 |
NameValuePair nvp4 = new NameValuePair("maximumRecords", "10"); |
|
197 |
NameValuePair nvp5 = new NameValuePair("recordPacking", |
|
198 |
getOutputFormat()); |
|
199 |
NameValuePair nvp6 = new NameValuePair("startRecord", |
|
200 |
new String(new Integer(firstRecord).toString())); |
|
201 |
|
|
202 |
return new NameValuePair[] { nvp1, nvp2, nvp3, nvp4, nvp5, nvp6 }; |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* It creates the SOAP message for the getCapabilities request |
|
207 |
* |
|
208 |
* @return |
|
209 |
* String with the SOAP message |
|
210 |
*/ |
|
211 |
public String getSOAPMessageCapabilities() { |
|
212 |
String soapMessage = |
|
213 |
"<SRW:explainRequest xmlns:SRW=\"http://www.loc.gov/zing/srw/\">" + |
|
214 |
"<SRW:version>" + version + "</SRW:version>" + |
|
215 |
"</SRW:explainRequest>"; |
|
216 |
|
|
217 |
return SOAPProtocol.setSOAPMessage(soapMessage,null); |
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* It creates the SOAP message for the getRecords request |
|
222 |
* |
|
223 |
* @return |
|
224 |
* String with the SOAP message |
|
225 |
*/ |
|
226 |
public String getSOAPMessageRecords(Query query) { |
|
227 |
SRWFilter qsrwd = new SRWFilter(query); |
|
228 |
|
|
229 |
String soapMessage = |
|
230 |
"<srw:searchRetrieveRequest xmlns:srw=\"http://www.loc.gov/zing/srw/\">" + |
|
231 |
"<srw:query><![CDATA[" + qsrwd.getQuery(null) + "]]></srw:query>" + |
|
232 |
"<srw:sortKeys xsi:nil=\"true\"/>" + "<srw:startRecord>" + |
|
233 |
getStartPosition() + "</srw:startRecord>" + "<srw:maximumRecords>" + |
|
234 |
getMaxRecords() + "</srw:maximumRecords>" + "<srw:recordPacking>" + |
|
235 |
getOutputFormat() + "</srw:recordPacking>" + "<srw:recordSchema>" + |
|
236 |
getOutputSchema()[0] + "</srw:recordSchema>" + |
|
237 |
"<srw:resultSetTTL>" + getResultSetTTL() + "</srw:resultSetTTL>" + |
|
238 |
"</srw:searchRetrieveRequest>"; |
|
239 |
|
|
240 |
return SOAPProtocol.setSOAPMessage(soapMessage,null); |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 | 175 |
* @return Returns the recordXPath. |
245 | 176 |
*/ |
246 | 177 |
public String getRecordXPath() { |
Also available in: Unified diff