Collaboration API Documentation

com.filenet.bso.api.util
Class BsoSearchResultsXMLReader

java.lang.Object
  |
  +--com.filenet.bso.api.util.BsoSearchResultsXMLReader

public class BsoSearchResultsXMLReader
extends java.lang.Object

This class parses Search Results XML, in the format returned from a Search.execute() call, and returns the data as BsoSearchResultRow objects. The class will handle queries involving joins between classes. It will separate out each row into a virtual row for each class.

The information about the classes is passed to the parse() method as an array of BsoSearchResultsClassData objects. You can optionally declare that a class references other classes. If that is the case, each virtual row object will reference one or more virtual row objects for each of the classes it references. Whether a row will reference a single or multiple other row objects depends on how the BsoSearchResultsClassData objects are configured, and is based on how you want to read the data out.

Take for example fictitious Folder and Document classes where you are modeling direct containment rather than the referential containment provided by the base content engine classes. You might use a query such as the following to return all the documents and the folders that contain them:

 SELECT d.Id [d_Id], d.DocumentTitle [d_DocumentTitle],
        f.Id [f_Id], f.FolderName [f_FolderName]
 FROM DirectDocument d INNER JOIN DirectFolder f ON d.DirectParent = f.This
 
The class data objects could be configured as follows to fetch the rows by documents first and then the folder each document belongs to. Note that each column must be aliased with a prefix that represents that class. Also a column must be selected for each class that is the identity column for that class (typically Id). In this way duplicate virtual rows can be detected, as in this example when multiple documents will refer to the same parent folder.
 BsoSearchResultsClassData[] classDatas = new BsoSearchResultsClassData[]
 {
     new BsoSearchResultsClassData("d_", "Id", new String[] {"f_"}),
     new BsoSearchResultsClassData("f_", "Id", null)
 };

 BsoSearchResultsXMLReader reader = new BsoSearchResultsXMLReader();
 reader.parse(xml, classDatas);

 // Get each document
 int numDocs = reader.getRowCount("d_");
 for (int iDoc = 0; iDoc < numDocs; iDoc++)
 {
     BsoSearchResultRow docRow = reader.getRow("d_", iDoc);
     // Get columns of the document row
     String val = docRow.getColumnValue("DocumentTitle");
     String type = docRow.getColumnType("DocumentTitle");
     // Get the folder this document belongs to (only a single row)
     BsoSearchResultRow folderRow = docRow.getReferencedClassRow("f_", 0);
 }
 
If, however, you wanted to retrieve the data by folders first and then the documents that belonged to each folder, you could configure the class data objects as follows:
 BsoSearchResultsClassData[] classDatas = new BsoSearchResultsClassData[]
 {
     new BsoSearchResultsClassData("d_", "Id", null),
     new BsoSearchResultsClassData("f_", "Id", new String[] {"d_"})
 };

 BsoSearchResultsXMLReader reader = new BsoSearchResultsXMLReader();
 reader.parse(xml, classDatas);

 // Get each folder
 int numFolds = reader.getRowCount("f_");
 for (int iFold = 0; iFold < numFolds; iFold++)
 {
     BsoSearchResultRow foldRow = reader.getRow("f_", iFold);
     // Get columns of the folder row
     String val = foldRow.getColumnValue("FolderName");
     String type = foldRow.getColumnType("FolderName");
     // Get the documents that belong to this folder
     int numRefedDocs = foldRow.getReferencedClassRowCount("d_");
     for (int iRefedDoc = 0; iRefedDoc < numRefedDocs; iRefedDoc++)
     {
         BsoSearchResultRow docRow = foldRow.getReferencedClassRow("d_", iRefedDoc);
     }
 }
 


Inner Class Summary
protected  class BsoSearchResultsXMLReader.ResultsHandler
          SAX Parser inner class to parse the search results XML
 
Field Summary
static java.lang.String ATTRIBUTETYPE_ELEMNAME
           
static java.lang.String DATATYPE_ELEMNAME
           
static java.lang.String NAME_ATTRNAME
           
static java.lang.String ROW_ELEMNAME
           
static java.lang.String TYPE_ATTRNAME
           
 
Constructor Summary
BsoSearchResultsXMLReader()
          Construct a reader instance.
 
Method Summary
 BsoSearchResultsClassData getClassData(java.lang.String classIdent)
          Returns the data for a particular class.
 java.lang.String[] getClassPrefixes()
           
 BsoSearchResultRow getRow(java.lang.String classIdent, int idx)
          Gets an individual row parsed.
 BsoSearchResultRow getRow(java.lang.String classIdent, java.lang.String ident)
          Returns a specific row given a particular identity column value.
 int getRowCount(java.lang.String classIdent)
          Get the number of rows parsed.
 boolean hasClassData(java.lang.String classIdent)
          Indicates if the reader has a particular class.
 boolean hasRow(java.lang.String classIdent, java.lang.String ident)
          Indicates if there exists a row with a particular identity column value.
 void parse(java.lang.String xml, BsoSearchResultsClassData[] classDatas)
          Parse some search results XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTETYPE_ELEMNAME

public static final java.lang.String ATTRIBUTETYPE_ELEMNAME

DATATYPE_ELEMNAME

public static final java.lang.String DATATYPE_ELEMNAME

ROW_ELEMNAME

public static final java.lang.String ROW_ELEMNAME

NAME_ATTRNAME

public static final java.lang.String NAME_ATTRNAME

TYPE_ATTRNAME

public static final java.lang.String TYPE_ATTRNAME
Constructor Detail

BsoSearchResultsXMLReader

public BsoSearchResultsXMLReader()
Construct a reader instance.
Method Detail

parse

public void parse(java.lang.String xml,
                  BsoSearchResultsClassData[] classDatas)
Parse some search results XML. The rows produced from parsing can be obtained with getRowCount() and getRow()
Parameters:
xml - The search results XML.
classDatas - Class data objects that describe the classes involved in the query and any references from one class to others. Can be null if the query does not involve multiple classes.

getRowCount

public int getRowCount(java.lang.String classIdent)
Get the number of rows parsed. Either all rows or the rows for a particular class.
Parameters:
classIdent - Identifier of class. This can be null if the search does not involve multiple classes. Otherwise it can be the class prefix, or one of the keys specified for that class.
Returns:
Number of rows.

getRow

public BsoSearchResultRow getRow(java.lang.String classIdent,
                                 int idx)
Gets an individual row parsed.
Parameters:
classIdent - Identifier of class. Can be null if the search does not involve multiple classes. Otherwise it can be the class prefix, or one of the keys specified for that class.
idx - The index of the row.
Returns:
The row object.

hasRow

public boolean hasRow(java.lang.String classIdent,
                      java.lang.String ident)
Indicates if there exists a row with a particular identity column value. This cannot be called if no identity column was specified for the class.
Parameters:
classIdent - A class identifier. This can be null if the query does not involve multiple classes. Otherwise it can be the class prefix or one of the keys specified for the class.
ident - The identity column value.

getRow

public BsoSearchResultRow getRow(java.lang.String classIdent,
                                 java.lang.String ident)
Returns a specific row given a particular identity column value. This cannot be called if no identity column was specified for the class.
Parameters:
classIdent - A class identifier. This can be null if the query does not involve multiple classes. Otherwise it can be the class prefix or one of the keys specified for the class.
ident - The identity column value.

hasClassData

public boolean hasClassData(java.lang.String classIdent)
Indicates if the reader has a particular class.
Parameters:
classIdent - A class identifier. This can be the class prefix or one of the keys specified for the class.

getClassData

public BsoSearchResultsClassData getClassData(java.lang.String classIdent)
Returns the data for a particular class.
Parameters:
classIdent - A class identifier. This can be the class prefix or one of the keys specified for the class.

getClassPrefixes

public java.lang.String[] getClassPrefixes()

Collaboration API Documentation

Copyright ?2002 - 2005 FileNet Corporation. All rights reserved.