*/
private void save(HttpServletRequest request, ModelAndView next,
WikiPageInfo pageInfo) throws Exception {
String topicName = WikiUtil.getTopicFromRequest(request);
String virtualWiki = pageInfo.getVirtualWikiName();
Topic topic = loadTopic(virtualWiki, topicName);
Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki,
topicName, false, null);
if (lastTopic != null
&& !lastTopic.getCurrentVersionId().equals(
retrieveLastTopicVersionId(request, topic))) {
// someone else has edited the topic more recently
resolve(request, next, pageInfo);
return;
}
String contents = request.getParameter("contents");
String sectionName = "";
if (!StringUtils.isBlank(request.getParameter("section"))) {
// load section of topic
int section = Integer.valueOf(request.getParameter("section"));
ParserOutput parserOutput = new ParserOutput();
String[] spliceResult = ParserUtil.parseSplice(parserOutput, request
.getContextPath(), request.getLocale(), virtualWiki, topicName,
section, contents);
contents = spliceResult[1];
sectionName = parserOutput.getSectionName();
}
if (contents == null) {
logger.warning("The topic " + topicName + " has no content");
throw new WikiException(new WikiMessage("edit.exception.nocontent",
topicName));
}
// strip line feeds
contents = StringUtils.remove(contents, '\r');
String lastTopicContent = (lastTopic != null) ? StringUtils.remove(
lastTopic.getTopicContent(), '\r') : "";
if (lastTopic != null && StringUtils.equals(lastTopicContent, contents)) {
// topic hasn't changed. redirect to prevent user from refreshing and
// re-submitting
ServletUtil.redirect(next, virtualWiki, topic.getName());
return;