{
layout = request.getParameter("layout");
if ( layout != null && layout.length() > 0 )
{
PortletWindow window = requestContext.getActionWindow();
ContentFragment targetFragment = requestPage.getContentFragmentById(window.getId().toString());
if ( targetFragment == null )
{
// ignore no longer consistent page definition
return;
}
if ( addLayout )
{
try
{
Fragment fragment = pageManager.newFragment();
fragment.setType(Fragment.LAYOUT);
fragment.setName(layout);
targetFragment.getFragments().add(fragment);
pageManager.updatePage(requestPage);
}
catch (Exception e)
{
throw new PortletException("failed to add portlet " + layout + " to page: " + requestPage+": "+e.getMessage(), e);
}
}
else if ( !layout.equals(targetFragment.getName()) )
{
try
{
// layout portlet change
targetFragment.setName(layout);
pageManager.updatePage(requestPage);
entityAccess.updatePortletEntity(window.getPortletEntity(), targetFragment);
entityAccess.storePortletEntity(window.getPortletEntity());
windowAccess.createPortletWindow(window.getPortletEntity(), targetFragment.getId());
return;
}
catch (Exception e)
{
throw new PortletException("Unable to update page: "+e.getMessage(), e);