source: trunk/java-client/org/nzdl/gsdl/SimpleClient.java@ 2066

Last change on this file since 2066 was 2066, checked in by say1, 23 years ago

put the SimpleClient in the package

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/*
2 * SimpleClient.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// the package we're in
21package org.nzdl;
22
23// classes and packages we're importing ...
24import java.util.Set;
25import java.util.Map;
26import java.util.ListIterator;
27import java.util.Iterator;
28import java.util.List;
29import org.nzdl.service.NzdlCollectionInfo;
30import org.nzdl.service.NzdlQuery;
31import org.nzdl.service.NzdlRequest;
32import org.nzdl.service.NzdlResponse;
33import org.nzdl.service.NzdlResultSet;
34import org.nzdl.service.NzdlService;
35import org.nzdl.service.NzdlServiceImpl;
36
37
38/**
39 * Class SimpleClient
40 *
41 * A class to test the workings of Corba interface from the client side.
42 *
43 * @author Dave Nichol ([email protected])
44 * @author Gordon Paynter ([email protected])
45 * @author stuart yeates ([email protected])
46 * @version $Revision: 2066 $
47 * @see org.nzdl.service.NzdlCollectionInfo;
48 * @see org.nzdl.service.NzdlQuery;
49 * @see org.nzdl.service.NzdlRequest;
50 * @see org.nzdl.service.NzdlResponse;
51 * @see org.nzdl.service.NzdlResultSet;
52 * @see org.nzdl.service.NzdlService;
53 * @see org.nzdl.service.NzdlServiceImpl;
54 */
55
56public class SimpleClient {
57
58 public static final void main( String [] args ) {
59
60 NzdlService nzdl = new NzdlServiceImpl( args );
61
62 if (args.length < 3) {
63 System.err.println("WARNING: missing command line arguments. using defualts:");
64 System.err.println("usage: java <javaoptions> SimpleClient <collect> <xxx> <query>");
65 System.err.println(" <javaoptions> = options to the JVM ");
66 System.err.println(" <collect> = the greenstone collection to use (demo)");
67 System.err.println(" <xxx> = a currently unused option (xxx)");
68 System.err.println(" <query> = the query to use on the collection (the)");
69 args = new String [3];
70 args[0] = "demo";
71 args[1] = "xxx";
72 args[2] = "the";
73 }
74
75 // extract some highlevel information on the collections on the server
76 // independent of the command line arguments passed in
77
78 Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
79 System.out.println("Number of collections on the server: " + collectionSet.size());
80
81 Iterator collectionSetIterator = collectionSet.iterator();
82 while (collectionSetIterator.hasNext() ) {
83 String collectionName = (String)collectionSetIterator.next(); // object -> String
84 NzdlCollectionInfo collectionInfo = nzdl.getCollectionInfo( collectionName );
85 // this next line should work but doesn't
86 System.out.println("Collection: " + collectionInfo.getName());
87 // so we revert to using the original string from the collectionSet
88 System.out.println("Collection: " + collectionName);
89 if (nzdl.hasCollection(collectionName) ) {
90 System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is true");
91 if (nzdl.pingCollection(collectionName) ) {
92 System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is true");
93 // these next statements make use of the NzdlCollection API
94 System.out.println("\t" + "Public: " + collectionInfo.isPublic());
95 System.out.println("\t" + "Beta: " + collectionInfo.isBeta());
96 int buildDate = collectionInfo.getBuildDate();
97 //process buildDate into something sensible
98 System.out.println("\t" + "Build Date: " + buildDate);
99 System.out.println("\t" + "No. of Documents: " + collectionInfo.getNumOfDocs());
100 System.out.println("\t" + "No. of Words: " + collectionInfo.getNumOfWords());
101 System.out.println("\t" + "No. of Bytes: " + collectionInfo.getNumOfBytes());
102 }
103 else {
104 System.out.println("\t" + "pingCollection(" + collectionName + ")" + " is false");
105 }
106 }
107 else
108 { System.out.println("\t" + "hasCollection(" + collectionName + ")" + " is false"); }
109 }
110
111
112
113
114 String collName = args[0];
115 NzdlCollectionInfo collInfo = nzdl.getCollectionInfo( collName );
116
117 System.out.println("Searching collection: " + collName);
118
119 int numResults = collInfo.getNumOfDocs(); // what precisely is this number ?
120 System.out.println("Collection " + collName + " suggests to get results in chunks of " + numResults + " hits" );
121 String method = args[1];
122 System.out.println("Search method: " + method);
123 String queryTerm = args[2];
124 System.out.println("Query Term: " + queryTerm);
125 String metaTag = "Title";
126
127 System.out.println("Searching in '" + metaTag + "' metadata");
128
129 NzdlQuery query = new NzdlQuery( queryTerm );
130 // return the first numResults that match
131 //query.setEndResults( 15 );
132 // "-1" means consider all the documents that match
133 query.setMaxDocs( -1 );
134
135 NzdlRequest request = new NzdlRequest( query );
136 NzdlResponse response = new NzdlResponse( );
137 System.out.println("getting document IDs ... ");
138 nzdl.service( collName, request, response );
139
140 NzdlResultSet results = response.getResultSet();
141 List docIDs = results.getDocumentIDs();
142 System.out.println("Number of documents returned: " + docIDs.size());
143
144 System.out.println("getting '" + metaTag + "' meta data of documents ... ");
145 Map metaData = nzdl.getMetaData( collName, docIDs, metaTag );
146
147 for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
148 String id = (String) i.next();
149 Set meta = (Set) metaData.get( id );
150 System.out.println(meta.toString());
151 System.out.println("getting document contents ... ");
152 String documentContents = nzdl.getDocument(collName, id);
153 System.out.println("got document contents. ");
154 System.out.println(" *************** START DOC " + id + " ***************");
155 System.out.println(documentContents);
156 System.out.println(" *************** END DOC " + id + " ***************");
157 }
158
159
160 } //main
161
162} // class
Note: See TracBrowser for help on using the repository browser.