MicroStrategy ONE
Highlighting an Object
This example demonstrates how to access a specific prompt instance, highlight an object, and obtain the Display XML.
This code sample assumes that the values for messageID, stateID, prompt index and prompt answer are obtained from the HTML form data. It is expected that the object are in the current window.
// obtain the WebObjectSource and WebReportSource interfaces from the WebObjectsFactory
WebObjectsFactory factory = WebObjectsFactory.getInstance();
WebObjectSource objectSource = factory.getObjectSource();
WebReportSource reportSource = factory.getReportSource();
// get the messageID, stateID, prompt index and prompt answer are obtained from the HTML form data
String messageID = "";
int stateID = 1;
int pin = 1;
String promptAnswer = "";
int blockBegin = 1;
// expect that the object is in the current window
String highlightObjectID = "";
int highlightObjectType = 12;
// specify the maximum number answers that are displayed at any given time
int maxObjects = 25;
try {
// obtain the report instance
WebReportInstance reportInstance = reportSource.getInstance(messageID, stateID);
// check for prompted and non-prompted reports
WebPrompt prompt = reportInstance.getPrompts().findPromptByPIN(pin);
if(prompt == null) {
Log.logger.log(Level.ERROR, "Unable to find the specified prompt instance!");
return;
}
// load the existing answer XML
prompt.populateAnswer(promptAnswer);
// get the prompt type and check if the prompt had an original, default or previous answer, or
// if no answer was specified. Once this information is retrieved, set the maximum number of
// answers for display at any given time. This value is obtained from the maxObjects variable
switch (prompt.getType()) {
case EnumWebPromptType.WebPromptTypeObjects:
WebObjectsPrompt objPrompt = (WebObjectsPrompt) prompt;
if(objPrompt.getSearchRestriction() != null) {
objPrompt.getSearchRestriction().setBlockBegin(blockBegin);
objPrompt.getSearchRestriction().setBlockCount(maxObjects);
}
break;
case EnumWebPromptType.WebPromptTypeElements:
WebElementsPrompt elemPrompt = (WebElementsPrompt) prompt;
elemPrompt.setBlockBegin(blockBegin);
elemPrompt.setBlockCount(maxObjects);
break;
case EnumWebPromptType.WebPromptTypeExpression:
WebExpressionPrompt expPrompt = (WebExpressionPrompt) prompt;
if(expPrompt.getOrigin() != null && expPrompt.getOrigin().getType() == EnumDSSXMLObjectTypes.DssXmlTypeSearch) {
((WebSearch) expPrompt.getOrigin()).setBlockBegin(blockBegin);
((WebSearch) expPrompt.getOrigin()).setBlockCount(maxObjects);
}
break;
case EnumWebPromptType.WebPromptTypeDimty:
WebDimtyPrompt dmyPrompt = (WebDimtyPrompt) prompt;
if(dmyPrompt.getSearchRestriction() != null) {
dmyPrompt.getSearchRestriction().setBlockBegin(blockBegin);
dmyPrompt.getSearchRestriction().setBlockCount(maxObjects);
}
break;
default:
break;
}
// get the Display XML
WebDisplayHelper displayHelper = prompt.getDisplayHelper();
WebDefaultDisplaySettings defaultSettings = displayHelper.getDefaultDisplaySettings();
// enable default highlighting
defaultSettings.setUseDefaultHighlighting(true);
defaultSettings.setUseDetailedHighlighting(true);
defaultSettings.setUseDefaultSelection(true);
//defaultSettings.setHighlightEnabled(true);
//defaultSettings.setDetailed(true);
//defaultSettings.setSelectEnabled(true);
/* Note that the default element source is used only if the default highlighting algorithm
highlights an attribute. It is used only for expression prompts.
For element prompts, the attribute is marked highlighted with details
and hence is not affected by the default highlighting algorithm.
*/
// obtain the default element source and specify the maximum number of elements
WebElementSource elemSrc = defaultSettings.getElementSource();
elemSrc.setBlockBegin(blockBegin);
elemSrc.setBlockCount(maxObjects);
/ obtain the display unit to be highlighted
WebObjectInfo highlightObj = objectSource.getObject(highlightObjectID, highlightObjectType);
WebDisplayUnits availUnits = displayHelper.getAvailableDisplayUnits();
WebDisplayUnit highlightDisplayUnit = availUnits.findItem(highlightObj);
// confirm that the object is in current window
if(highlightDisplayUnit != null)
// highlight the unit with details
highlightDisplayUnit.highlightUnit(true);
promptAnswer = prompt.getAnswerXML(true); // Encoded for HTML use...
}
catch (WebObjectsException e) {
Log.logger.log(Level.ERROR, e.getMessage());
}