return null;
}
@Override
public ServiceResponse savePage(Map<String, String> vo) {
PageEntity page = null;
if (!StringUtils.isEmpty(vo.get("id"))) {
page = getPage(Long.valueOf(vo.get("id")));
}
if (page == null) {
page = new PageEntity();
page.setFriendlyURL(vo.get("friendlyUrl"));
page.setSortIndex(getPageBusiness().getNextSortIndex(
vo.get("friendlyUrl")));
getPageBusiness().setDefaultValues(page);
}
if (vo.get("friendlyUrl") != null) {
page.setFriendlyURL(vo.get("friendlyUrl"));
}
if (vo.get("commentsEnabled") != null) {
page.setCommentsEnabled(Boolean.valueOf(vo.get("commentsEnabled")));
}
if (vo.get("searchable") != null) {
page.setSearchable(Boolean.valueOf(vo.get("searchable")));
}
if (vo.get("velocityProcessing") != null) {
page.setVelocityProcessing(Boolean.valueOf(vo
.get("velocityProcessing")));
}
if (vo.get("skipPostProcessing") != null) {
page.setSkipPostProcessing(Boolean.valueOf(vo
.get("skipPostProcessing")));
}
if (vo.get("cached") != null) {
page.setCached(Boolean.valueOf(vo.get("cached")));
}
String languageCode = vo.get("languageCode");
ContentPermissionEntity perm = getBusiness()
.getContentPermissionBusiness().getPermission(
page.getFriendlyURL(),
VosaoContext.getInstance().getUser());
boolean approve = Boolean.valueOf(vo.get("approve"));
if (approve && perm.isPublishGranted()) {
page.setState(PageState.APPROVED);
} else {
page.setState(PageState.EDIT);
}
if (!perm.isChangeGranted(languageCode)) {
return ServiceResponse.createErrorResponse(Messages.get(
"access_denied"));
}
if (vo.get("publishDate") != null) {
try {
page.setPublishDate(DateUtil.dateTimeToDate(
vo.get("publishDate")));
} catch (ParseException e) {
return ServiceResponse
.createErrorResponse(Messages.get(
"date_wrong_format"));
}
}
if (vo.get("endPublishDate") != null) {
try {
if (!StringUtils.isEmpty(vo.get("endPublishDate"))) {
page.setEndPublishDate(DateUtil.dateTimeToDate(
vo.get("endPublishDate")));
}
else if (page.getEndPublishDate() != null) {
page.setEndPublishDate(null);
}
} catch (ParseException e) {
return ServiceResponse
.createErrorResponse(Messages.get(
"date_wrong_format"));
}
}
if (vo.get("template") != null) {
page.setTemplate(Long.valueOf(vo.get("template")));
}
if (vo.get("titles") != null) {
page.setTitleValue(vo.get("titles"));
}
if (vo.get("title") != null) {
page.setTitle(vo.get("title"));
}
if (vo.get("pageType") != null) {
page.setPageType(PageType.valueOf(vo.get("pageType")));
}
if (vo.get("structureId") != null) {
page.setStructureId(Long.valueOf(vo.get("structureId")));
}
if (vo.get("structureTemplateId") != null) {
page.setStructureTemplateId(Long.valueOf(vo
.get("structureTemplateId")));
}
if (vo.get("keywords") != null) {
page.setKeywords(vo.get("keywords"));
}
if (vo.get("description") != null) {
page.setDescription(vo.get("description"));
}
if (vo.get("headHtml") != null) {
page.setHeadHtml(vo.get("headHtml"));
}
if (vo.get("dependencies") != null) {
savePageDependencies(page.getFriendlyURL(), vo.get("dependencies"));
}
if (vo.get("contentType") != null) {
page.setContentType(vo.get("contentType"));
}
if (vo.get("wikiProcessing") != null) {
page.setWikiProcessing(Boolean.valueOf(vo.get("wikiProcessing")));
}
if (vo.get("enableCkeditor") != null) {
page.setEnableCkeditor(Boolean.valueOf(vo.get("enableCkeditor")));
}
if (vo.get("restful") != null) {
page.setRestful(Boolean.valueOf(vo.get("restful")));
}
if (vo.get("attributes") != null) {
page.setAttributes(vo.get("attributes"));
}
List<String> errors = getPageBusiness().validateBeforeUpdate(page);
if (errors.isEmpty()) {
boolean isNew = page.isNew();
getPageBusiness().save(page);
if (isNew && !vo.containsKey("content")
&& !page.isForInternalUse()) {
getPageBusiness().updateDefaultContent(page);
}
if (vo.containsKey("content")) {
getPageBusiness().saveContent(page, languageCode,
vo.get("content"));
}
return ServiceResponse.createSuccessResponse(page.getId()
.toString());
} else {
return ServiceResponse.createErrorResponse(
Messages.get("errors_occured"), errors);
}