Revision 342
Added by berkley over 24 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
168 | 168 |
} |
169 | 169 |
return docListResult; |
170 | 170 |
} |
171 |
|
|
172 |
/** |
|
173 |
* format a structured query as an XML document that conforms |
|
174 |
* to the pathquery.dtd and is appropriate for submission to the DBQuery |
|
175 |
* structured query engine |
|
176 |
* |
|
177 |
* @param params The list of parameters that should be included in the query |
|
178 |
* @param doctype the type of documents to include in the result set -- use |
|
179 |
* "any" or "ANY" for unfiltered result sets |
|
180 |
*/ |
|
181 |
public static String createSQuery(Hashtable params, String doctype) |
|
182 |
{ |
|
183 |
StringBuffer query=null; |
|
184 |
Enumeration elements; |
|
185 |
Enumeration keys; |
|
186 |
Object nextkey; |
|
187 |
Object nextelement; |
|
188 |
query.append("<?xml version=\"1.0\"?>"); |
|
171 | 189 |
|
190 |
query.append("<pathquery version=\"1.0\"><meta_file_id>"); |
|
191 |
if(params.containsKey("meta_file_id")) |
|
192 |
{ |
|
193 |
query.append( ((String[])params.get("meta_file_id"))[0]); |
|
194 |
query.append("</meta_file_id>"); |
|
195 |
} |
|
196 |
else |
|
197 |
{ |
|
198 |
query.append("unspecified</meta_file_id>"); |
|
199 |
} |
|
200 |
query.append("<querytitle>"); |
|
201 |
if(params.containsKey("querytitle")) |
|
202 |
{ |
|
203 |
query.append(((String[])params.get("querytitle"))[0]); |
|
204 |
query.append("</querytitle>"); |
|
205 |
} |
|
206 |
else |
|
207 |
{ |
|
208 |
query.append("unspecified</querytitle>"); |
|
209 |
} |
|
210 |
if (!doctype.equals("any") && |
|
211 |
!doctype.equals("ANY") && |
|
212 |
!doctype.equals("") ) |
|
213 |
{ |
|
214 |
query.append("<returndoctype>"); |
|
215 |
query.append(doctype).append("</returndoctype>"); |
|
216 |
} |
|
217 |
query.append("<querygroup operator=\"" + |
|
218 |
((String[])params.get("operator"))[0] + "\">"); |
|
219 |
|
|
220 |
|
|
221 |
//anyfield is a special case because it does a |
|
222 |
//free text search. It does not have a <pathexpr> |
|
223 |
//tag. |
|
224 |
if(params.containsKey("anyfield") && |
|
225 |
!((String[])params.get("anyfield"))[0].equals("")) |
|
226 |
{ |
|
227 |
query.append("<queryterm casesensitive=\"false\" " + |
|
228 |
"searchmode=\"contains\"><value>" + |
|
229 |
((String[])params.get("anyfield"))[0] + |
|
230 |
"</value></queryterm>"); |
|
231 |
} |
|
232 |
|
|
233 |
//this while loop finds the rest of the parameters |
|
234 |
//and attempts to query for the field specified |
|
235 |
//by the parameter. |
|
236 |
elements = params.elements(); |
|
237 |
keys = params.keys(); |
|
238 |
while(keys.hasMoreElements() && elements.hasMoreElements()) |
|
239 |
{ |
|
240 |
nextkey = keys.nextElement(); |
|
241 |
nextelement = elements.nextElement(); |
|
242 |
|
|
243 |
//make sure we aren't querying for any of these |
|
244 |
//parameters since the are already in the query |
|
245 |
//in one form or another. |
|
246 |
if(!nextkey.toString().equals("doctype") && |
|
247 |
!nextkey.toString().equals("action") && |
|
248 |
!nextkey.toString().equals("qformat") && |
|
249 |
!nextkey.toString().equals("anyfield") && |
|
250 |
!nextkey.toString().equals("operator") && |
|
251 |
!(((String[])nextelement)[0].equals("")) ) |
|
252 |
{ |
|
253 |
query.append("<queryterm casesensitive=\"false\" " + |
|
254 |
"searchmode=\"contains\">" + |
|
255 |
"<value>" + |
|
256 |
//add the query value |
|
257 |
((String[])nextelement)[0] + |
|
258 |
"</value><pathexpr>" + |
|
259 |
//add the path to query by |
|
260 |
nextkey.toString() + |
|
261 |
"</pathexpr></queryterm>"); |
|
262 |
} |
|
263 |
} |
|
264 |
query.append("</querygroup></pathquery>"); |
|
265 |
return query.toString(); |
|
266 |
} |
|
267 |
|
|
172 | 268 |
/** |
173 | 269 |
* format a simple free-text value query as an XML document that conforms |
174 | 270 |
* to the pathquery.dtd and is appropriate for submission to the DBQuery |
... | ... | |
181 | 277 |
public static String createQuery(String value, String doctype) { |
182 | 278 |
StringBuffer xmlquery = new StringBuffer(); |
183 | 279 |
xmlquery.append("<?xml version=\"1.0\"?>\n"); |
184 |
//xmlquery.append("<!DOCTYPE pathquery PUBLIC "); |
|
185 |
//xmlquery.append("\"-//NCEAS//pathquery-1.0//EN\" "); |
|
186 |
//xmlquery.append("\"http://24.237.19.164/xmltodb/lib/pathquery.dtd\" >"); |
|
187 | 280 |
xmlquery.append("<pathquery version=\"1.0\">"); |
188 | 281 |
xmlquery.append("<meta_file_id>Unspecified</meta_file_id>"); |
189 | 282 |
xmlquery.append("<querytitle>Unspecified</querytitle>"); |
... | ... | |
219 | 312 |
|
220 | 313 |
/** |
221 | 314 |
* '$Log$ |
315 |
* 'Revision 1.10 2000/07/26 20:40:41 higgins |
|
316 |
* 'no message |
|
317 |
* ' |
|
222 | 318 |
* 'Revision 1.9 2000/06/26 10:35:04 jones |
223 | 319 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
224 | 320 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
Also available in: Unified diff
added createSQuery