String newPagePath = folder.getPath()+(folder.getPath().endsWith(Folder.PATH_SEPARATOR) ? "" : Folder.PATH_SEPARATOR)+pageName+Page.DOCUMENT_TYPE;
if (pageManager.pageExists(newPagePath))
{
throw new IllegalArgumentException("Page "+newPagePath+" exists");
}
Page newPage = pageManager.newPage(newPagePath);
if (!Utils.isNull(layoutName) && (newPage.getRootFragment() instanceof Fragment))
{
((Fragment)newPage.getRootFragment()).setName(layoutName);
}
if (!Utils.isNull(pageTitle))
{
newPage.setTitle(pageTitle);
}
if (!Utils.isNull(pageShortTitle))
{
newPage.setShortTitle(pageShortTitle);
}
String defaultLayoutDecorator = null;
String defaultPortletDecorator = null;
if (page != null)
{
defaultLayoutDecorator = page.getDefaultDecorator(Fragment.LAYOUT);
if (defaultLayoutDecorator != null)
{
newPage.setDefaultDecorator(defaultLayoutDecorator, Fragment.LAYOUT);
}
defaultPortletDecorator = page.getDefaultDecorator(Fragment.PORTLET);
if (defaultPortletDecorator != null)
{
newPage.setDefaultDecorator(defaultPortletDecorator, Fragment.PORTLET);
}
}
// update new page in page manager
pageManager.updatePage(newPage);
// add new page to parent document order list
List documentOrder = folder.getDocumentOrder();
if (documentOrder == null)
{
documentOrder = new ArrayList(4);
folder.setDocumentOrder(documentOrder);
}
if (documentOrder.indexOf(newPage.getName()) == -1)
{
documentOrder.add(newPage.getName());
}
// update folder in page manager
pageManager.updateFolder(folder);
}