{
// dereference document in case proxy is supplied
pageSecurity = (PageSecurity)ProxyHelper.getRealObject(pageSecurity);
// look up and set parent folder if necessary
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);
getPersistenceBrokerTemplate().store(pageSecurity);
DatabasePageManagerCache.addTransaction(new TransactionedOperation(pageSecurity.getPath(), TransactionedOperation.ADD_OPERATION));
// reset parent folder page security cache
if (parent != null)
{
parent.resetPageSecurity((PageSecurityImpl)pageSecurity, true);
}
}
catch (Exception e)
{
throw new FailedToUpdateDocumentException("Parent folder page security exists: " + parentPath);
}
// notify page manager listeners
delegator.notifyNewNode(pageSecurity);
}
else
{
// check for edit access on document and parent folder
pageSecurity.checkAccess(JetspeedActions.EDIT);
// update document and mark cache transaction
getPersistenceBrokerTemplate().store(pageSecurity);
DatabasePageManagerCache.addTransaction(new TransactionedOperation(pageSecurity.getPath(), TransactionedOperation.UPDATE_OPERATION));
// reset parent folder page security cache 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
if (parent != null)
{
parent.resetPageSecurity((PageSecurityImpl)pageSecurity, true);
}
// notify page manager listeners
delegator.notifyUpdatedNode(pageSecurity);
}