示例#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);
 }
示例#2
0
 @Test
 public void testImportFromFileWithUnsortedHistory() throws Throwable {
   String virtualWiki = VIRTUAL_WIKI_EN;
   List<String> results = this.importTestFile(FILE_ONE_TOPIC_WITH_UNSORTED_HISTORY);
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, TOPIC_NAME3, false, null);
   // validate that the current topic content is correct
   assertEquals(
       "Incorrect topic ordering: " + topic.getTopicId() + " / " + topic.getCurrentVersionId(),
       "Newest Revision",
       topic.getTopicContent());
 }
示例#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);
 }
示例#4
0
 private void writePages(
     Writer writer, String virtualWiki, List<String> topicNames, boolean excludeHistory)
     throws DataAccessException, IOException, MigrationException {
   // note that effort is being made to re-use temporary objects as this
   // code can generate an OOM "GC overhead limit exceeded" with HUGE (500MB) topics
   // since the garbage collector ends up being invoked excessively.
   TopicVersion topicVersion;
   Topic topic;
   WikiUser user;
   // choose 100,000 as an arbitrary max
   Pagination pagination = new Pagination(100000, 0);
   List<Integer> topicVersionIds;
   Map<String, String> textAttributes = new HashMap<String, String>();
   textAttributes.put("xml:space", "preserve");
   for (String topicName : topicNames) {
     topicVersionIds = new ArrayList<Integer>();
     topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false);
     if (topic == null) {
       throw new MigrationException(
           "Failure while exporting: topic " + topicName + " does not exist");
     }
     writer.append("\n<page>");
     writer.append('\n');
     XMLUtil.buildTag(writer, "title", topic.getName(), true);
     writer.append('\n');
     XMLUtil.buildTag(writer, "id", topic.getTopicId());
     if (excludeHistory) {
       // only include the most recent version
       topicVersionIds.add(topic.getCurrentVersionId());
     } else {
       // FIXME - changes sorted newest-to-oldest, should be reverse
       List<RecentChange> changes =
           WikiBase.getDataHandler().getTopicHistory(topic, pagination, true);
       for (int i = (changes.size() - 1); i >= 0; i--) {
         topicVersionIds.add(changes.get(i).getTopicVersionId());
       }
     }
     for (int topicVersionId : topicVersionIds) {
       topicVersion = WikiBase.getDataHandler().lookupTopicVersion(topicVersionId);
       writer.append("\n<revision>");
       writer.append('\n');
       XMLUtil.buildTag(writer, "id", topicVersion.getTopicVersionId());
       writer.append('\n');
       XMLUtil.buildTag(
           writer, "timestamp", this.parseJAMWikiTimestamp(topicVersion.getEditDate()), true);
       writer.append("\n<contributor>");
       user =
           (topicVersion.getAuthorId() != null)
               ? WikiBase.getDataHandler().lookupWikiUser(topicVersion.getAuthorId())
               : null;
       if (user != null) {
         writer.append('\n');
         XMLUtil.buildTag(writer, "username", user.getUsername(), true);
         writer.append('\n');
         XMLUtil.buildTag(writer, "id", user.getUserId());
       } else if (Utilities.isIpAddress(topicVersion.getAuthorDisplay())) {
         writer.append('\n');
         XMLUtil.buildTag(writer, "ip", topicVersion.getAuthorDisplay(), true);
       } else {
         writer.append('\n');
         XMLUtil.buildTag(writer, "username", topicVersion.getAuthorDisplay(), true);
       }
       writer.append("\n</contributor>");
       writer.append('\n');
       XMLUtil.buildTag(writer, "comment", topicVersion.getEditComment(), true);
       writer.append('\n');
       XMLUtil.buildTag(writer, "text", topicVersion.getVersionContent(), textAttributes, true);
       writer.append("\n</revision>");
       // explicitly null out temp variables to improve garbage collection and
       // avoid OOM "GC overhead limit exceeded" errors on HUGE (500MB) topics
       topicVersion = null;
       user = null;
     }
     writer.append("\n</page>");
   }
 }