svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / drivers / SRWCatalogServiceDriver.java @ 2658
History | View | Annotate | Download (7.21 KB)
1 |
package es.gva.cit.catalogClient.drivers; |
---|---|
2 |
|
3 |
import java.net.URL; |
4 |
import java.util.StringTokenizer; |
5 |
|
6 |
import org.apache.commons.httpclient.NameValuePair; |
7 |
import org.w3c.dom.Node; |
8 |
|
9 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
10 |
import es.gva.cit.catalogClient.metadataXML.XMLTreeNumberOfRecordsAnswer; |
11 |
import es.gva.cit.catalogClient.protocols.HTTPGetProtocol; |
12 |
import es.gva.cit.catalogClient.protocols.HTTPPostProtocol; |
13 |
import es.gva.cit.catalogClient.protocols.SOAPProtocol; |
14 |
import es.gva.cit.catalogClient.querys.Query; |
15 |
import es.gva.cit.catalogClient.querys.SRWQuery; |
16 |
|
17 |
|
18 |
/* Generated by Together */
|
19 |
|
20 |
public class SRWCatalogServiceDriver extends AbstractCatalogServiceDriver { |
21 |
private String version = "1.1"; |
22 |
private String recordXPath; |
23 |
private String resultSetTTL; |
24 |
/* (non-Javadoc)
|
25 |
* @see ICatalogServerDriver#GetCapabilities(java.lang.String, java.lang.String)
|
26 |
*/
|
27 |
|
28 |
|
29 |
public Node[] getCapabilities(URL url){ |
30 |
|
31 |
Node[] nodos = new HTTPGetProtocol().doQuery(url,getMessageCapabilities(),0); |
32 |
if (nodos != null){ |
33 |
setCommunicationProtocol("GET");
|
34 |
return nodos;
|
35 |
} |
36 |
|
37 |
nodos = new HTTPPostProtocol().doQuery(url,getMessageCapabilities(),0); |
38 |
if (nodos != null){ |
39 |
setCommunicationProtocol("POST");
|
40 |
return nodos;
|
41 |
} |
42 |
|
43 |
nodos = new SOAPProtocol().doQuery(url,getSOAPMessageCapabilities(),0); |
44 |
if (nodos != null){ |
45 |
setCommunicationProtocol("SOAP");
|
46 |
} |
47 |
|
48 |
return nodos;
|
49 |
} |
50 |
|
51 |
/* (non-Javadoc)
|
52 |
* @see ICatalogServerDriver#GetRecords(java.lang.String, java.lang.String, java.lang.String, int, int, java.lang.String, java.lang.String)
|
53 |
*/
|
54 |
public Node[] getRecords(URL url ,Query query, int firstRecord) { |
55 |
setQuery(query); |
56 |
Node[] answerNodes = null; |
57 |
Node[] nodes = null; |
58 |
|
59 |
if (getCommunicationProtocol().equals("GET")) |
60 |
nodes = new HTTPGetProtocol().doQuery(url,getMessageRecords(getQuery(),firstRecord),firstRecord);
|
61 |
if (getCommunicationProtocol().equals("POST")) |
62 |
nodes = new HTTPPostProtocol().doQuery(url,getMessageRecords(getQuery(),firstRecord),firstRecord);
|
63 |
if (getCommunicationProtocol().equals("SOAP")) |
64 |
nodes = new SOAPProtocol().doQuery(url,getMessageRecords(getQuery(),firstRecord),firstRecord);
|
65 |
|
66 |
String prefix = new StringTokenizer(nodes[0].getNodeName(),":").nextToken(); |
67 |
if (prefix.equals(nodes[0].getNodeName())) |
68 |
prefix = "";
|
69 |
else
|
70 |
prefix = prefix + ":";
|
71 |
|
72 |
//Hay que capturar la excepci?n.
|
73 |
int numberOfRecords = Integer.parseInt(XMLTree.searchNodeValue(nodes[0],prefix + "numberOfRecords")); |
74 |
|
75 |
if (numberOfRecords > 10) |
76 |
answerNodes = new Node[11]; |
77 |
else
|
78 |
answerNodes = new Node[numberOfRecords + 1]; |
79 |
|
80 |
answerNodes[0] = XMLTreeNumberOfRecordsAnswer.getNode(numberOfRecords,
|
81 |
firstRecord, |
82 |
firstRecord + numberOfRecords ); |
83 |
|
84 |
nodes = XMLTree.searchMultipleNode(nodes[0],prefix + "records->" + prefix + "record"); |
85 |
|
86 |
for (int i = 1; (i <= numberOfRecords) && (i <= 10) ; i++) |
87 |
answerNodes[i] = nodes[i-1];
|
88 |
|
89 |
return answerNodes;
|
90 |
} |
91 |
|
92 |
public NameValuePair[] getMessageCapabilities(){ |
93 |
NameValuePair nvp1= new NameValuePair("OPERATION","explain"); |
94 |
NameValuePair nvp2= new NameValuePair("VERSION",this.version); |
95 |
return new NameValuePair[]{nvp1,nvp2}; |
96 |
} |
97 |
|
98 |
public NameValuePair[] getMessageRecords(Query query,int firstRecord){ |
99 |
SRWQuery qsrwd = new SRWQuery(query);
|
100 |
|
101 |
NameValuePair nvp1= new NameValuePair("operation","searchRetrieve"); |
102 |
NameValuePair nvp2= new NameValuePair("version",this.version); |
103 |
NameValuePair nvp3= new NameValuePair("query",qsrwd.getQuery()); |
104 |
NameValuePair nvp4= new NameValuePair("maximumRecords","10"); |
105 |
NameValuePair nvp5= new NameValuePair("recordPacking",getOutputFormat() ); |
106 |
NameValuePair nvp6= new NameValuePair("startRecord",new String(new Integer(firstRecord).toString())); |
107 |
|
108 |
return new NameValuePair[]{nvp1,nvp2,nvp3,nvp4,nvp5,nvp6}; |
109 |
} |
110 |
|
111 |
public String getSOAPMessageCapabilities(){ |
112 |
String soapMessage = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" + |
113 |
"<SOAP:Body><SRW:explainRequest xmlns:SRW=\"http://www.loc.gov/zing/srw/\">" +
|
114 |
"<SRW:version>" + version + "</SRW:version>" + |
115 |
"</SRW:explainRequest>" +
|
116 |
"</SOAP:Body>" +
|
117 |
"</SOAP:Envelope>";
|
118 |
return soapMessage;
|
119 |
} |
120 |
|
121 |
public String getSOAPMessageRecords(Query query){ |
122 |
SRWQuery qsrwd = new SRWQuery(query);
|
123 |
|
124 |
String soapMessage = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> <soap:Body>" + |
125 |
"<srw:searchRetrieveRequest xmlns:srw=\"http://www.loc.gov/zing/srw/\">" +
|
126 |
"<srw:query><![CDATA[" + qsrwd.getQuery() + "]]></srw:query>" + |
127 |
"<srw:sortKeys xsi:nil=\"true\"/>" +
|
128 |
"<srw:startRecord>" + getStartPosition() + "</srw:startRecord>" + |
129 |
"<srw:maximumRecords>" + getMaxRecords() + "</srw:maximumRecords>" + |
130 |
"<srw:recordPacking>" + getOutputFormat() + "</srw:recordPacking>" + |
131 |
"<srw:recordSchema>" + getOutputSchema()[0] + "</srw:recordSchema>" + |
132 |
"<srw:resultSetTTL>" + getResultSetTTL() + "</srw:resultSetTTL>" + |
133 |
"</srw:searchRetrieveRequest>" +
|
134 |
"</soap:Body></soap:Envelope>";
|
135 |
|
136 |
return soapMessage;
|
137 |
} |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
/**
|
143 |
* @return Returns the recordXPath.
|
144 |
*/
|
145 |
public String getRecordXPath() { |
146 |
return recordXPath;
|
147 |
} |
148 |
/**
|
149 |
* @param recordXPath The recordXPath to set.
|
150 |
*/
|
151 |
public void setRecordXPath(String recordXPath) { |
152 |
this.recordXPath = recordXPath;
|
153 |
} |
154 |
/**
|
155 |
* @return Returns the resultSetTTL.
|
156 |
*/
|
157 |
public String getResultSetTTL() { |
158 |
return resultSetTTL;
|
159 |
} |
160 |
/**
|
161 |
* @param resultSetTTL The resultSetTTL to set.
|
162 |
*/
|
163 |
public void setResultSetTTL(String resultSetTTL) { |
164 |
this.resultSetTTL = resultSetTTL;
|
165 |
} |
166 |
/**
|
167 |
* @return Returns the version.
|
168 |
*/
|
169 |
public String getVersion() { |
170 |
return version;
|
171 |
} |
172 |
/**
|
173 |
* @param version The version to set.
|
174 |
*/
|
175 |
public void setVersion(String version) { |
176 |
this.version = version;
|
177 |
} |
178 |
/* (non-Javadoc)
|
179 |
* @see catalogClient.ICatalogServerDriver#ServerReady(java.lang.String, int)
|
180 |
*/
|
181 |
|
182 |
/* (non-Javadoc)
|
183 |
* @see catalogClient.ICatalogServerDriver#setParameters(java.util.Properties)
|
184 |
*/
|
185 |
public boolean setParameters(Node[] nodes) { |
186 |
if (nodes[0].getNodeName() != null){ |
187 |
String prefix = new StringTokenizer(nodes[0].getNodeName(),":").nextToken(); |
188 |
prefix = prefix + ":";
|
189 |
this.setOutputSchema(XMLTree.searchNodeValue(nodes[0],prefix + "record->" + prefix + "recordSchema")); |
190 |
this.setOutputFormat(XMLTree.searchNodeValue(nodes[0],prefix + "record->" + prefix + "recordPacking")); |
191 |
this.setStartPosition("1"); |
192 |
this.setMaxRecords("10"); |
193 |
this.setRecordXPath(""); |
194 |
this.setResultSetTTL("0"); |
195 |
this.setServerAnswerReady("Titulo: " + |
196 |
XMLTree.searchNodeValue(nodes[0],prefix + "record->" + prefix + "recordData->explain->databaseInfo->title") + |
197 |
"\nDescripcion: " +
|
198 |
XMLTree.searchNodeValue(nodes[0],prefix + "record->" + prefix + "recordData->explain->databaseInfo->description") |
199 |
); |
200 |
} |
201 |
return true; |
202 |
} |
203 |
|
204 |
|
205 |
/* (non-Javadoc)
|
206 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiveDriver#isTheProtocol(java.net.URL)
|
207 |
*/
|
208 |
public boolean isProtocolSupported(URL url) { |
209 |
return SOAPProtocol.isProtocolSupported(url);
|
210 |
} |
211 |
|
212 |
|
213 |
|
214 |
|
215 |
} |