FormatRendererContext formatRendererContext)
throws IOException, RendererException {
NDimensionalIndex index = NDimensionalIndex.ZERO_DIMENSIONS;
LayoutModule module = formatRendererContext.getLayoutModule();
// Save the current DeviceLayoutContext to restore later.
// Set the current device layout context.
formatRendererContext.pushDeviceLayoutContext(context);
RuntimeDeviceLayout deviceLayout = formatRendererContext.getDeviceLayout();
LayoutAttributes attributes = factory.createLayoutAttributes();
attributes.setDeviceLayoutContext(context);
// Get the style sheet associated with the layout and push it into the
// styling engine.
RuntimeDeviceLayout runtimeDeviceLayout = context.getDeviceLayout();
CompiledStyleSheet layoutStyleSheet =
runtimeDeviceLayout.getCompiledStyleSheet();
// Set up the styling engine with the applicable style sheets.
FormatStylingEngine formatStylingEngine =
formatRendererContext.getFormatStylingEngine();
// First add the layout style sheet into the styling engine.
formatStylingEngine.pushStyleSheet(layoutStyleSheet);
// Then add the theme style sheet(s) into the styling engine.
CompiledStyleSheetCollection themeStyleSheets =
context.getThemeStyleSheets();
if (themeStyleSheets != null) {
themeStyleSheets.pushAll(formatStylingEngine);
}
// else, allow tests to run without doing the above. Dodgy.
// Process a nested inclusion, this is done after the page context has been
// updated in order to make sure that the nesting depth is correct.
boolean inclusion = (context.getIncludingDeviceLayoutContext() != null);
if (inclusion) {
module.beginNestedInclusion();
}
module.writeOpenLayout(attributes);
Fragment fragment = formatRendererContext.getCurrentFragment();
if (fragment == null) {
if (logger.isDebugEnabled()) {
String name =
deviceLayout != null ? deviceLayout.getName():null;
logger.debug("Writing out the Layout named "
+ name + " to the page");
// Write the format tree
}
Format root = deviceLayout.getRootFormat();
if (root != null) {
FormatInstance rootInstance =
formatRendererContext.getFormatInstance(
root, index);
formatRendererContext.renderFormat(rootInstance);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Empty layout");
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Writing out the fragment named "
+ fragment.getName() + " to the page");
}
// Write out the fragment and the fragment link list which contains
// links to the fragment's parent and peer fragments.
if (!module.getSupportsFragmentLinkListTargetting()) {
// Write out parent/peer fragment link list *after* the fragment.
// This is necessary as the fragment link list is being appended to
// the existing content and must therefore come after it.
// First, write out the fragment itself
FormatInstance fragmentInstance =
formatRendererContext.getFormatInstance(
fragment, index);
formatRendererContext.renderFormat(fragmentInstance);
// Then, write out the parent/peer fragment link list.
writeFragmentLinkList(fragment, formatRendererContext);
} else {
// Write out parent/peer fragment link list *before* the fragment.
// This is necessary as the fragment link list is going into it's
// own pane which would be empty if we tried to render it before
// creating them.
// First, write out parent/peer fragment link list.
writeFragmentLinkList(fragment, formatRendererContext);
// Then, write out the fragment itself.
FormatInstance fragmentInstance =
formatRendererContext.getFormatInstance(
fragment, index);
formatRendererContext.renderFormat(fragmentInstance);
}
}
// Write the link to the default segment if necessary.
SegmentLinkWriter segmentLinkWriter =
formatRendererContext.getSegmentLinkWriter();
segmentLinkWriter.writeDefaultSegmentLink();
module.writeCloseLayout(attributes);
// Finish processing the nested inclusion.
if (inclusion) {
module.endNestedInclusion();
}
// Clean up the styling information we added to the styling engine.
// This should be done in reverse order.
// First we remove the theme style sheet(s).