boolean pageExists = (existingHTMLPage != null) && InodeUtils.isSet(existingHTMLPage.getInode());
if (pageExists) {
if ( newHtmlPage.getIdentifier() != null && !newHtmlPage.getIdentifier().equals( existingHTMLPage.getIdentifier() ) ) {
throw new DotDataException( "You are trying to save a page with the same name and location but a different identifier. " +
"If you are trying to push Publish you may have to rename the folder [" + parentFolder.getPath() + "]. " +
"HTMLPage trying to save [" + newHtmlPage.getIdentifier() + "], found HTMLPage [" + existingHTMLPage.getIdentifier() + "]" );
}
if (!permissionAPI.doesUserHavePermission(existingHTMLPage, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
throw new DotSecurityException("You don't have permission to read the HTML page.");
}
}
if (!permissionAPI.doesUserHavePermission(template, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
throw new DotSecurityException("You don't have permission to read the template or the template is not published.");
}
if (!permissionAPI.doesUserHavePermission(parentFolder, PermissionAPI.PERMISSION_WRITE, user, respectFrontendRoles)) {
throw new DotSecurityException("You don't have permission to write in the destination folder.");
}
try {
newHtmlPage.setModUser(user.getUserId());
newHtmlPage.setModDate(new Date());
boolean previousShowMenu = false;
// parent identifier for this file
Identifier identifier = null;
if (pageExists) {
previousShowMenu = existingHTMLPage.isShowOnMenu();
identifier = (Identifier) APILocator.getIdentifierAPI().find(existingHTMLPage);
}
// Some checks
// Get asset host based on the parentFolder of the asset
Host host = hostAPI.findParentHost(parentFolder, user, false);
// get an identifier based on this new uri
Identifier testIdentifier = (Identifier) APILocator.getIdentifierAPI().find(host, newHtmlPage.getURI(parentFolder));
// if this is a new htmlpage and there is already an identifier with
// this uri, return
if ((existingHTMLPage != null) && !InodeUtils.isSet(existingHTMLPage.getInode()) && InodeUtils.isSet(testIdentifier.getInode())) {
existingHTMLPage.setParent(parentFolder.getInode());
throw new DotDataException("Another page with the same page url exists in this folder");
}
// if this is an existing htmlpage and there is already an
// identifier
// with this uri, return
else if (pageExists
&& (!testIdentifier.getInode().equalsIgnoreCase(identifier.getInode()))
&& InodeUtils.isSet(testIdentifier.getInode())) {
// when there is an error saving should unlock working asset
unLockAsset(existingHTMLPage);
throw new DotDataException("Another page with the same page url exists in this folder");
}
if (template != null) {
// Adds template children from selected box
Identifier templateIdentifier = APILocator.getIdentifierAPI().find(template);