TemplateEntity template = getDao().getTemplateDao().getByUrl(themeUrl);
Long templateId = null;
if (template != null) {
templateId = template.getId();
}
PageEntity newPage = new PageEntity();
newPage.setTitleValue(title);
newPage.setFriendlyURL(url);
newPage.setTemplate(templateId);
newPage.setPublishDate(publishDate);
newPage.setEndPublishDate(endPublishDate);
if (commentsEnabled != null) {
newPage.setCommentsEnabled(Boolean.valueOf(commentsEnabled));
}
newPage.setState(PageState.APPROVED);
for (Iterator<Element> i = pageElement.elementIterator(); i.hasNext();) {
Element element = i.next();
if (element.getName().equals("version")) {
newPage.setVersion(XmlUtil.readIntegerText(element, 1));
}
if (element.getName().equals("versionTitle")) {
newPage.setVersionTitle(element.getText());
}
if (element.getName().equals("state")) {
newPage.setState(PageState.valueOf(element.getText()));
}
if (element.getName().equals("createUserEmail")) {
newPage.setCreateUserEmail(element.getText());
}
if (element.getName().equals("modUserEmail")) {
newPage.setModUserEmail(element.getText());
}
if (element.getName().equals("pageType")) {
newPage.setPageType(PageType.valueOf(element.getText()));
}
if (element.getName().equals("sortIndex")) {
newPage.setSortIndex(XmlUtil.readIntegerText(element, 0));
}
if (element.getName().equals("structure")) {
StructureEntity structure = getDao().getStructureDao().getByTitle(
element.getText());
newPage.setStructureId(structure == null ? null : structure.getId());
}
if (element.getName().equals("structureTemplate")) {
StructureTemplateEntity structureTemplate = getDao()
.getStructureTemplateDao().getByName(element.getText());
if (structureTemplate == null) {
structureTemplate = getDao()
.getStructureTemplateDao().getByTitle(element.getText());
}
newPage.setStructureTemplateId(structureTemplate == null ? null :
structureTemplate.getId());
}
if (element.getName().equals("createDate")) {
try {
newPage.setCreateDate(DateUtil.dateTimeToDate(
element.getText()));
} catch (ParseException e) {
logger.error("Wrong date format for createDate "
+ element.getText());
}
}
if (element.getName().equals("modDate")) {
try {
newPage.setModDate(DateUtil.dateTimeToDate(
element.getText()));
} catch (ParseException e) {
logger.error("Wrong date format for createDate "
+ element.getText());
}
}
if (element.getName().equals("keywords")) {
newPage.setKeywords(element.getText());
}
if (element.getName().equals("description")) {
newPage.setDescription(element.getText());
}
if (element.getName().equals("searchable")) {
newPage.setSearchable(XmlUtil.readBooleanText(element, true));
}
if (element.getName().equals("velocityProcessing")) {
newPage.setVelocityProcessing(XmlUtil.readBooleanText(element,
false));
}
if (element.getName().equals("headHtml")) {
newPage.setHeadHtml(element.getText());
}
if (element.getName().equals("skipPostProcessing")) {
newPage.setSkipPostProcessing(XmlUtil.readBooleanText(element,
false));
}
if (element.getName().equals("cached")) {
newPage.setCached(XmlUtil.readBooleanText(element, true));
}
if (element.getName().equals("contentType")) {
newPage.setContentType(element.getText());
}
if (element.getName().equals("wikiProcessing")) {
newPage.setWikiProcessing(XmlUtil.readBooleanText(element,
false));
}
if (element.getName().equals("enableCkeditor")) {
newPage.setEnableCkeditor(XmlUtil.readBooleanText(element,
true));
}
if (element.getName().equals("attributes")) {
newPage.setAttributes(element.getText());
}
if (element.getName().equals("restful")) {
newPage.setRestful(XmlUtil.readBooleanText(element,
true));
}
}
PageEntity page = getDao().getPageDao().getByUrlVersion(url,
newPage.getVersion());
if (page != null) {
page.copy(newPage);
} else {
page = newPage;
}
getDaoTaskAdapter().pageSave(page);
readContents(pageElement, page);