{
// validate fragments element
BaseFragmentsElementImpl fragmentsElementImpl = (BaseFragmentsElementImpl)fragmentsElement;
if (!fragmentsElementImpl.validateFragments())
{
throw new PageNotUpdatedException("Fragments hierarchy invalid for fragments/page: " + fragmentsElement.getPath() + ", not updated.");
}
// look up and set parent folder if necessary
FolderImpl parent = (FolderImpl)fragmentsElement.getParent();
if (parent == null)
{
// access folder by path
String pageElementPath = fragmentsElement.getPath();
String parentPath = pageElementPath.substring(0, pageElementPath.lastIndexOf(Folder.PATH_SEPARATOR));
if (parentPath.length() == 0)
{
parentPath = Folder.PATH_SEPARATOR;
}
try
{
parent = (FolderImpl)getFolder(parentPath);
}
catch (FolderNotFoundException fnfe)
{
throw new PageNotUpdatedException("Missing parent folder: " + parentPath);
}
// check for edit access on parent folder; fragments/page
// access not checked on create
parent.checkAccess(JetspeedActions.EDIT);
// update fragments/page and mark cache transaction
fragmentsElement.setParent(parent);
storeEntity(fragmentsElement, pageElementPath, true);
// new fragments/page
newFragmentsElement[0] = true;
}
else
{
// check for edit access on fragments/page and parent folder
fragmentsElement.checkAccess(JetspeedActions.EDIT);
// update fragments/page and mark cache transaction
storeEntity(fragmentsElement, fragmentsElement.getPath(), false);
// updated fragments/page
newFragmentsElement[0] = false;
}
// return parent folder to update its caches after update
return parent;
}
catch (PageNotUpdatedException pnue)
{
throw pnue;
}
catch (SecurityException se)
{
throw se;
}
catch (Exception e)
{
throw new PageNotUpdatedException("Fragments/page element " + fragmentsElement.getPath() + " not updated.", e);
}
}