{
throw new WebApplicationException(new IllegalArgumentException("Layout fragment not found for the fragment: " + fragmentId));
}
}
PortletPlacementContext ppc = null;
try
{
ppc = new PortletPlacementContextImpl(contentPage, portletRegistry, layoutFragment);
if ("left".equals(direction))
{
ppc.moveLeft(contentFragment);
}
else if ("right".equals(direction))
{
ppc.moveRight(contentFragment);
}
else if ("up".equals(direction))
{
ppc.moveUp(contentFragment);
}
else if ("down".equals(direction))
{
ppc.moveDown(contentFragment);
}
else
{
throw new WebApplicationException(new IllegalArgumentException("Invalid direction: " + direction));
}
// synchronize back to the page layout root fragment
contentPage = ppc.syncPageFragments(PageLayoutComponent.USER_PROPERTY_SCOPE, null);
}
catch (PortletPlacementException e)
{
throw new WebApplicationException(e);
}
}
else if (!StringUtils.isBlank(rowParam) && !StringUtils.isBlank(colParam))
{
int row = NumberUtils.toInt(rowParam, -1);
int col = NumberUtils.toInt(colParam, -1);
float posHeight = NumberUtils.toFloat(posHeightParam, -1.0f);
if (row != -1 && col != -1 && (contentFragment.getLayoutRow() != row || contentFragment.getLayoutColumn() != col))
{
try
{
ContentFragment layoutFragment = null;
boolean attach = false;
if (!StringUtils.isBlank(layoutFragmentId) && layoutFragmentId.equals("attach"))
{
layoutFragmentId = null;
attach = true;
}
if (!StringUtils.isBlank(layoutFragmentId))
{
layoutFragment = contentPage.getFragmentByFragmentId(layoutFragmentId);
if (layoutFragment == null)
{
throw new WebApplicationException(new IllegalArgumentException("Layout fragment not found with the specified id: " + layoutFragmentId));
}
}
else
{
layoutFragment = getParentFragment(contentPage.getNonTemplateRootFragment(), fragmentId);
if (layoutFragment == null)
{
throw new WebApplicationException(new IllegalArgumentException("Layout fragment not found for the fragment: " + fragmentId));
}
}
PortletPlacementContext ppc = new PortletPlacementContextImpl(contentPage, portletRegistry, layoutFragment);
Coordinate coordinate = new CoordinateImpl(0, 0, col, row);
ppc.moveAbsolute(contentFragment, coordinate);
if (posHeight != -1.0f)
{
pageLayoutComponent.updatePosition(contentFragment, -1.0f, -1.0f, -1.0f, -1.0f, posHeight, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
}
// synchronize back to the page layout root fragment
contentPage = ppc.syncPageFragments(PageLayoutComponent.USER_PROPERTY_SCOPE, null);
if (attach)
pageLayoutComponent.updateStateMode(contentFragment, JetspeedActions.NORMAL, null, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
}
catch (Exception e)
{
throw new WebApplicationException(e);
}
}
else if (!StringUtils.isBlank(layoutFragmentId) && layoutFragmentId.equals("attach"))
{
pageLayoutComponent.updateStateMode(contentFragment, JetspeedActions.NORMAL, null, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
}
}
else
{
float posX = NumberUtils.toFloat(posXParam, -1.0f);
float posY = NumberUtils.toFloat(posYParam, -1.0f);
float posZ = NumberUtils.toFloat(posZParam, -1.0f);
float posWidth = NumberUtils.toFloat(posWidthParam, -1.0f);
float posHeight = NumberUtils.toFloat(posHeightParam, -1.0f);
try
{
pageLayoutComponent.updatePosition(contentFragment, posX, posY, posZ, posWidth, posHeight, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
pageLayoutComponent.updateStateMode(contentFragment, JetspeedActions.DETACH, null, PageLayoutComponent.USER_PROPERTY_SCOPE, null);
if (layoutFragmentId != null && layoutFragmentId.equals("detach"))
{
// first time detach, reallocate column and move it to the back
ContentFragment layoutFragment = getParentFragment(contentPage.getNonTemplateRootFragment(), fragmentId);
if (layoutFragment == null)
{
throw new WebApplicationException(new IllegalArgumentException("Layout fragment not found for the fragment: " + fragmentId));
}
PortletPlacementContext ppc = new PortletPlacementContextImpl(contentPage, portletRegistry, layoutFragment);
int col = contentFragment.getLayoutColumn();
int row = ppc.getNumberRows((col <= 0) ? 0 : col - 1);
Coordinate coordinate = new CoordinateImpl(col, contentFragment.getLayoutRow(), col, row);
ppc.moveAbsolute(contentFragment, coordinate);
contentPage = ppc.syncPageFragments(PageLayoutComponent.USER_PROPERTY_SCOPE, null);
}
}
catch (Exception e)
{
throw new WebApplicationException(e);