String sharedDataKey = String.valueOf(item.getId());
//
// Get the Rave Widget for this regionWidget instance
//
W3CWidget contextualizedWidget = (W3CWidget) widgetService.getWidget(user, sharedDataKey, item.getWidget());
//
// TODO make this do something useful; currently these preferences aren't
// actually available in the Widget Instance as prefs are managed separately in Wookie
//
JSONObject userPrefs = new JSONObject();
if (item.getPreferences() != null) {
for (RegionWidgetPreference regionWidgetPreference : item.getPreferences()) {
try {
userPrefs.put(regionWidgetPreference.getName(), regionWidgetPreference.getValue());
} catch (JSONException e) {
logger.error("Exception caught adding preference to JSONObject: " + regionWidgetPreference, e);
}
}
}
//
// Use width and height attributes if available, otherwise set to "100%"
//
String width = "100%";
String height = "100%";
if (contextualizedWidget.getWidth() > 0)
width = String.valueOf(contextualizedWidget.getWidth()) + "px";
if (contextualizedWidget.getHeight() > 0)
height = String.valueOf(contextualizedWidget.getHeight()) + "px";
// get attributes about the sub page this regionWidget is on. This is needed to assist the client in
// determining which gadgets are on visible tabs/sub pages initially to make widget rendering more efficient
Long pageId = null;
String pageName = "";
boolean isDefault = false;
Page page = item.getRegion().getPage();
if (PageType.SUB_PAGE.equals(page.getPageType())) {
pageId = page.getId();
pageName = page.getName();
// check to see if this regionWidget is on the first sub page, which will be the default
// subpage rendered if the user doesn't specify which subpage via the URL hash
isDefault = isDefaultSubPage(page);
}
//
// Construct and return script block
//
return String.format(SCRIPT_BLOCK,
item.getRegion().getId(),
WIDGET_TYPE,
item.getId(),
contextualizedWidget.getUrl(),
height,
width,
item.isCollapsed(),
item.getWidget().getId(),
item.isLocked(),