import java.util.*;
import lotus.domino.*;

public class listviewentries{
	public static void main(String argv[]){
		try{
			// test and get args
			if (argv.length < 5){
				// arguments were entered. give user the variables
				System.out.println("You need to enter arguments for this application...");
				System.out.println("   server, database, view, user, password");
				System.exit(0);
			}			
			String server = argv[0];
			String database = argv[1];
			String view = argv [2];
			String user = argv[3];
			String pass = argv[4];

			// start bubblegum wrapper and start session
			NotesThread.sinitThread();
			Session s = NotesFactory.createSession(server, user, pass);

			//get server, database, and view
			String servername=s.getServerName();
			if(servername==""){
				System.out.println("Could not attach to server");
				System.exit(0);
				}
			System.out.println("Attached to Server: " + servername);
			Database db = s.getDatabase(servername, database);
			if (db.isOpen()==false){
				System.out.println("Could not open database: " + database);
				System.exit(0);
			}
			System.out.println("Attached to database: " + db.getTitle());
			View v = db.getView(view);
			if (v == null){
				System.out.println("Unable to open view. It doesn't seem to exist.");
				System.exit(0);
			}
			System.out.println("Opened View: " + v.getName());

			//Create Nav and test for first entry
			ViewNavigator nav=v.createViewNav();
			ViewEntry ve = nav.getFirst();
			if (ve==null){
				System.out.println("Sorry, no entries/documents are in this view.");
				System.exit(0);
			}
			System.out.println("Listing view entries...\n ");
			//Loop through view entries and print first column.
			while(ve != null){
				System.out.println( (String) (ve.getColumnValues().elementAt(0)));
				ve = nav.getNext();
			}
			System.out.println("\n ...end listing");
		}
		catch (Exception e){
		if (e instanceof NotesException){
			NotesException ne=(NotesException)e;
			System.out.println("Domino-side error:\n" + ne.text + "\n");
		}
		e.printStackTrace();
		}
		finally {
		NotesThread.stermThread();
		}
	}
}	