if ( addLayout || request.getParameter("jsChangeLayout") != null )
{
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);
}
}
}
return;
}
if ( request.getParameter("jsSubmitPage" ) != null )
{
String jsPageName = request.getParameter("jsPageName");
if ( jsPageName != null && jsPageName.length() > 0 && jsPageName.indexOf(Folder.PATH_SEPARATOR) == -1 )
{
try
{
Folder parent = (Folder)requestPage.getParent();
if (parent != null)
{
String path = parent.getPath();
if (path.endsWith(Folder.PATH_SEPARATOR))
{
path = path + getEscapedPageName(jsPageName);
}
else
{
path = path + Folder.PATH_SEPARATOR
+ getEscapedPageName(jsPageName);
}
Page page = pageManager.newPage(path);
if ( layout == null || layout.length() == 0 )
{
layout = requestPage.getRootFragment().getName();
}
page.getRootFragment().setName(layout);
page.setDefaultDecorator(requestPage.getDefaultDecorator(Fragment.LAYOUT), Fragment.LAYOUT);
page.setDefaultDecorator(requestPage.getDefaultDecorator(Fragment.PORTLET), Fragment.PORTLET);
page.setTitle(jsPageName);
pageManager.updatePage(page);
List orderList = parent.getDocumentOrder();
if (orderList != null)
{
String name = page.getName();
if (orderList.indexOf(name) < 0)
{
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
}
}
catch (Exception e)
{
throw new PortletException("Unable to access page for editing: "+e.getMessage(), e);
}
}
return;
}
if ( request.getParameter("jsDeletePage" ) != null )
{
try
{
Folder parent = (Folder)requestPage.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
if (orderList != null)
{
String name = requestPage.getName();
if (orderList.indexOf(name) > -1)
{
orderList.remove(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
}
pageManager.removePage(requestPage);
}
catch (Exception e)
{
throw new PortletException("Unable to access page for removing: "+e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMovePageLeft") != null)
{
try
{
Folder parent = (Folder) requestPage.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
String name = requestPage.getName();
if (orderList != null)
{
int index = orderList.indexOf(name);
if (index > -1)
{
String type = requestPage.getType();
int i = index - 1;
while (i >= 0)
{
String value = (String) orderList.get(i);
if (value.endsWith(type))
{
orderList.remove(index);
orderList.add(i, name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
break;
}
i--;
}
}
else
{
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
else
{
orderList = new ArrayList(4);
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
}
catch (Exception e)
{
throw new PortletException(
"Unable to access page for changing the document order: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMovePageRight") != null)
{
try
{
Folder parent = (Folder) requestPage.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
String name = requestPage.getName();
if (orderList != null)
{
int index = orderList.indexOf(name);
if (index > -1)
{
String type = requestPage.getType();
int i = index + 1;
while (i < orderList.size())
{
String value = (String) orderList.get(i);
if (value.endsWith(type))
{
orderList.remove(index);
orderList.add(i, name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
break;
}
i++;
}
}
else
{
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
else
{
orderList = new ArrayList(4);
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
}
catch (Exception e)
{
throw new PortletException(
"Unable to access page for changing the document order: "
+ e.getMessage(), e);
}
return;
}
String theme = request.getParameter("theme");
if ( theme != null && theme.length() > 0 && !theme.equals(requestPage.getDefaultDecorator(Fragment.LAYOUT)) )
{
requestPage.setDefaultDecorator(theme, Fragment.LAYOUT);
try
{
pageManager.updatePage(requestPage);
}
catch (Exception e)
{
throw new PortletException("Unable to update page: "+e.getMessage(), e);
}
return;
}
String fragmentId = request.getParameter("fragment");
if ( fragmentId != null && fragmentId.length() > 0 )
{
String move = request.getParameter("move");
if ( move != null && move.length() > 0 )
{
int moveCode = Integer.parseInt(move);
PortletWindow window = requestContext.getActionWindow();
Fragment currentFragment = requestPage.getFragmentById(window.getId().toString());
Fragment fragmentToMove = requestPage.getFragmentById(fragmentId);
if ( currentFragment == null || fragmentToMove == null )
{
// ignore no longer consistent page definition
return;
}
ColumnLayout columnLayout;
try
{
columnLayout = new ColumnLayout(numColumns, layoutType, currentFragment.getFragments(), null);
columnLayout.addLayoutEventListener(new PageManagerLayoutEventListener(pageManager, requestPage, layoutType));
}
catch (LayoutEventException e1)
{
throw new PortletException("Failed to build ColumnLayout "+e1.getMessage(), e1);
}
try
{
switch (moveCode)
{
case LayoutEvent.MOVED_UP:
columnLayout.moveUp(fragmentToMove);
break;
case LayoutEvent.MOVED_DOWN:
columnLayout.moveDown(fragmentToMove);
break;
case LayoutEvent.MOVED_RIGHT:
columnLayout.moveRight(fragmentToMove);
break;
case LayoutEvent.MOVED_LEFT:
columnLayout.moveLeft(fragmentToMove);
break;
default:
throw new PortletException("Invalid movement code " + moveCode);
}
}
catch (SecurityException se)
{
// ignore page security constraint violations, only
// permitted users can edit managed pages; page
// update will remain transient
log.info("Unable to update page " + requestPage.getId() + " layout due to security permission/constraint.", se);
}
catch (Exception e)
{
if (e instanceof PortletException)
{
throw (PortletException)e;
}
else
{
throw new PortletException("Unable to process layout for page " + requestPage.getId() + " layout: " + e.toString(), e);
}
}
return;
}
String remove = request.getParameter("remove");
if ( remove != null && remove.length() > 0 )
{
Page page = null;
try
{
// TODO: for now retrieve the real Page instead of ContentPage
// because removing fragments isn't working through the ContentFragment wrapping
page = pageManager.getPage(requestPage.getPath());
}
catch (Exception e)
{
throw new PortletException("Unable to retrieve page "+requestPage.getId(),e);
}
PortletWindow window = requestContext.getActionWindow();
Fragment currentFragment = page.getFragmentById(window.getId().toString());
if ( currentFragment == null )
{
// ignore no longer consistent page definition
return;
}
removeFragment(page, currentFragment, fragmentId);
return;
}
String decorator = request.getParameter("decorator");
if ( decorator != null )
{
Fragment fragment = requestPage.getFragmentById(fragmentId);
if ( fragment == null )
{
// ignore no longer consistent page definition
return;
}
if (decorator.trim().length() == 0)
fragment.setDecorator(null);
else
fragment.setDecorator(decorator);
try
{
pageManager.updatePage(requestPage);
}
catch (Exception e)
{
throw new PortletException("Unable to update page for fragment decorator: "+e.getMessage(), e);
}
return;
}
// evlach
String decorators = request.getParameter("decorators");
if ( decorators != null )
{
Iterator fragmentsIter = requestPage.getRootFragment().getFragments().iterator();
while(fragmentsIter.hasNext())
{
Fragment fragment = (Fragment) fragmentsIter.next();
if ( fragment == null )
{
// ignore no longer consistent page definition
return;
}
if (decorators.trim().length() == 0)
fragment.setDecorator(null);
else
fragment.setDecorator(decorators);
}
try
{
pageManager.updatePage(requestPage);
}
catch (Exception e)
{
throw new PortletException("Unable to update page for fragment decorator: "+e.getMessage(), e);
}
return;
}
//end evlach
}
String portlets = request.getParameter("portlets");
if ( portlets != null && portlets.length() > 0 )
{
PortletWindow window = requestContext.getActionWindow();
Fragment targetFragment = requestPage.getFragmentById(window.getId().toString());
if ( targetFragment == null )
{
// ignore no longer consistent page definition
return;