Displaying a list of documents
You use methods from the ODCriteria, ODFolder, and ODHit classes to display a list of documents from a folder.
About this task
The following example uses ODCriteria, ODFolder, and ODHit
methods to do the following tasks:
- Search a folder using the default search criteria
- Print the number of documents that matched the query
- Lists the documents that matched the query
This example demonstrates the following ODFolder methods:
- getDisplayOrder
- getFolderSortOrder
- getCriteria
- getSortLocation
- setSortLocation
- search
- close
This example demonstrates the following ODHit methods:
- getDisplayValue
This example also demonstrates these ODServer methods:
- initialize
- logon
- openFolder
- logoff
- terminate
This example uses the following runtime parameters:
- Server name
- User Id
- Password
- Folder name
Example of displaying a list of documents:
import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;
public class TcSortedHitlist
{
public static void main ( String argv[] )
{
ODServer odServer;
ODFolder odFolder;
ODCriteria odCrit;
Enumeration crit_enum;
String server, userid, password, folder, crit1, crit2, crit3;
boolean ascend1, ascend2, ascend3;
//----------
// If too few parameters, display syntax and get out
//----------
if ( argv.length < 11 )
{
System.out.println( "usage: java TcSortedHitlist <server> <port> <userid> <password> <folder> <criteria1>" +
" <ascending1> <criteria2> <ascending2> <criteria3> <ascending3>" );
return;
}
try
{
//----------
// Set the stage
//----------
System.out.println("Testcase TcSortedHitlist started." );
System.out.println("This testcase should:");
System.out.println(" Logon to the specified server");
System.out.println(" Open the specified folder");
System.out.println(" 1. Display sort order information");
System.out.println(" Sort is disabled");
System.out.println(" Search the folder using the default criteria");
System.out.println(" Display the hitlist");
System.out.println(" 2. Display sort order information");
System.out.println(" Sort is enabled");
System.out.println(" Search the folder using default folder sort criteria");
System.out.println(" Search folder using setSortLocation(MIDTIER)");
System.out.println(" Search the folder using default criteria");
System.out.println(" Display the hitlist");
System.out.println(" 3. Display sort order information");
System.out.println(" Sort is disabled");
System.out.println(" Search folder using setSortLocation(NONE)");
System.out.println(" Search the folder using the default criteria");
System.out.println(" Display the hitlist");
System.out.println(" 4. Display sort order information");
System.out.println(" Sort is enabled");
System.out.println(" Search folder using setSortLocation(MIDTIER)");
System.out.println(" Search the folder using the default criteria");
System.out.println(" Display the hitlist");
System.out.println(" 5. Display sort order information");
System.out.println(" Sort is enabled");
System.out.println(" Search folder using setSortLocation(SERVER)");
System.out.println(" Search the folder using the default criteria");
System.out.println(" Display the hitlist");
System.out.println("");
System.out.println("---------------------------------------------------");
System.out.println("");
//----------
// Logon to the server
//----------
server = argv[0];
userid = argv[2];
password = argv[3];
folder = argv[4];
crit1 = argv[5];
ascend1 = argv[6].equals( "0" ) ?false:true;
crit2 = argv[7];
ascend2 = argv[8].equals( "0" ) ?false:true;
crit3 = argv[9];
ascend3 = argv[10].equals( "0" ) ?false:true;
ODConfig odConfig = new ODConfig();
if(odConfig != null)
{
odServer = new ODServer(odConfig );
odServer.initialize( "TcSortedHitlist.java" );
odServer.setPort(Integer.parseInt(argv[1]));
System.out.println( "Logging on to " + server + " server with user " + userid + "..." );
odServer.logon( server, userid, password);
//----------
// Open the folder and display default folder sort order
//----------
System.out.println("Opening " + folder + "...");
odFolder = odServer.openFolder(folder);
System.out.println("Sort Location = " + odFolder.getSortLocation());
displayFolderSortOrder(odFolder);
//----------
// Search the folder with sort disabled by default
//----------
System.out.println("With sort disabled by default:");
System.out.println(" Searching with SORT=NONE...");
searchAndListHits(odFolder);
//----------
// Search the folder after enabling sort
//----------
odFolder.setSortLocation(ODConstant.OD_SORT_LOCATION_MIDTIER);
displayFolderSortOrder(odFolder);
System.out.println("With Mid-tier sort enabled: USING Default Folder sort settings");
System.out.println("Sort Location = " + odFolder.getSortLocation());
System.out.println(" Searching folder with SORT=M and default criteria...");
searchAndListHits(odFolder);
//----------
// Create a new sort order and display it
//----------
System.out.println("Setting specified sort order...");
System.out.println("------------------------------------------------------------------");
for (crit_enum = odFolder.getCriteria(); crit_enum.hasMoreElements();)
{
odCrit = (ODCriteria) crit_enum.nextElement();
odCrit.setSortOrder(0);
}
if (!(crit1.equals("-")))
{
odCrit = odFolder.getCriteria(crit1);
odCrit.setSortOrder(1);
odCrit.setAscending(ascend1);
}
if (!(crit2.equals("-")))
{
odCrit = odFolder.getCriteria(crit2);
odCrit.setSortOrder(2);
odCrit.setAscending(ascend2);
}
if (!(crit3.equals("-")))
{
odCrit = odFolder.getCriteria(crit3);
odCrit.setSortOrder(3);
odCrit.setAscending(ascend3);
}
displayFolderSortOrder(odFolder);
//----------
// Search the folder after disabling sort
//----------
odFolder.setSortLocation(ODConstant.OD_SORT_LOCATION_NONE);
System.out.println("With sort disabled:");
System.out.println(" Searching folder with setSortLocation(NONE) ...");
System.out.println("Sort Location = " + odFolder.getSortLocation());
searchAndListHits(odFolder);
//----------
// Search the folder after enabling sort
//----------
odFolder.setSortLocation(ODConstant.OD_SORT_LOCATION_MIDTIER);
displayFolderSortOrder(odFolder);
System.out.println(" Searching folder with setSortLocation(MIDTIER) and
CmdLine sort order (default criteria)...");
System.out.println("Sort Location = " + odFolder.getSortLocation());
searchAndListHits(odFolder);
//----------
// Search the folder after enabling Server sort
//----------
odFolder.setSortLocation(ODConstant.OD_SORT_LOCATION_SERVER);
displayFolderSortOrder(odFolder);
System.out.println(" Searching folder with setSortLocation(SERVER) and
CmdLine sort order (default criteria)...");
System.out.println("Sort Location = " + odFolder.getSortLocation());
searchAndListHits(odFolder);
//----------
// Cleanup
//----------
odFolder.close();
odServer.logoff();
odServer.terminate();
System.out.println("");
System.out.println("---------------------------------------------------");
System.out.println("");
System.out.println( "Testcase TcSortedHitlist completed - Ensure that:" );
System.out.println(" 1. The default sort order is the same as that shown by the");
System.out.println(" Windows Client");
System.out.println(" 2. The 1st hitlist is not sorted");
System.out.println(" 3. The 2nd hitlist is sorted according to the default order");
System.out.println(" 4. The new sort order is correct for the command line");
System.out.println(" 5. The 3rd hitlist is not sorted");
System.out.println(" 6. The 4th hitlist is sorted according to the specified order");
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();
}
}
static void searchAndListHits( ODFolder odFolder )
{
ODHit odHit;
Vector hits;
String[] display_crit;
String value;
int j, k;
try
{
System.out.println( " Searching folder with default criteria..." );
hits = odFolder.search();
System.out.println(" Number of hits: " + hits.size());
if ( hits != null && hits.size( ) > 0 )
{
display_crit = odFolder.getDisplayOrder();
value = " ";
for (j = 0; j < display_crit.length; j++)
value = value + display_crit[j] + "--";
System.out.println(value);
for ( j = 0; j < hits.size( ); j++ )
{
odHit = (ODHit) hits.elementAt(j);
value = " ";
for (k = 0; k < display_crit.length; k++)
value = value + odHit.getDisplayValue(display_crit[k]) + "--";
System.out.println(value);
}
}
}
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();
}
}
static void displayFolderSortOrder( ODFolder odFolder )
{
ODCriteria odCrit;
ArrayList sort_order;
int j, order;
try
{
sort_order = odFolder.getCriteriaSortOrder();
System.out.println("Sort Order:");
for ( order = -1; order < 100; order++ )
{
for( j = 0; j < sort_order.size( ); j++ )
{
odCrit = (ODCriteria) sort_order.get(j);
if (odCrit.getSortOrder() == order)
System.out.println(" "
+ order
+ ". "
+ odCrit.getName()
+ (order <= 0 ? "" : " ("
+ (odCrit.getAscending() ? "ascending" : "descending")
+ ")"));
}
}
}
catch ( Exception e2 )
{
System.out.println("exception: " + e2);
e2.printStackTrace();
}
}
}