Listing folders and folder information

You use methods from the ODServer class to create a list of folders. Then, you write code that prints the name and description of a folder on one line.

About this task

The following example uses ODServer methods to print a line that shows the number of folders on the specified server that might be searched by the specified user ID. The example prints one line for each folder, showing the folder name and description.

This example demonstrates the following ODServer methods:
  • initialize
  • logon
  • getNumFolders
  • getFolderNames
  • getFolderDescription
  • logoff
  • terminate
This example uses the following runtime parameters:
  • Server name
  • Port
  • User Id
  • Password
Example of listing folders and folder information:
import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;

public class TcListFolders
{
    public static void main ( String argv[] )
    {
        ODServer    odServer;
        Enumeration folders_enum;
        String folder_name;
        String folder_desc;
        int num_folders;

        //----------
        // If too few parameters, display syntax and get out
        //----------
        if ( argv.length < 4 )
        {
            System.out.println( "usage: java TcListFolders <server> <port> <userid> <password>" );
            return;
        }

        try
        {
            //----------
            // Set the stage
            //----------
            System.out.println( "Testcase TcListFolders started." );
            System.out.println( "This testcase should:" );
            System.out.println( "  Display a line showing number of folders on the server available to the userid" );
            System.out.println( "  Display one line for each folder, showing name and description" );
            System.out.println( "" );
            System.out.println( "The information should be the same as that displayed using the Windows Client" );
            System.out.println( "(with the 'All' button checked if available), but the sequence of the folders" );
            System.out.println( "may be different depending on the server specified" );
            System.out.println( "" );
            System.out.println( "---------------------------------------------------" );
            System.out.println( "" );

            //----------
            // Logon to specified server
            //----------
            ODConfig odConfig = new ODConfig();
            if(odConfig != null)
            {
                odServer = new ODServer(odConfig );
                odServer.initialize(  "TcListFolders.java" );
                System.out.println( "Logging on to " + argv[0]  + " server with user " + argv[2] + "..." );
                odServer.setPort(Integer.parseInt(argv[1]));
                odServer.logon( argv[0], argv[2], argv[3]);

                //----------
                // Display the number of folders available.
                //----------
                num_folders = odServer.getNumFolders( );
                System.out.println( "" );
                System.out.println( "There are " + num_folders + " folders available to " + argv[2] + " on "
                                     + argv[0] + ":" );

                //----------
                // Display the folder names and descriptions
                //----------
                for ( folders_enum = odServer.getFolderNames( ); folders_enum.hasMoreElements( ); )
                {
                    folder_name = (String)folders_enum.nextElement( );
                    folder_desc = odServer.getFolderDescription( folder_name );
                    System.out.println( "  " + folder_name + "  ---  " + folder_desc );
                }

                //----------
                // Cleanup
                //----------
                odServer.logoff( );
                odServer.terminate( );
                System.out.println( "" );
                System.out.println( "---------------------------------------------------" );
                System.out.println( "" );
                System.out.println( "Testcase TcListFolders completed - compare results to Windows Client if required" );
                System.out.println( "" );
            }
        }

        catch ( ODException e )
        {
            System.out.println( "ODException: " + e );
            System.out.println( "   id = " + e.getErrorId( ) );
            System.out.println( "  msg = " + e.getErrorMsg( ) );
            e.printStackTrace( );
        }
        catch ( Exception e2 )
        {
            System.out.println( "exception: " + e2 );
            e2.printStackTrace( );
        }
    }
}