// dereference document in case proxy is supplied
pageSecurity = (PageSecurity)ProxyHelper.getRealObject(pageSecurity);
// look up and set parent folder if necessary
boolean newPageSecurity = false;
FolderImpl parent = (FolderImpl)pageSecurity.getParent();
if (parent == null)
{
// access folder by path
String pageSecurityPath = pageSecurity.getPath();
String parentPath = pageSecurityPath.substring(0, pageSecurityPath.lastIndexOf(Folder.PATH_SEPARATOR));
if (parentPath.length() == 0)
{
parentPath = Folder.PATH_SEPARATOR;
}
try
{
parent = (FolderImpl)getFolder(parentPath);
}
catch (FolderNotFoundException fnfe)
{
throw new FailedToUpdateDocumentException("Missing parent folder: " + parentPath);
}
// do not replace existing page security documents
try
{
parent.getPageSecurity();
throw new FailedToUpdateDocumentException("Parent folder page security exists: " + parentPath);
}
catch (DocumentNotFoundException dnfe)
{
// check for edit access on parent folder; document
// access not checked on create
parent.checkAccess(JetspeedActions.EDIT);
// update document and mark cache transaction
pageSecurity.setParent(parent);
storeEntity(pageSecurity, pageSecurityPath, true);
// new page security
newPageSecurity = true;
}
catch (Exception e)
{
throw new FailedToUpdateDocumentException("Parent folder page security exists: " + parentPath);
}
}
else
{
// check for edit access on document and parent folder
pageSecurity.checkAccess(JetspeedActions.EDIT);
// update document and mark cache transaction
storeEntity(pageSecurity, pageSecurity.getPath(), false);
// update page security
newPageSecurity = false;
}
// reset parent folder page security cache if new or
// in case parent is holding an out of date copy of
// this page security that was removed from the cache
// before this one was accessed
parent.resetPageSecurity((PageSecurityImpl)pageSecurity, true);
// reset all cached security constraints
DatabasePageManagerCache.resetCachedSecurityConstraints();
// notify page manager listeners