Add simple CLI program
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / ZoomCLI.java
1 /*
2  * Copyright (c) 1995-2013, Index Datassss
3  * All rights reserved.
4  * See the file LICENSE for details.
5  */
6 package org.yaz4j;
7
8 import java.util.List;
9 import org.yaz4j.exception.ZoomException;
10
11 /**
12  *
13  * @author jakub
14  */
15 class ZoomCLI {
16   static public void main(String[] args) {
17     System.out.println("Open connection to z3950.indexdata.dk:210/gils...");
18     Connection con = new Connection("z3950.indexdata.dk:210/gils", 0);
19     try {
20       con.setSyntax("sutrs");
21       con.connect();
22       System.out.println("Search for 'utah'...");
23       ResultSet s = con.search(new PrefixQuery("@attr 1=4 utah"));
24       System.out.println("Retrieve all records..");
25       List<Record> all = s.getRecords(0, (int) s.getHitCount());
26       for (Record r : all) {
27         System.out.println(r.render());
28       }
29       System.out.println("Success");
30     } catch (ZoomException ze) {
31       System.out.println("Failure");
32       ze.printStackTrace();
33     } finally {
34       con.close();
35     }
36   }
37 }