MicroStrategy ONE
Browsing the Contents of a Folder
This code sample uses SessionManagementSample.java from the Creating a Session topic to create a session on the MicroStrategy Tutorial project and then browses the contents of the Shared Reports folder. The code sample for browsing the contents of a folder—FolderBrowsingSample.java—is provided in the samples/java/webobjects subfolder inside the MicroStrategy SDK installation.
/**
* MicroStrategy SDK
*
* Copyright © 2001-2006 MicroStrategy Incorporated. All Rights Reserved.
*
* MICROSTRATEGY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
* SUITABILITY OF THIS SAMPLE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. MICROSTRATEGY SHALL NOT
* BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
* MODIFYING OR DISTRIBUTING THIS SAMPLE CODE OR ITS DERIVATIVES.
*/
package com.microstrategy.sdk.samples.webobjects;
import com.microstrategy.web.objects.WebIServerSession;
import com.microstrategy.web.objects.WebFolder;
import com.microstrategy.webapi.EnumDSSXMLFolderNames;
import com.microstrategy.webapi.EnumDSSXMLObjectTypes;
import com.microstrategy.web.objects.WebObjectSource;
import com.microstrategy.web.objects.WebObjectsException;
import com.microstrategy.web.objects.WebDisplayUnits;
/**
*
* <p>Title: FolderBrowsingSample</p>
* <p>Description: Displays the contents for the "Shared Reports" folder for the "MicroStrategy Tutorial" project.</p>
* <p>Company: Microstrategy, Inc.</p>
*/
public class FolderBrowsingSample {
/**
* Use Web Objects to fetch the contents from the Shared Reports Folder.
* Developers should modify the values store
*/
public static void browseSharedReportsFolder() {
//Create internal variables
WebFolder folder = null;
String objectType = "";
String sharedReportsFolderID = "";
//Create a session using
WebIServerSession serverSession = SessionManagementSample.getSession();
WebObjectSource objSource = serverSession.getFactory().getObjectSource();
try {
//Obtain ID for Shared Reports Folder and populate WebFolder
//Setting
sharedReportsFolderID = objSource.getFolderID(EnumDSSXMLFolderNames.DssXmlFolderNamePublicReports);
folder = (WebFolder) objSource.getObject(sharedReportsFolderID, EnumDSSXMLObjectTypes.DssXmlTypeFolder);
//Set number of elements to fetch
folder.setBlockBegin(1);
folder.setBlockCount(50);
//Fetch Contents from Intelligence Server
folder.populate() ;
//If the folder has any contents, display them
if(folder.size() > 0) {
//Extract folder contents
WebDisplayUnits units = folder.getChildUnits();
//Print folder contents
Log.logger.log(Level.INFO,"nnnPrinting folder contents:");
if (units != null) {
for (int i = 0; i < units.size(); i++) {
switch (units.get(i).getDisplayUnitType()) {
case EnumDSSXMLObjectTypes.DssXmlTypeFolder:
objectType = "Folder";
break;
case EnumDSSXMLObjectTypes.DssXmlTypeReportDefinition:
objectType = "Report";
break;
case EnumDSSXMLObjectTypes.DssXmlTypeDocumentDefinition:
objectType = "Document";
break;
case EnumDSSXMLObjectTypes.DssXmlTypeFilter:
objectType = "Filter";
break;
case EnumDSSXMLObjectTypes.DssXmlTypeTemplate:
objectType = "Template";
break;
}
Log.logger.log(Level.INFO,"t" + objectType + ": " + units.get(i).getDisplayName());
}
Log.logger.log(Level.INFO, "");
}
}
}
catch (WebObjectsException ex) {
Log.logger.log(Level.ERROR,"nError while fetching folder contents: " + ex.getMessage());
}
//Close the session to clean up resources on Intelligence Server
SessionManagementSample.closeSession(serverSession);
}
/**
* Execute Folder Browsing Sample
* @param args String[]
*/
public static void main(String args[]) {
browseSharedReportsFolder();
}
}