Example #1
0
 private void view(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromURI(request);
   if (StringUtils.isBlank(topicName)) {
     String virtualWikiName = pageInfo.getVirtualWikiName();
     VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName);
     topicName = virtualWiki.getRootTopicName();
   }
   String virtualWiki = pageInfo.getVirtualWikiName();
   if (StringUtils.isBlank(virtualWiki)) {
     virtualWiki = VirtualWiki.defaultVirtualWiki().getName();
   }
   Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
   if (topic.getTopicId() <= 0) {
     // topic does not exist, return 404 and display empty page
     response.setStatus(HttpServletResponse.SC_NOT_FOUND);
     WikiMessage wikiMessage = new WikiMessage("topic.notcreated");
     // topic name is escaped from WikiUtil.getTopicFromURI, so do not double-escape
     wikiMessage.setParamsWithoutEscaping(new String[] {topicName});
     next.addObject("notopic", wikiMessage);
   }
   WikiMessage pageTitle = new WikiMessage("topic.title", topicName);
   ServletUtil.viewTopic(request, next, pageInfo, pageTitle, topic, true, true);
 }
Example #2
0
 /** Functionality to handle the "Preview" button being clicked. */
 private void preview(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   String contents = (String) request.getParameter("contents");
   Topic previewTopic = new Topic(virtualWiki, topicName);
   previewTopic.setTopicContent(contents);
   next.addObject("editPreview", "true");
   ServletUtil.viewTopic(request, next, pageInfo, null, previewTopic, false, false);
 }
Example #3
0
 /**
  * Utility method used when viewing a topic.
  *
  * @param request The current servlet request object.
  * @param next The current Spring ModelAndView object.
  * @param pageInfo The current WikiPageInfo object, which contains information needed for
  *     rendering the final JSP page.
  * @param topicName The topic being viewed. This value must be a valid topic that can be loaded as
  *     a org.jamwiki.model.Topic object.
  * @throws Exception Thrown if any error occurs during processing.
  */
 protected static void viewTopic(
     HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName)
     throws Exception {
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   if (!StringUtils.hasText(virtualWiki)) {
     virtualWiki = WikiBase.DEFAULT_VWIKI;
   }
   Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
   if (topic.getTopicId() <= 0) {
     // topic does not exist, display empty page
     next.addObject("notopic", new WikiMessage("topic.notcreated", topicName));
   }
   WikiMessage pageTitle = new WikiMessage("topic.title", topicName);
   viewTopic(request, next, pageInfo, pageTitle, topic, true);
 }