{
if ( ! fragment.getId().equals( page.getRootFragment().getId() ) )
{
throw new Exception( "for layout fragments, change action applies to only to the root layout fragment (i.e. it does not apply to nested layout fragments)" );
}
PageActionAccess pageActionAccess = (PageActionAccess)requestContext.getAttribute( PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE );
if ( pageActionAccess == null )
{
throw new Exception( "cannot change action for root layout fragment due to null PageActionAccess object" );
}
//pageActionAccess.
PortletWindow window = requestContext.getPortletWindow(fragment);
if (!window.isValid())
{
throw new Exception("Failed to retrieve Portlet Definition for: "+ fragment.getId() + ", " + fragment.getName());
}
PortletMode currentMode = requestContext.getPortalURL().getNavigationalState().getMode( window );
WindowState currentState = requestContext.getPortalURL().getNavigationalState().getState( window );
boolean requestedModeAlreadySet = false;
if ( requestedMode == null )
{
requestedModeAlreadySet = true;
}
else
{
if ( requestedMode.equals( PortletMode.EDIT.toString() ) )
{
if( pageActionAccess.isEditing() )
requestedModeAlreadySet = true;
else
{
if ( pageActionAccess.isEditAllowed())
{
pageActionAccess.setEditing( true );
resultMap.put(STATUS, status);
resultMap.put(OLD_PORTLET_MODE, currentMode.toString());
resultMap.put(PORTLET_MODE, requestedMode);
}
else
{
throw new Exception( "permissions do no allow page edit" );
}
}
}
else if ( requestedMode.equals( PortletMode.VIEW.toString() ) )
{
pageActionAccess.setEditing( false );
//if ( currentMode.equals( PortletMode.HELP ) )
resultMap.put(STATUS, status);
resultMap.put(OLD_PORTLET_MODE, currentMode.toString());
resultMap.put(PORTLET_MODE, requestedMode);
}