{
throw new Exception( FRAGMENTID + " not provided; must specify portlet or layout id" );
}
resultMap.put(FRAGMENTID, moveFragmentId);
Fragment currentLayoutFragment = null;
Fragment moveToLayoutFragment = null;
// when layoutId is null we use old behavior, ignoring everything to do with multiple layout fragments
if ( layoutId != null && layoutId.length() > 0 && iMoveType != CARTESIAN )
{
Page page = requestContext.getPage();
currentLayoutFragment = page.getFragmentById( layoutId );
if ( currentLayoutFragment == null )
{
throw new Exception("layout id not found: " + layoutId );
}
else
{
// determine if layoutId parameter refers to the current or the move target layout fragment
moveToLayoutFragment = currentLayoutFragment;
Iterator layoutChildIter = moveToLayoutFragment.getFragments().iterator();
while ( layoutChildIter.hasNext() )
{
Fragment childFrag = (Fragment)layoutChildIter.next();
if ( childFrag != null )
{
if ( moveFragmentId.equals( childFrag.getId() ) )
{
moveToLayoutFragment = null;
break;
}
}
}
if ( moveToLayoutFragment != null )
{
// figure out the current layout fragment - must know to be able to find the portlet
// fragment by row/col when a new page is created
Fragment root = requestContext.getPage().getRootFragment();
currentLayoutFragment = getParentFragmentById(moveFragmentId, root);
}
}
if ( currentLayoutFragment == null )
{
// report error
throw new Exception("parent layout id not found for portlet id:" + moveFragmentId );
}
}
if (false == checkAccess(requestContext, JetspeedActions.EDIT))
{
Page page = requestContext.getPage();
Fragment fragment = page.getFragmentById(moveFragmentId);
if (fragment == null)
{
success = false;
resultMap.put(REASON, "Fragment not found");
return success;
}
// remember current row/column of porlet fragment
int column = fragment.getLayoutColumn();
int row = fragment.getLayoutRow();
// rememeber current row/column of parent layout fragment and move-to layout fragment
int layoutColumn = -1, layoutRow = -1;
int moveToLayoutColumn = -1, moveToLayoutRow = -1;
if ( currentLayoutFragment != null )
{
layoutColumn = currentLayoutFragment.getLayoutColumn();
layoutRow = currentLayoutFragment.getLayoutRow();
if ( moveToLayoutFragment != null )
{
moveToLayoutColumn = moveToLayoutFragment.getLayoutColumn();
moveToLayoutRow = moveToLayoutFragment.getLayoutRow();
}
}
if (!createNewPageOnEdit(requestContext))
{
success = false;
resultMap.put(REASON, "Insufficient access to edit page");
return success;
}
status = "refresh";
// translate old portlet id to new portlet id
Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
if (newFragment == null)
{
success = false;
resultMap.put( REASON, "Failed to find new fragment for portlet id: " + moveFragmentId );
return success;
}
moveFragmentId = newFragment.getId();
if ( currentLayoutFragment != null )
{
newFragment = getFragmentIdFromLocation(layoutRow, layoutColumn, requestContext.getPage());
if (newFragment == null)
{
success = false;
resultMap.put( REASON, "Failed to find new parent layout fragment id: " + currentLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
return success;
}
currentLayoutFragment = newFragment;
if ( moveToLayoutFragment != null )
{
newFragment = getFragmentIdFromLocation(moveToLayoutRow, moveToLayoutColumn, requestContext.getPage());
if (newFragment == null)
{
success = false;
resultMap.put( REASON, "Failed to find new move-to layout fragment id: " + moveToLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
return success;
}
moveToLayoutFragment = newFragment;
}
}
}
if ( moveToLayoutFragment != null )
{
success = moveFragment( requestContext,
pageManager,
batch,
resultMap,
moveFragmentId,
moveToLayoutFragment,
currentLayoutFragment ) ;
}
else
{
PortletPlacementContext placement = null;
if ( currentLayoutFragment != null )
placement = new PortletPlacementContextImpl(requestContext, currentLayoutFragment, 1);
else
{
placement = new PortletPlacementContextImpl(requestContext);
}
Fragment fragment = placement.getFragmentById(moveFragmentId);
if (fragment == null)
{
success = false;
resultMap.put(REASON, "Failed to find fragment for portlet id: " + moveFragmentId );
return success;
}
Coordinate returnCoordinate = null;
float oldX = 0f, oldY = 0f, oldZ = 0f, oldWidth = 0f, oldHeight = 0f;
float x = -1f, y = -1f, z = -1f, width = -1f, height = -1f;
boolean absHeightChanged = false;
String posExtended = getActionParameter(requestContext, DESKTOP_EXTENDED);
if ( posExtended != null )
{
Map fragmentProperties = fragment.getProperties();
if ( fragmentProperties == null )
{
success = false;
resultMap.put(REASON, "Failed to acquire fragment properties map for portlet id: " + moveFragmentId );
return success;
}
String oldDeskExt = (String)fragmentProperties.get( DESKTOP_EXTENDED );
resultMap.put( OLD_DESKTOP_EXTENDED, ( (oldDeskExt != null) ? oldDeskExt : "" ) );
fragmentProperties.put( DESKTOP_EXTENDED, posExtended );
}
// Only required for moveabs
if (iMoveType == ABS)
{
Coordinate a_oCoordinate = getCoordinateFromParams(requestContext);
returnCoordinate = placement.moveAbsolute(fragment, a_oCoordinate);
String sHeight = getActionParameter(requestContext, HEIGHT);
if ( sHeight != null && sHeight.length() > 0 )
{
oldHeight = fragment.getLayoutHeight();
height = Float.parseFloat(sHeight);
fragment.setLayoutHeight(height);
absHeightChanged = true;
}
}
else if (iMoveType == LEFT)
{
returnCoordinate = placement.moveLeft(fragment);
}
else if (iMoveType == RIGHT)
{
returnCoordinate = placement.moveRight(fragment);
}
else if (iMoveType == UP)
{
returnCoordinate = placement.moveUp(fragment);
}
else if (iMoveType == DOWN)
{
returnCoordinate = placement.moveDown(fragment);
}
else if (iMoveType == CARTESIAN)
{
String sx = getActionParameter(requestContext, X);
String sy = getActionParameter(requestContext, Y);
String sz = getActionParameter(requestContext, Z);
String sWidth = getActionParameter(requestContext, WIDTH);
String sHeight = getActionParameter(requestContext, HEIGHT);
if (sx != null)
{
oldX = fragment.getLayoutX();
x = Float.parseFloat(sx);
fragment.setLayoutX(x);
}
if (sy != null)
{
oldY = fragment.getLayoutY();
y = Float.parseFloat(sy);
fragment.setLayoutY(y);
}
if (sz != null)
{
oldZ = fragment.getLayoutZ();
z = Float.parseFloat(sz);
fragment.setLayoutZ(z);
}
if (sWidth != null)
{
oldWidth = fragment.getLayoutWidth();
width = Float.parseFloat(sWidth);
fragment.setLayoutWidth(width);
}
if (sHeight != null)
{
oldHeight = fragment.getLayoutHeight();
height = Float.parseFloat(sHeight);
fragment.setLayoutHeight(height);
}
}
// synchronize back to the page layout root fragment
Page page = placement.syncPageFragments();