public void move(DavResource davResource) throws DavException {
Page thisPage = getPage();
String[] destinationResourcePathComponents = StringUtils.split(davResource.getResourcePath(), '/');
User user = AuthenticatedUserThreadLocal.getUser();
if (!isDestinationPathValid(destinationResourcePathComponents))
throw new DavException(
HttpServletResponse.SC_FORBIDDEN,
"Cannot move " + getResourcePath() + " to " + StringUtils.join(destinationResourcePathComponents, '/'));
String destinationSpaceKey = destinationResourcePathComponents[2];
String destinationPageTitle = destinationResourcePathComponents[destinationResourcePathComponents.length - 1];
if (!permissionManager.hasPermission(user, Permission.EDIT, thisPage))
throw new DavException(HttpServletResponse.SC_FORBIDDEN, "Permission denied to move " + thisPage);
if (!StringUtils.equals(thisPage.getTitle(), destinationPageTitle)) {
if (null != pageManager.getPage(destinationSpaceKey, destinationPageTitle))
throw new DavException(HttpServletResponse.SC_FORBIDDEN, StringUtils.join(destinationResourcePathComponents, '/') + " points to an existing page.");
pageManager.renamePage(thisPage, destinationPageTitle);
} else {
String destinationPageParentTitle = destinationResourcePathComponents.length > 4
? destinationResourcePathComponents[destinationResourcePathComponents.length - 2]
: null;
Page destinationPageParent = null == destinationPageParentTitle
? null
: pageManager.getPage(destinationSpaceKey, destinationPageParentTitle);
Space destinationSpace = spaceManager.getSpace(destinationSpaceKey);
pageManager.movePageAsChild(thisPage, destinationPageParent);
}
}