// Make sure the user has editing rights
if (!SecurityUtils.userHasRole(user, SystemRole.EDITOR))
throw new WebApplicationException(Status.UNAUTHORIZED);
// Parse the page and store it
PageImpl page = null;
URI uri = null;
if (!StringUtils.isBlank(pageXml)) {
logger.debug("Adding page to {}", pageURI);
try {
PageReader pageReader = new PageReader();
page = pageReader.read(IOUtils.toInputStream(pageXml, "utf-8"), site);
page.setIdentifier(pageURI.getIdentifier());
page.setPath(pageURI.getPath());
page.setVersion(pageURI.getVersion());
} catch (IOException e) {
logger.warn("Error reading page {} from request", pageURI);
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (ParserConfigurationException e) {
logger.warn("Error configuring parser to read updated page {}: {}", pageURI, e.getMessage());
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (SAXException e) {
logger.warn("Error parsing updated page {}: {}", pageURI, e.getMessage());
throw new WebApplicationException(Status.BAD_REQUEST);
}
} else {
logger.debug("Creating new page at {}", pageURI);
page = new PageImpl(pageURI);
page.setTemplate(site.getDefaultTemplate().getIdentifier());
page.setCreated(user, new Date());
}
// Store the new page
try {
contentRepository.put(page, true);