Monday, December 28, 2009

Get All Documents from a View

* Method to obtain a collection of all documents from a specified view in a specified database
* @param targetDB - the database from which the document collection is to be obtained
* @param viewName - the name of the view from which the document collection is to be obtained
* @return String[]
* @author karthikeyan_a
* @since 30-April-2009

public DocumentCollection getViewDocuments(Database targetDB, String viewName) {
//if any of the input parameters in undefined then return null
if ((targetDB==null)|| (viewName==null) || (viewName.trim().equals(""))) {
return null;
//mark the return value and initialize other variables
DocumentCollection viewDocs=null;
Document viewDoc=null;
ViewEntryCollection viewEntries=null;
ViewEntry viewEntry=null;
View chosenView=null;
try {
//set the handle for the view mentioned by the view name
//if the view handle is not set then return null
if (chosenView==null) {
return null;

//ensure that an empty document collection is created
Random generator = new Random();

* loop through all the entries in the view and push their associated
* documents into the document collection
viewEntries= chosenView.getAllEntries();
//get the handle for the first entry in the collection
while(viewEntry!=null) {
if (viewEntry.isDocument()) {
* If the document concerned with the entry is already present in the
* collection then a duplicate exception is thrown. So catch the same and
* dont allow that to hurt the process
try {
catch (NotesException duplicateException) {
//by pass exception
//push the handle to the next entry in the collection

} catch (NotesException e) {
//return the collection of documents thus obtained
return viewDocs;

No comments:

Post a Comment