/* * SimpleClient.java * Copyright (C) 2001 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // the package we're in package org.nzdl; // classes and packages we're importing ... import java.util.Set; import java.util.Map; import java.util.ListIterator; import java.util.Iterator; import java.util.List; import org.nzdl.service.NzdlCollectionInfo; import org.nzdl.service.NzdlQuery; import org.nzdl.service.NzdlRequest; import org.nzdl.service.NzdlResponse; import org.nzdl.service.NzdlResultSet; import org.nzdl.service.NzdlService; import org.nzdl.service.NzdlServiceImpl; /** * Class SimpleClient * * A class to test the workings of Corba interface from the client side. * * @author Dave Nichol (daven@cs.waikato.ac.nz) * @author Gordon Paynter (paynter@cs.waikato.ac.nz) * @author stuart yeates (say1@cs.waikato.ac.nz) * @version $Revision: 2066 $ * @see org.nzdl.service.NzdlCollectionInfo; * @see org.nzdl.service.NzdlQuery; * @see org.nzdl.service.NzdlRequest; * @see org.nzdl.service.NzdlResponse; * @see org.nzdl.service.NzdlResultSet; * @see org.nzdl.service.NzdlService; * @see org.nzdl.service.NzdlServiceImpl; */ public class SimpleClient { public static final void main( String [] args ) { NzdlService nzdl = new NzdlServiceImpl( args ); if (args.length < 3) { System.err.println("WARNING: missing command line arguments. using defualts:"); System.err.println("usage: java SimpleClient "); System.err.println(" = options to the JVM "); System.err.println(" = the greenstone collection to use (demo)"); System.err.println(" = a currently unused option (xxx)"); System.err.println(" = the query to use on the collection (the)"); args = new String [3]; args[0] = "demo"; args[1] = "xxx"; args[2] = "the"; } // extract some highlevel information on the collections on the server // independent of the command line arguments passed in Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles System.out.println("Number of collections on the server: " + collectionSet.size()); Iterator collectionSetIterator = collectionSet.iterator(); while (collectionSetIterator.hasNext() ) { String collectionName = (String)collectionSetIterator.next(); // object -> String NzdlCollectionInfo collectionInfo = nzdl.getCollectionInfo( collectionName ); // this next line should work but doesn't System.out.println("Collection: " + collectionInfo.getName()); // so we revert to using the original string from the collectionSet System.out.println("Collection: " + collectionName); if (nzdl.hasCollection(collectionName) ) { System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is true"); if (nzdl.pingCollection(collectionName) ) { System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is true"); // these next statements make use of the NzdlCollection API System.out.println("\t" + "Public: " + collectionInfo.isPublic()); System.out.println("\t" + "Beta: " + collectionInfo.isBeta()); int buildDate = collectionInfo.getBuildDate(); //process buildDate into something sensible System.out.println("\t" + "Build Date: " + buildDate); System.out.println("\t" + "No. of Documents: " + collectionInfo.getNumOfDocs()); System.out.println("\t" + "No. of Words: " + collectionInfo.getNumOfWords()); System.out.println("\t" + "No. of Bytes: " + collectionInfo.getNumOfBytes()); } else { System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is false"); } } else { System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is false"); } } String collName = args[0]; NzdlCollectionInfo collInfo = nzdl.getCollectionInfo( collName ); System.out.println("Searching collection: " + collName); int numResults = collInfo.getNumOfDocs(); // what precisely is this number ? System.out.println("Collection " + collName + " suggests to get results in chunks of " + numResults + " hits" ); String method = args[1]; System.out.println("Search method: " + method); String queryTerm = args[2]; System.out.println("Query Term: " + queryTerm); String metaTag = "Title"; System.out.println("Searching in '" + metaTag + "' metadata"); NzdlQuery query = new NzdlQuery( queryTerm ); // return the first numResults that match //query.setEndResults( 15 ); // "-1" means consider all the documents that match query.setMaxDocs( -1 ); NzdlRequest request = new NzdlRequest( query ); NzdlResponse response = new NzdlResponse( ); System.out.println("getting document IDs ... "); nzdl.service( collName, request, response ); NzdlResultSet results = response.getResultSet(); List docIDs = results.getDocumentIDs(); System.out.println("Number of documents returned: " + docIDs.size()); System.out.println("getting '" + metaTag + "' meta data of documents ... "); Map metaData = nzdl.getMetaData( collName, docIDs, metaTag ); for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) { String id = (String) i.next(); Set meta = (Set) metaData.get( id ); System.out.println(meta.toString()); System.out.println("getting document contents ... "); String documentContents = nzdl.getDocument(collName, id); System.out.println("got document contents. "); System.out.println(" *************** START DOC " + id + " ***************"); System.out.println(documentContents); System.out.println(" *************** END DOC " + id + " ***************"); } } //main } // class