Package org.jamwiki.model

Examples of org.jamwiki.model.Topic


    String virtualWiki = pageInfo.getVirtualWikiName();
    Pagination pagination = ServletUtil.loadPagination(request, next);
    Set<String> allItems = new TreeSet<String>();
    List<String> unlinkedTopics = WikiBase.getDataHandler().getAllTopicNames(
        virtualWiki);
    Topic topic;
    List<SearchResultEntry> topicLinks = null;
    ParserInput parserInput;
    ParserOutput parserOutput;
    for (String topicName : unlinkedTopics) {
      topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName,
          true, null);
      if (topic == null) {
        logger.warning("No topic found: " + virtualWiki + " / " + topicName);
        continue;
      }
      if (topic.getTopicType() != Topic.TYPE_ARTICLE) {
        continue;
      }
      // only mark them orphaned if there is neither category defined in it, nor
      // a link to it!
      // topicLinks = WikiBase.getSearchEngine().findLinkedTo(virtualWiki,
      // topicName);
      if (topicLinks == null || !topicLinks.isEmpty()) {
        continue;
      }
      parserInput = new ParserInput();
      parserInput.setContext(request.getContextPath());
      parserInput.setLocale(request.getLocale());
      parserInput.setWikiUser(ServletUtil.currentWikiUser());
      parserInput.setTopicName(topicName);
      parserInput.setUserDisplay(ServletUtil.getIpAddress(request));
      parserInput.setVirtualWiki(virtualWiki);
      parserInput.setAllowSectionEdit(false);
      parserOutput = new ParserOutput();
      ParserUtil.parse(parserInput, parserOutput, topic.getTopicContent());
      if (parserOutput.getCategories().size() == 0) {
        allItems.add(topic.getName());
      }
    }
    // FIXME - this is a nasty hack until data can be retrieved properly for
    // pagination
    Set<String> items = new TreeSet<String>();
View Full Code Here


  private void writeTopic(HttpServletRequest request, WikiPageInfo pageInfo) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    String language = request.getParameter("language");
    String topicName = NamespaceHandler.NAMESPACE_JAMWIKI + NamespaceHandler.NAMESPACE_SEPARATOR + Utilities.decodeTopicName(filename(language), true);
    String contents = "<pre><nowiki>\n" + Utilities.readFile(filename(language)) + "\n</nowiki></pre>";
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    if (topic == null) {
      topic = new Topic();
      topic.setVirtualWiki(virtualWiki);
      topic.setName(topicName);
    }
    int charactersChanged = StringUtils.length(contents) - StringUtils.length(topic.getTopicContent());
    topic.setTopicContent(contents);
    topic.setReadOnly(true);
    topic.setTopicType(Topic.TYPE_SYSTEM_FILE);
    WikiUser user = ServletUtil.currentWikiUser();
    TopicVersion topicVersion = new TopicVersion(user, ServletUtil.getIpAddress(request), null, contents, charactersChanged);
    WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, null);
  }
View Full Code Here

  /**
   *
   */
  private void deletePage(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, true, null);
    if (topic.getDeleted()) {
      logger.warning("Attempt to delete a topic that is already deleted: " + virtualWiki + " / " + topicName);
      return;
    }
    int charactersChanged = 0 - StringUtils.length(topic.getTopicContent());
    String contents = "";
    topic.setTopicContent(contents);
    WikiUser user = ServletUtil.currentWikiUser();
    TopicVersion topicVersion = new TopicVersion(user, ServletUtil.getIpAddress(request), request.getParameter("deleteComment"), contents, charactersChanged);
    topicVersion.setEditType(TopicVersion.EDIT_DELETE);
    WikiBase.getDataHandler().deleteTopic(topic, topicVersion);
  }
View Full Code Here

    String topicName = WikiUtil.getTopicFromRequest(request);
    String virtualWiki = pageInfo.getVirtualWikiName();
    if (topicName == null) {
      throw new WikiException(new WikiMessage("common.exception.notopic"));
    }
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    if (topic == null) {
      throw new WikiException(new WikiMessage("common.exception.notopic"));
    }
    topic.setReadOnly(request.getParameter("readOnly") != null);
    topic.setAdminOnly(request.getParameter("adminOnly") != null);
    WikiUser user = ServletUtil.currentWikiUser();
    TopicVersion topicVersion = new TopicVersion(user, ServletUtil.getIpAddress(request), null, topic.getTopicContent(), 0);
    topicVersion.setEditType(TopicVersion.EDIT_PERMISSION);
    WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, null);
    next.addObject("message", new WikiMessage("manage.message.updated", topicName));
    view(request, next, pageInfo);
  }
View Full Code Here

  /**
   *
   */
  private void undeletePage(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, true, null);
    if (!topic.getDeleted()) {
      logger.warning("Attempt to undelete a topic that is not deleted: " + virtualWiki + " / " + topicName);
      return;
    }
    TopicVersion previousVersion = WikiBase.getDataHandler().lookupTopicVersion(topic.getCurrentVersionId());
    while (previousVersion != null && previousVersion.getPreviousTopicVersionId() != null && previousVersion.getEditType() == TopicVersion.EDIT_DELETE) {
      // loop back to find the last non-delete edit
      previousVersion = WikiBase.getDataHandler().lookupTopicVersion(previousVersion.getPreviousTopicVersionId());
    }
    String contents = previousVersion.getVersionContent();
    topic.setTopicContent(contents);
    WikiUser user = ServletUtil.currentWikiUser();
    int charactersChanged = StringUtils.length(contents);
    TopicVersion topicVersion = new TopicVersion(user, ServletUtil.getIpAddress(request), request.getParameter("undeleteComment"), contents, charactersChanged);
    topicVersion.setEditType(TopicVersion.EDIT_UNDELETE);
    WikiBase.getDataHandler().undeleteTopic(topic, topicVersion);
View Full Code Here

   *
   */
  private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String topicName = WikiUtil.getTopicFromRequest(request);
    String virtualWiki = pageInfo.getVirtualWikiName();
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, true, null);
    if (topic == null) {
      throw new WikiException(new WikiMessage("common.exception.notopic"));
    }
    String commentsPage = WikiUtil.extractCommentsLink(topicName);
    if (!topicName.equals(commentsPage)) {
      Topic commentsTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki, commentsPage, true, null);
      if (commentsTopic != null && commentsTopic.getDeleted() == topic.getDeleted()) {
        // add option to also move comments page
        next.addObject("manageCommentsPage", commentsPage);
      }
    }
    next.addObject("readOnly", topic.isReadOnly());
View Full Code Here

   */
  private void edit(HttpServletRequest request, ModelAndView next,
      WikiPageInfo pageInfo) throws Exception {
    String topicName = WikiUtil.getTopicFromRequest(request);
    String virtualWiki = pageInfo.getVirtualWikiName();
    Topic topic = loadTopic(virtualWiki, topicName);
    // topic name might be updated by loadTopic
    topicName = topic.getName();
    // Integer lastTopicVersionId = retrieveLastTopicVersionId(request, topic);
    // next.addObject("lastTopicVersionId", lastTopicVersionId);
    String contents = (String) request.getParameter("contents");
    if (isPreview(request)) {
      preview(request, next, pageInfo);
    } else if (isShowChanges(request)) {
      // showChanges(request, next, pageInfo, virtualWiki, topicName,
      // lastTopicVersionId);
      // } else if
      // (!StringUtils.isBlank(request.getParameter("topicVersionId"))) {
      // // editing an older version
      // Integer topicVersionId =
      // Integer.valueOf(request.getParameter("topicVersionId"));
      // TopicVersion topicVersion =
      // WikiBase.getDataHandler().lookupTopicVersion(topicVersionId);
      // if (topicVersion == null) {
      // throw new WikiException(new WikiMessage("common.exception.notopic"));
      // }
      // contents = topicVersion.getVersionContent();
      // if (!lastTopicVersionId.equals(topicVersionId)) {
      // next.addObject("topicVersionId", topicVersionId);
      // }
    } else if (!StringUtils.isBlank(request.getParameter("section"))) {
      // editing a section of a topic
      int section = Integer.valueOf(request.getParameter("section"));
      String[] sliceResults = ParserUtil.parseSlice(request.getContextPath(),
          request.getLocale(), virtualWiki, topicName, section);
      contents = sliceResults[1];
      String sectionName = sliceResults[0];
      String editComment = "/* " + sectionName + " */ ";
      next.addObject("editComment", editComment);
    } else {
      // editing a full new or existing topic
      contents = (topic == null) ? "" : topic.getTopicContent();
    }
    this.loadEdit(request, next, pageInfo, contents, virtualWiki, topicName,
        true);
  }
View Full Code Here

   * specified name already exists then it will be initialized, otherwise a new
   * topic is created.
   */
  private Topic loadTopic(String virtualWiki, String topicName)
      throws Exception {
    Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
    // if (topic.getReadOnly()) {
    // throw new WikiException(new WikiMessage("error.readonly"));
    // }
    return topic;
  }
View Full Code Here

            null) == null) {
      WikiMessage messageObject = new WikiMessage("login.message.editnew");
      return ServletUtil.viewLogin(request, pageInfo, WikiUtil
          .getTopicFromURI(request), messageObject);
    }
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName,
        false, null);
    if (topic == null) {
      // this should never trigger, but better safe than sorry...
      return null;
    }
View Full Code Here

  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();
    previewTopic.setName(topicName);
    previewTopic.setTopicContent(contents);
    previewTopic.setVirtualWiki(virtualWiki);
    next.addObject("editPreview", "true");
    ServletUtil.viewTopic(request, next, pageInfo, null, previewTopic, false,
        false);
  }
View Full Code Here

TOP

Related Classes of org.jamwiki.model.Topic

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.