Enumeration keys;
Hashtable parms;
int maximumRecords=1, maximumTerms=11, responsePosition=6, resultSetTTL=0, startRecord=1;
long startTime;
ScanRequestType scanRequest;
SearchRetrieveRequestType searchRequest;
SearchRetrieveResponseType searchResponse;
String input, key, query=null, recordPacking="xml", scanClause=null,
schema=null, sortKeys=null;
Transformer transformer=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\ntype \"help\" for an explanation of the commands");
System.out.print("enter request: ");
input=br.readLine();
while(input!=null && input.length()>0 && !quit) {
parms=parseInput(input);
scan=search=false;
keys=parms.keys();
while(keys.hasMoreElements()) {
key=(String)keys.nextElement();
if(key.equals("explain")) {
System.out.println(db.getExplainRecord(null));
}
else if(key.equals("help")) {
help();
}
else if(key.equals("maximumRecords")) {
maximumRecords=Integer.parseInt((String)parms.get(key));
}
else if(key.equals("maximumTerms")) {
maximumTerms=Integer.parseInt((String)parms.get(key));
}
else if(key.equals("q") || key.equals("quit")) {
quit=true;
}
else if(key.equals("query")) {
query=convertUnicodeSequence((String)parms.get(key));
search=true;
}
else if(key.equals("recordPacking")) {
recordPacking=(String)parms.get(key);
}
else if(key.equals("recordSchema")) {
schema=(String)parms.get(key);
}
else if(key.equals("responsePosition")) {
responsePosition=Integer.parseInt((String)parms.get(key));
}
else if(key.equals("resultSetTTL")) {
resultSetTTL=Integer.parseInt((String)parms.get(key));
}
else if(key.equals("scanClause")) {
scanClause=convertUnicodeSequence((String)parms.get(key));
scan=true;
}
else if(key.equals("sortKeys")) {
sortKeys=(String)parms.get(key);
}
else if(key.equals("startRecord")) {
startRecord=Integer.parseInt((String)parms.get(key));
}
else if(key.equals("x-info-5-restrictorSummary")) {
restrictorSummary=!((String)parms.get(key)).equals("false");
}
else if(key.equalsIgnoreCase("xsl")) {
String xslFileName=(String)parms.get(key);
Source xslSource=new StreamSource(xslFileName);
if(xslSource==null) {
System.out.println("Unable to make StreamSource for: "+xslFileName);
continue;
}
TransformerFactory tFactory=TransformerFactory.newInstance();
transformer=tFactory.newTransformer(xslSource);
}
else { // assume it is a query
query=key;
search=true;
}
}
if(search) {
System.out.print("operation=searchRetrieve");
searchRequest=new SearchRetrieveRequestType();
System.out.print("&version=1.1");
searchRequest.setVersion("1.1");
System.out.print("&maximumRecords="+maximumRecords);
searchRequest.setMaximumRecords(new NonNegativeInteger(Integer.toString(maximumRecords)));
System.out.print("&query="+query);
searchRequest.setQuery(query);
System.out.print("&recordPacking="+recordPacking);
searchRequest.setRecordPacking(recordPacking);
if(schema!=null && schema.length()>0) {
System.out.print("&recordSchema="+schema);
searchRequest.setRecordSchema(schema);
}
if(restrictorSummary) {
System.out.print("&x-info-5-restrictorSummary");
ExtraDataType edt=new ExtraDataType();
MessageElement elems[]=new MessageElement[1];
edt.set_any(elems);
Document domDoc;
DocumentBuilderFactory dbf=
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder docb=dbf.newDocumentBuilder();
StringReader sr=new StringReader("<restrictorSummary xmlns=\"info:srw/extension/5/restrictorSummary\"/>");
domDoc=docb.parse(new InputSource(sr));
sr.close();
Element el=domDoc.getDocumentElement();
elems[0]=new MessageElement(el);
domDoc=null;
searchRequest.setExtraRequestData(edt);
}
System.out.print("&resultSetTTL="+resultSetTTL);
searchRequest.setResultSetTTL(new NonNegativeInteger(Integer.toString(resultSetTTL)));
if(sortKeys!=null && sortKeys.length()>0) {
System.out.print("&sortKeys="+sortKeys);
searchRequest.setSortKeys(sortKeys);
}
System.out.println("&startRecord="+startRecord+"\n");
searchRequest.setStartRecord(new PositiveInteger(Integer.toString(startRecord)));
startTime=System.currentTimeMillis();
searchResponse = db.doRequest(searchRequest);
System.out.println("elapsed time: "+(System.currentTimeMillis()-startTime)+"ms");
DiagnosticsType diags=searchResponse.getDiagnostics();
if(diags!=null) {