String jsPageShortTitle = request.getParameter("jsPageShortTitle");
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 + getEscapedName(jsPageName);
}
else
{
path = path + Folder.PATH_SEPARATOR
+ getEscapedName(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(jsPageTitle != null && !jsPageTitle.equals("") ? jsPageTitle : jsPageName);
page.setShortTitle(jsPageShortTitle != null
&& !jsPageShortTitle.equals("") ? jsPageShortTitle
: jsPageName);
pageManager.updatePage(page);
clearLayoutAttributes(request);
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("jsChangePageName") != null)
{
String jsPageTitle = request.getParameter("jsPageTitle");
String jsPageShortTitle = request
.getParameter("jsPageShortTitle");
try
{
if (jsPageTitle != null && !jsPageTitle.equals(""))
{
requestPage.setTitle(jsPageTitle);
}
if (jsPageShortTitle != null
&& !jsPageShortTitle.equals(""))
{
requestPage.setShortTitle(jsPageShortTitle);
}
pageManager.updatePage(requestPage);
}
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;
}
if (request.getParameter("jsSubmitFolder") != null)
{
String jsFolderName = request.getParameter("jsFolderName");
String jsFolderTitle = request.getParameter("jsFolderTitle");
String jsFolderShortTitle = request.getParameter("jsFolderShortTitle");
if (jsFolderName != null && jsFolderName.length() > 0
&& jsFolderName.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 + getEscapedName(jsFolderName);
}
else
{
path = path + Folder.PATH_SEPARATOR
+ getEscapedName(jsFolderName);
}
Folder folder = pageManager.newFolder(path);
if (layout == null || layout.length() == 0)
{
layout = requestPage.getRootFragment()
.getName();
}
folder.setDefaultDecorator(requestPage
.getDefaultDecorator(Fragment.LAYOUT),
Fragment.LAYOUT);
folder.setDefaultDecorator(requestPage
.getDefaultDecorator(Fragment.PORTLET),
Fragment.PORTLET);
folder
.setTitle(jsFolderTitle != null
&& !jsFolderTitle.equals("") ? jsFolderTitle
: jsFolderName);
folder
.setShortTitle(jsFolderShortTitle != null
&& !jsFolderShortTitle.equals("") ? jsFolderShortTitle
: jsFolderName);
pageManager.updateFolder(folder);
List orderList = parent.getDocumentOrder();
if (orderList != null)
{
String name = folder.getName();
if (orderList.indexOf(name) < 0)
{
orderList.add(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
// add default page
path = folder.getPath();
if (path.endsWith(Folder.PATH_SEPARATOR))
{
path = path + getEscapedName("default-page");
}
else
{
path = path + Folder.PATH_SEPARATOR
+ getEscapedName("default-page");
}
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(jsFolderName);
pageManager.updatePage(page);
orderList = folder.getDocumentOrder();
if (orderList != null)
{
String name = page.getName();
if (orderList.indexOf(name) < 0)
{
orderList.add(name);
folder.setDocumentOrder(orderList);
pageManager.updateFolder(folder);
}
}
}
}
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
{
Folder parent = (Folder) requestPage.getParent();
if (parent != null)
{
if (jsFolderTitle != null && !jsFolderTitle.equals(""))
{
parent.setTitle(jsFolderTitle);
}
if (jsFolderShortTitle != null
&& !jsFolderShortTitle.equals(""))
{
parent.setShortTitle(jsFolderShortTitle);
}
pageManager.updateFolder(parent);
}
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for editing: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsDeleteFolder") != null)
{
try
{
Folder targetFolder = (Folder) requestPage.getParent();
Folder parent = (Folder) targetFolder.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
if (orderList != null)
{
String name = targetFolder.getName();
if (orderList.indexOf(name) > -1)
{
orderList.remove(name);
parent.setDocumentOrder(orderList);
pageManager.updateFolder(parent);
}
}
// do not remove if the folder is root.
pageManager.removeFolder(targetFolder);
}
}
catch (Exception e)
{
throw new PortletException(
"Unable to access folder for removing: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMoveFolderLeft") != null)
{
try
{
Folder targetFolder = (Folder) requestPage.getParent();
Folder parent = (Folder) targetFolder.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
String name = targetFolder.getName();
if (orderList != null)
{
int index = orderList.indexOf(name);
if (index > -1)
{
int i = index - 1;
while (i >= 0)
{
String value = (String) orderList.get(i);
if (!value.endsWith(".psml")
&& !value.endsWith(".link"))
{
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 folder for changing the document order: "
+ e.getMessage(), e);
}
return;
}
if (request.getParameter("jsMoveFolderRight") != null)
{
try
{
Folder targetFolder = (Folder) requestPage.getParent();
Folder parent = (Folder) targetFolder.getParent();
if (parent != null)
{
List orderList = parent.getDocumentOrder();
String name = targetFolder.getName();
if (orderList != null)
{
int index = orderList.indexOf(name);
if (index > -1)
{
int i = index + 1;
while (i < orderList.size())
{
String value = (String) orderList.get(i);
if (!value.endsWith(".psml")
&& !value.endsWith(".link"))
{
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 folder 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;
}
}
// 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);