{
// generate content fragment hierarchy for specific fragment;
// merges fragment hierarchy and attributes from fragments,
// page fragments, and fragment references in page, page template,
// and fragment definitions
ContentFragmentImpl contentFragmentImpl = null;
String contentFragmentId = null;
if (fragment instanceof Fragment)
{
// construct content fragment to reflect fragment hierarchy
Fragment fragmentFragment = (Fragment)fragment;
contentFragmentId = ((parentId != null) ? parentId+CONTENT_FRAGMENT_ID_SEPARATOR+fragmentFragment.getId() : fragmentFragment.getId());
contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, definition, fragmentFragment, null, null, template, template);
// set content fragment attributes
mergeContentFragmentAttributes(contentFragmentImpl, fragmentFragment);
// set content fragment security constraints
setContentFragmentSecurityConstraints(contentFragmentImpl, fragmentFragment);
}
else if (fragment instanceof PageFragment)
{
PageFragment pageFragmentFragment = (PageFragment)fragment;
contentFragmentId = ((parentId != null) ? parentId+CONTENT_FRAGMENT_ID_SEPARATOR+pageFragmentFragment.getId() : pageFragmentFragment.getId());
// check if page fragment definition in page template
// or if in primary page or template
if ((definition != pageOrTemplate) || template)
{
// consume page fragment and build fragment hierarchy from page
BaseFragmentElement pageRootFragment = pageOrTemplate.getRootFragment();
if (pageRootFragment instanceof FragmentReference)
{
// consume top level page fragment reference and build fragment
// hierarchy from referenced fragment
FragmentReference fragmentReferenceFragment = (FragmentReference)pageRootFragment;
contentFragmentId += CONTENT_FRAGMENT_ID_SEPARATOR+fragmentReferenceFragment.getId();
Fragment [] fragmentFragment = new Fragment[]{null};
contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, pageOrTemplate, fragmentReferenceFragment, template, fragmentFragment);
// inherit page fragment attributes
mergeContentFragmentAttributes(contentFragmentImpl, pageFragmentFragment);
// inherit fragment reference attributes
mergeContentFragmentAttributes(contentFragmentImpl, fragmentReferenceFragment);
// set content fragment security constraints
setContentFragmentSecurityConstraints(contentFragmentImpl, fragmentReferenceFragment);
// test resolved reference id
if (fragmentFragment[0] != null)
{
// merge content fragment attributes
mergeContentFragmentAttributes(contentFragmentImpl, fragmentFragment[0]);
}
else
{
// constructed content fragment for fragment reference
// since reference id was not resolved
contentFragmentImpl.setType(ContentFragment.REFERENCE);
}
}
else if (pageRootFragment instanceof Fragment)
{
// construct content fragment to reflect page fragment hierarchy
Fragment fragmentFragment = (Fragment)pageRootFragment;
contentFragmentId += CONTENT_FRAGMENT_ID_SEPARATOR+fragmentFragment.getId();
contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, pageOrTemplate, fragmentFragment, null, null, false, false);
// inherit page fragment attributes
mergeContentFragmentAttributes(contentFragmentImpl, pageFragmentFragment);
// merge content fragment attributes
mergeContentFragmentAttributes(contentFragmentImpl, fragmentFragment);
// set content fragment security constraints
setContentFragmentSecurityConstraints(contentFragmentImpl, fragmentFragment);
}
// ensure that page/fragment hierarchy page root is a
// layout portlet by generating a transient locked
// parent layout fragment if necessary
if (!contentFragmentImpl.getType().equals(ContentFragment.LAYOUT))
{
ContentFragmentImpl layoutContentFragmentImpl = newContentFragment("", pageOrTemplate, null, null, null, null, false, true);
layoutContentFragmentImpl.setType(ContentFragment.LAYOUT);
layoutContentFragmentImpl.setName(defaultLayoutPortletName);
layoutContentFragmentImpl.getFragments().add(contentFragmentImpl);
contentFragmentImpl = layoutContentFragmentImpl;
}
}
else
{