throw new IllegalArgumentException("Portlet type and name not specified");
}
// get page root content fragment
ContentPageImpl contentPageImpl = (ContentPageImpl)contentPage;
ContentFragmentImpl pageRootContentFragmentImpl = contentPageImpl.getPageRootContentFragment();
if ((pageRootContentFragmentImpl != null) && pageRootContentFragmentImpl.isLocked())
{
pageRootContentFragmentImpl = (ContentFragmentImpl)pageRootContentFragmentImpl.getNonTemplateLayoutFragment();
}
if ((pageRootContentFragmentImpl == null) || pageRootContentFragmentImpl.isLocked())
{
throw new IllegalArgumentException("Page root content fragment not found or is locked");
}
// retrieve current page or template and root fragment from page manager
BaseFragmentsElement pageOrTemplate = getPageOrTemplate(contentPageImpl.getPageOrTemplate().getPath());
BaseFragmentElement rootFragment = pageOrTemplate.getRootFragment();
if (!(rootFragment instanceof Fragment))
{
throw new IllegalArgumentException("New fragment cannot be added to page root fragment");
}
Fragment fragment = (Fragment)rootFragment;
if (!Fragment.LAYOUT.equals(fragment.getType()))
{
throw new IllegalArgumentException("New fragment cannot be added to non-layout page root fragment");
}
// check for edit permission
fragment.checkAccess(JetspeedActions.EDIT);
// create fragment and add to layout root fragment
Fragment newFragment = pageManager.newFragment();
newFragment.setType(contentFragment.getType());
newFragment.setName(contentFragment.getName());
if (!Utils.isNull(row))
{
newFragment.setLayoutRow(row);
}
if (!Utils.isNull(column))
{
newFragment.setLayoutColumn(column);
}
fragment.getFragments().add(newFragment);
// update page in page manager
updatePage(pageOrTemplate);
// update content page context
ContentFragmentImpl contentFragmentImpl = (ContentFragmentImpl)contentFragment;
contentFragmentImpl.initialize(this, pageOrTemplate, pageOrTemplate, newFragment, null, null, false, false);
if (!Utils.isNull(row))
{
contentFragmentImpl.setLayoutRow(null, null, row);
}
if (!Utils.isNull(column))
{
contentFragmentImpl.setLayoutColumn(null, null, column);
}
pageRootContentFragmentImpl.getFragments().add(contentFragmentImpl);
String newContentFragmentId = pageRootContentFragmentImpl.getId()+CONTENT_FRAGMENT_ID_SEPARATOR+contentFragmentImpl.getFragment().getId();
contentFragmentImpl.setId(newContentFragmentId);
return contentFragmentImpl;
}
catch (Exception e)
{
throw new PageLayoutComponentException("Unexpected exception: "+e, e);