// get decorations
Theme theme = decorationFactory.getTheme( page, request );
HeaderResource hr = getHeaderResourceFactory().getHeaderResouce( request );
JetspeedDesktopContext desktopContext = new JetspeedDesktopContextImpl( request, this.baseUrlAccess, theme, hr, defaultLayoutTemplateExtension );
String layoutTemplateIdPropertyName = null;
if ( "true".equals( request.getRequest().getParameter( "jsprintmode" ) ) )
layoutTemplateIdPropertyName = JetspeedDesktopContext.LAYOUT_PRINT_TEMPLATE_ID_PROP;
layoutDecorationTemplatePath = desktopContext.getLayoutTemplatePath( layoutTemplateIdPropertyName );
layoutDecorationTemplatePathWasAssigned = true;
RequestDispatcher dispatcher = request.getRequest().getRequestDispatcher( layoutDecorationTemplatePath );
hr.dojoEnable();
request.getRequest().setAttribute( JetspeedDesktopContext.DESKTOP_CONTEXT_ATTRIBUTE, desktopContext );
request.getRequest().setAttribute( JetspeedDesktopContext.DESKTOP_REQUEST_CONTEXT_ATTRIBUTE, request );
request.getRequest().setAttribute( JetspeedDesktopContext.DESKTOP_COMPONENT_MANAGER_ATTRIBUTE, Jetspeed.getComponentManager() );
String layoutDecorationName = desktopContext.getLayoutDecorationName();
boolean inclStyleLayout = hr.isHeaderSectionIncluded( HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT );
String dojoConfigContentCacheKey = DOJO_CONFIG_LAYOUT_VAR_NAME + "." + layoutDecorationName;
String dojoConfigContent = getCachedContent( dojoConfigContentCacheKey );
if ( dojoConfigContent == null )
{
String portletDecorationsBasePath = decorationFactory.getPortletDecorationsBasePath();
StringBuffer dojoConfigAddOn = new StringBuffer();
dojoConfigAddOn.append( " " ).append( DOJO_CONFIG_LAYOUT_DECORATION_PATH_VAR_NAME ).append( " = \"" ).append( desktopContext.getLayoutBasePath() ).append( "\";" ).append( EOL );
dojoConfigAddOn.append( " " ).append( DOJO_CONFIG_LAYOUT_VAR_NAME ).append( " = \"" ).append( layoutDecorationName ).append( "\";" ).append( EOL );
dojoConfigAddOn.append( " " ).append( DOJO_CONFIG_PORTLET_DECORATIONS_PATH_VAR_NAME ).append( " = \"" ).append( portletDecorationsBasePath ).append( "\";" ).append( EOL );
LayoutDecoration desktopLayoutDecoration = decorationFactory.getLayoutDecoration( layoutDecorationName, request );
if ( desktopLayoutDecoration != null )
{
boolean atLeastOneFound = false;
StringBuffer loadingPropsBuffer = new StringBuffer();
loadingPropsBuffer.append( " " ).append( DOJO_CONFIG_LOADING_IMGPROPS_NAME ).append( " = { " );
for ( int i = 0 ; i < DESKTOP_LOADING_PROPERTY_NAMES.length ; i++ )
{
String propValue = desktopLayoutDecoration.getProperty( DESKTOP_LOADING_IMG_NAME_PREFIX + DESKTOP_LOADING_PROPERTY_NAMES[ i ] );
if ( propValue != null )
{
if ( atLeastOneFound )
{
loadingPropsBuffer.append( ", " );
}
else
{
atLeastOneFound = true;
}
String usePropertyName = DESKTOP_LOADING_PROPERTY_NAMES[ i ];
if ( DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES != null && DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES.length > i && DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES[i] != null )
usePropertyName = DESKTOP_LOADING_OUTPUT_PROPERTY_NAMES[i];
loadingPropsBuffer.append( usePropertyName ).append( ": " ).append( propValue );
}
}
loadingPropsBuffer.append( " };" );
if ( atLeastOneFound )
dojoConfigAddOn.append( loadingPropsBuffer.toString() ).append( EOL );
addPageEditorSettings( dojoConfigAddOn, desktopLayoutDecoration );
}
else
{
log.error( "Failed to find desktop layout decoration " + layoutDecorationName + " - layout decoration properties cannot be added to content." );
}
Set desktopPortletDecorationsNames = decorationFactory.getDesktopPortletDecorations( request );
String portletDecorationNamesContent = HeaderResourceLib.makeJSONStringArray( desktopPortletDecorationsNames );
dojoConfigAddOn.append( " " ).append( DOJO_CONFIG_PORTLET_DECORATIONS_ALLOWED_VAR_NAME ).append( " = " ).append( portletDecorationNamesContent ).append( ";" );
StringBuffer pDecsOut = new StringBuffer();
Iterator desktopPortletDecorationsNamesIter = desktopPortletDecorationsNames.iterator();
while ( desktopPortletDecorationsNamesIter.hasNext() )
{
String desktopPortletDecorationName = (String)desktopPortletDecorationsNamesIter.next();
PortletDecoration desktopPortletDecoration = decorationFactory.getPortletDecoration( desktopPortletDecorationName, request );
StringBuffer pOut = new StringBuffer();
String actionButtonOrderContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_ORDER );
if ( actionButtonOrderContent != null && actionButtonOrderContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_ORDER ).append( ": " ).append( actionButtonOrderContent );
}
String actionNoImageContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_NOIMAGE );
if ( actionNoImageContent != null && actionNoImageContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ACTION_NOIMAGE ).append( ": " ).append( actionNoImageContent );
}
String actionMenuOrderContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_MENU_ORDER );
if ( actionMenuOrderContent != null && actionMenuOrderContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ACTION_MENU_ORDER ).append( ": " ).append( actionMenuOrderContent );
}
String windowActionButtonTooltip = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_TOOLTIP );
if ( windowActionButtonTooltip != null && windowActionButtonTooltip.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_TOOLTIP ).append( ": " ).append( windowActionButtonTooltip );
}
String windowActionButtonMax = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ACTION_BUTTON_MAX );
if ( windowActionButtonMax != null && windowActionButtonMax.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ACTION_BUTTON_MAX ).append( ": " ).append( windowActionButtonMax );
}
String iconEnabledContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_ENABLED );
if ( iconEnabledContent != null && iconEnabledContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ICON_ENABLED ).append( ": " ).append( iconEnabledContent );
}
String iconPathContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_ICON_PATH );
if ( iconPathContent != null && iconPathContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_ICON_PATH ).append( ": " ).append( iconPathContent ).append( ";" ).append( EOL );
}
String titlebarEnabledContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_TITLEBAR_ENABLED );
if ( titlebarEnabledContent != null && titlebarEnabledContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_TITLEBAR_ENABLED ).append( ": " ).append( titlebarEnabledContent );
}
String resizebarEnabledContent = desktopPortletDecoration.getProperty( HeaderResource.HEADER_CONFIG_DESKTOP_WINDOW_RESIZEBAR_ENABLED );
if ( resizebarEnabledContent != null && resizebarEnabledContent.length() > 0 )
{
pOut.append( ( pOut.length() > 0 ) ? ", " : "" ).append( HeaderResource.DESKTOP_JSON_WINDOW_RESIZEBAR_ENABLED ).append( ": " ).append( resizebarEnabledContent );
}
if ( pOut.length() > 0 )
{
if ( pDecsOut.length() == 0 )
{
pDecsOut.append( DOJO_CONFIG_PORTLET_DECORATIONS_CONFIG_VAR_NAME ).append( " = { " );
}
else
{
pDecsOut.append( ", " );
}
pDecsOut.append( "\"" ).append( desktopPortletDecorationName ).append( "\": { " ).append( pOut.toString() ).append( " }" ).append( EOL );
}
} // while ( desktopPortletDecorationsNamesIter.hasNext() )
if ( pDecsOut.length() > 0 )
{
pDecsOut.append( " }" );
dojoConfigAddOn.append( EOL ).append( " " ).append( pDecsOut.toString() ).append( ";" );
}
dojoConfigContent = dojoConfigAddOn.toString();
setCachedContent( dojoConfigContentCacheKey, dojoConfigContent );
}
if ( dojoConfigContent != null )
{
hr.addHeaderSectionFragment( DOJO_CONFIG_LAYOUT_VAR_NAME, HeaderResource.HEADER_SECTION_DOJO_CONFIG, dojoConfigContent );
}
if ( inclStyleLayout )
{
String contextPath = request.getRequest().getContextPath();
String styleLayoutContentCacheKey = (HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT + "." + layoutDecorationName + "." + contextPath);
String styleLayoutContent = getCachedContent( styleLayoutContentCacheKey );
if ( styleLayoutContent == null )
{
String portletDecorationsBasePath = decorationFactory.getPortletDecorationsBasePath();
String portletDecorationsBaseRelative = portletDecorationsBasePath;
if ( portletDecorationsBaseRelative != null && portletDecorationsBaseRelative.length() > 1 && portletDecorationsBaseRelative.indexOf( '/' ) == 0 )
{
portletDecorationsBaseRelative = portletDecorationsBaseRelative.substring( 1 );
}
StringBuffer desktopThemeStyleLink = new StringBuffer();
int stylesheetCount = 0;
Iterator stylesheetIter = theme.getStyleSheets().iterator();
while ( stylesheetIter.hasNext() )
{
String stylesheetHref = (String)stylesheetIter.next();
if ( stylesheetHref != null && stylesheetHref.length() > 0 )
{
if ( ! stylesheetHref.startsWith( portletDecorationsBaseRelative ) )
{ // exclude portlet decorations - in desktop these are loaded via javascript
if ( stylesheetCount > 0 )
{
desktopThemeStyleLink.append( EOL );
}
desktopThemeStyleLink.append( "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen, projection\" href=\"" );
//desktopThemeStyleLink.append( desktopContext.getPortalResourceUrl( stylesheetHref ) ).append( "\"/>" );
desktopThemeStyleLink.append( contextPath + "/" + stylesheetHref ).append( "\"/>" );
stylesheetCount++;
}
}
}
styleLayoutContent = desktopThemeStyleLink.toString();
setCachedContent( styleLayoutContentCacheKey, styleLayoutContent );
}
if ( styleLayoutContent != null && styleLayoutContent.length() > 0 )
{
hr.setHeaderSectionType( HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT, HeaderResource.HEADER_TYPE_LINK_TAG );
hr.addHeaderSectionFragment( "desktop.style.layout", HeaderResource.HEADER_SECTION_DESKTOP_STYLE_LAYOUT, styleLayoutContent );
}
}
String layoutDecorationLocaleSuffix = "." + layoutDecorationName + "." + request.getLocale().toString();
String desktopActionLabelsCacheKey = DOJO_CONFIG_ACTION_LABELS_NAME + layoutDecorationLocaleSuffix;
String pageEditorLabelsCacheKey = DOJO_CONFIG_PAGEEDITOR_LABELS_NAME + layoutDecorationLocaleSuffix;
String pageEditorDialogLabelsCacheKey = DOJO_CONFIG_PAGEEDITOR_DIALOG_LABELS_NAME + layoutDecorationLocaleSuffix;
String desktopActionLabelsContent = getCachedContent( desktopActionLabelsCacheKey );
String pageEditorLabelsContent = getCachedContent( pageEditorLabelsCacheKey );
String pageEditorDialogLabelsContent = getCachedContent( pageEditorDialogLabelsCacheKey );
if ( desktopActionLabelsContent == null || pageEditorLabelsContent == null || pageEditorDialogLabelsContent == null )
{
ResourceBundle messages = desktopContext.getLayoutResourceBundle( request.getLocale() );
if ( desktopActionLabelsContent == null )
{
desktopActionLabelsContent = getResourcesAsJavascriptObject( DESKTOP_ACTION_RESOURCE_NAME_PREFIX, DESKTOP_ACTION_RESOURCE_NAMES, messages, DOJO_CONFIG_ACTION_LABELS_NAME, " ", true );
setCachedContent( desktopActionLabelsCacheKey, desktopActionLabelsContent );
}