if (!(element.getParent() instanceof Document) &&
!arguments.getTemplateResolution().getTemplateMode().equals(TEMPLATE_MODE_LEGACYHTML5)) {
logger.error("layout:decorator attribute must appear in the root element of your content page");
throw new IllegalArgumentException("layout:decorator attribute must appear in the root element of your content page");
}
Document document = arguments.getDocument();
// Locate the decorator page
StandardFragment fragment = StandardFragmentProcessor.computeStandardFragmentSpec(
arguments.getConfiguration(), arguments, element.getAttributeValue(attributeName),
DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_FRAGMENT);
Template decoratortemplate = arguments.getTemplateRepository().getTemplate(new TemplateProcessingParameters(
arguments.getConfiguration(), fragment.getTemplateName(), arguments.getContext()));
element.removeAttribute(attributeName);
Document decoratordocument = decoratortemplate.getDocument();
Element decoratorrootelement = decoratordocument.getFirstElementChild();
// Gather all fragment parts from this page
Map<String,Object> fragments = findFragments(document.getElementChildren());
// Decide which kind of decorator to apply, given the decorator page root element