if ( addLayout || request.getParameter("jsChangeLayout") != null )
{
layout = request.getParameter("layout");
if ( layout != null && layout.length() > 0 )
{
PortletWindow window = requestContext.getActionWindow();
ContentFragment targetFragment = requestPage.getFragmentById(window.getId().toString());
if ( targetFragment != null )
{
if ( addLayout )
{
try
{
targetFragment.addPortlet(Fragment.LAYOUT, layout);
clearLayoutAttributes(request);
}
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.updateName(layout);
clearLayoutAttributes(request);
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");
String jsPageTitle = request.getParameter("jsPageTitle");
String jsPageShortTitle = request.getParameter("jsPageShortTitle");
layout = request.getParameter("layout");
if ( ( layout == null ) || ( layout.length() == 0 ) )
{
layout = requestPage.getRootFragment().getName();
}
if ( jsPageName != null && jsPageName.length() > 0 && jsPageName.indexOf(Folder.PATH_SEPARATOR) == -1 )
{
try
{
requestPage.newSiblingPage(getEscapedName(jsPageName), layout, jsPageTitle, jsPageShortTitle);
}
catch (Exception e)
{
throw new PortletException("Unable to access page for editing: "+e.getMessage(), e);
}
}
return;
}
if (request.getParameter("jsChangePageName") != null)
{
String jsPageTitle = request.getParameter("jsPageTitle");
String jsPageShortTitle = request
.getParameter("jsPageShortTitle");
try
{
requestPage.updateTitles(jsPageTitle, jsPageShortTitle);
}
catch (Exception e)
{
throw new PortletException(
"Unable to access page for editing: "
+ e.getMessage(), e);
}
return;
}
if ( request.getParameter("jsDeletePage" ) != null )
{
try
{
requestPage.remove();
}
catch (Exception e)
{
throw new PortletException("Unable to access page for removing: "+e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMovePageLeft") != null)
{
try
{
requestPage.decrementInDocumentOrder();
}
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
{
requestPage.incrementInDocumentOrder();
}
catch (Exception e)
{
throw new PortletException(
"Unable to access page for changing the document order: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsSubmitFolder") != null)
{
String jsFolderName = request.getParameter("jsFolderName");
String jsFolderTitle = request.getParameter("jsFolderTitle");
String jsFolderShortTitle = request.getParameter("jsFolderShortTitle");
layout = request.getParameter("layout");
if ( ( layout == null ) || ( layout.length() == 0 ) )
{
layout = requestPage.getRootFragment().getName();
}
if (jsFolderName != null && jsFolderName.length() > 0
&& jsFolderName.indexOf(Folder.PATH_SEPARATOR) == -1)
{
try
{
requestPage.newSiblingFolder(getEscapedName(jsFolderName), jsFolderTitle, jsFolderShortTitle, layout);
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for editing: "
+ e.getMessage(), e);
}
}
return;
}
if (request.getParameter("jsChangeFolderName") != null)
{
String jsFolderTitle = request.getParameter("jsFolderTitle");
String jsFolderShortTitle = request
.getParameter("jsFolderShortTitle");
try
{
requestPage.updateFolderTitles(jsFolderTitle, jsFolderShortTitle);
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for editing: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsDeleteFolder") != null)
{
try
{
requestPage.removeFolder();
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for removing: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMoveFolderLeft") != null)
{
try
{
requestPage.decrementFolderInDocumentOrder();
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for changing the document order: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMoveFolderRight") != null)
{
try
{
requestPage.incrementFolderInDocumentOrder();
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for changing the document order: "
+ e.getMessage(), e);
}
return;
}
String theme = request.getParameter("theme");
if ( theme != null && theme.length() > 0 )
{
try
{
requestPage.updateDefaultDecorator(theme, Fragment.LAYOUT);
}
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();
ContentFragment currentFragment = requestPage.getFragmentById(window.getId().toString());
ContentFragment fragmentToMove = requestPage.getFragmentById(fragmentId);
if ( currentFragment != null && fragmentToMove != null )
{
ColumnLayout columnLayout;
try
{
columnLayout = new ColumnLayout(numColumns, layoutType, currentFragment.getFragments(), null);
columnLayout.addLayoutEventListener(new PageLayoutEventListener(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 )
{
try
{
requestPage.removeFragment(fragmentId);
}
catch (Exception e)
{
throw new PortletException("Unable to update page to remove fragment: "+e.getMessage(), e);
}
return;
}
String decorator = request.getParameter("decorator");
if ( decorator != null )
{
try
{
ContentFragment fragment = requestPage.getFragmentById(fragmentId);
if ( fragment != null )
{
fragment.updateDecorator(decorator);
}
}
catch (Exception e)
{
throw new PortletException("Unable to update page for fragment decorator: "+e.getMessage(), e);
}
return;
}
}
// change style for all pages in user folder
String jsChangeUserPagesTheme = request.getParameter("jsChangeUserPagesTheme");
if ( jsChangeUserPagesTheme != null )
{
String user_pages_theme = request.getParameter("user_pages_theme");
try
{
Folder f = pageManager.getUserFolder(request.getRemoteUser());
applyStyle(f,user_pages_theme,Fragment.LAYOUT);
}
catch (Exception e)
{
throw new PortletException("Unable to update folder for defUserLayoutDeco decorator: "+e.getMessage(), e);
}
return;
}
String jsChangeUserPortletsDeco = request.getParameter("jsChangeUserPortletsDeco");
if ( jsChangeUserPortletsDeco != null )
{
String user_portlets_deco = request.getParameter("user_portlets_deco");
try
{
Folder f = pageManager.getUserFolder(request.getRemoteUser());
applyStyle(f,user_portlets_deco,Fragment.PORTLET);
}
catch (Exception e)
{
throw new PortletException("Unable to update folder for defUserPortletDeco decorator: "+e.getMessage(), e);
}
return;
}
String jsChangeThemeAll = request.getParameter("jsChangeThemeAll");
if (jsChangeThemeAll != null)
{
String decorators = request.getParameter("decorators");
String targetFragmentId = request.getParameter("fragment");
ContentFragment targetFragment = requestPage.getFragmentById(targetFragmentId);
if (targetFragment != null)
{
Iterator fragmentsIter = targetFragment.getFragments().iterator();
while (fragmentsIter.hasNext())
{
ContentFragment fragment = (ContentFragment) fragmentsIter.next();
if (fragment != null )
{
try
{
fragment.updateDecorator(decorators);
}
catch (Exception e)
{
throw new PortletException("Unable to update page for fragment decorator: "+e.getMessage(), e);
}
}
}
}
return;
}
String portlets = request.getParameter("portlets");
if ( portlets != null && portlets.length() > 0 )
{
PortletWindow window = requestContext.getActionWindow();
ContentFragment targetFragment = requestPage.getFragmentById(window.getId().toString());
if ( targetFragment != null )
{
StringTokenizer tokenizer = new StringTokenizer(portlets, ",");
while (tokenizer.hasMoreTokens())
{