Package org.jamwiki.model

Examples of org.jamwiki.model.Topic


   */
  private void resolve(HttpServletRequest request, ModelAndView next,
      WikiPageInfo pageInfo) throws Exception {
    String topicName = WikiUtil.getTopicFromRequest(request);
    String virtualWiki = pageInfo.getVirtualWikiName();
    Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki,
        topicName, false, null);
    String contents1 = lastTopic.getTopicContent();
    String contents2 = request.getParameter("contents");
    // next.addObject("lastTopicVersionId", lastTopic.getCurrentVersionId());
    next.addObject("contentsResolve", contents2);
    this.loadDiff(request, next, pageInfo, contents1, contents2);
    this.loadEdit(request, next, pageInfo, contents1, virtualWiki, topicName,
View Full Code Here


   */
  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;
View Full Code Here

    }
    String virtualWiki = pageInfo.getVirtualWikiName();
    if (StringUtils.isBlank(virtualWiki)) {
      virtualWiki = WikiBase.DEFAULT_VWIKI;
    }
    Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
    if (topic.getContent()==null) {
      // topic does not exist, display empty page
      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);
View Full Code Here

    TopicVersion topicVersion = WikiBase.getDataHandler().lookupTopicVersion(
        topicVersionId);
    if (topicVersion == null) {
      throw new WikiException(new WikiMessage("common.exception.notopic"));
    }
    Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName,
        false, null);
    if (topic == null) {
      // the topic may have been deleted
      throw new WikiException(new WikiMessage("history.message.notopic",
          topicName));
    }
    topic.setTopicContent(topicVersion.getVersionContent());
    String versionDate = DateFormat.getDateTimeInstance().format(
        topicVersion.getEditDate());
    WikiMessage pageTitle = new WikiMessage("topic.title", topicName + " @"
        + versionDate);
    ServletUtil.viewTopic(request, next, pageInfo, pageTitle, topic, false,
View Full Code Here

    // if (cacheElement != null) {
    // content = (String) cacheElement.getObjectValue();
    // return (content == null) ? null : content;
    // }
    try {
      Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
      if (topic == null) {
        return "";
      }
      content = topic.getTopicContent();
      if (cook) {
        ParserInput parserInput = new ParserInput();
        parserInput.setContext(context);
        parserInput.setLocale(locale);
        parserInput.setVirtualWiki(virtualWiki);
View Full Code Here

   *           Thrown if any error occurs while retrieving or initializing the
   *           topic object.
   */
  protected static Topic initializeTopic(String virtualWiki, String topicName) throws WikiException {
    // WikiUtil.validateTopicName(topicName);
    Topic topic = null;
    // try {
    topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    // } catch (DataAccessException e) {
    // throw new WikiException(new WikiMessage("error.unknown", e.getMessage()),
    // e);
    // }
    if (topic != null) {
      return topic;
    }
    topic = new Topic();
    topic.setName(topicName);
    // topic.setVirtualWiki(virtualWiki);
    WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
    String namespace = wikiLink.getNamespace();
    topic.setTopicType(WikiUtil.findTopicTypeForNamespace(namespace));
    return topic;
  }
View Full Code Here

  protected static boolean isEditable(String virtualWiki, String topicName, WikiUserDetails user) throws WikiException {
    if (user == null || !user.hasRole(RoleImpl.ROLE_EDIT_EXISTING)) {
      // user does not have appropriate permissions
      return false;
    }
    Topic topic = null;
    try {
      if (!user.hasRole(RoleImpl.ROLE_EDIT_NEW)
          && WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null) == null) {
        // user does not have appropriate permissions
        return false;
      }
      topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    } catch (Exception e) {
      throw new WikiException(new WikiMessage("error.unknown", e.getMessage()), e);
    }
    if (topic == null) {
      // new topic, edit away...
      return true;
    }
    if (topic.isAdminOnly() && !user.hasRole(RoleImpl.ROLE_ADMIN)) {
      return false;
    }
    if (topic.isReadOnly()) {
      return false;
    }
    return true;
  }
View Full Code Here

  protected static boolean isMoveable(String virtualWiki, String topicName, WikiUserDetails user) throws WikiException {
    if (user == null || !user.hasRole(RoleImpl.ROLE_MOVE)) {
      // no permission granted to move pages
      return false;
    }
    Topic topic = null;
    // try {
    topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
    // } catch (DataAccessException e) {
    // throw new WikiException(new WikiMessage("error.unknown", e.getMessage()),
    // e);
    // }
    if (topic == null) {
      // cannot move a topic that doesn't exist
      return false;
    }
    if (topic.isReadOnly()) {
      return false;
    }
    if (topic.isAdminOnly() && !user.hasRole(RoleImpl.ROLE_ADMIN)) {
      return false;
    }
    return true;
  }
View Full Code Here

    try {
      contents = WikiUtil.readSpecialPage(locale, topicName);
    } catch (IOException e) {
      throw new DataAccessException(e);
    }
    Topic topic = new Topic();
    topic.setName(topicName);
    topic.setVirtualWiki(virtualWiki);
    topic.setTopicContent(contents);
    topic.setAdminOnly(adminOnly);
    int charactersChanged = StringUtils.length(contents);
    // FIXME - hard coding
    TopicVersion topicVersion = new TopicVersion(user, user
        .getLastLoginIpAddress(), "Automatically created by system setup",
        contents, charactersChanged);
View Full Code Here

    change.setTopicVersionId(rs.getTopicVersionId());
    change.setPreviousTopicVersionId(rs.getPreviousTopicVersionId());
    Key<Topic> topicId = rs.getTopicKey();
    change.setTopicOKey(topicId);

    Topic topic = rs.getTopicId();
    change.setTopicName(topic.getName());
    change.setCharactersChanged(rs.getCharactersChanged());
    change.setChangeDate(rs.getChangeDate());
    change.setChangeComment(rs.getChangeComment());

    change.setAuthorId(rs.getAuthorId());

    change.setAuthorName(rs.getAuthorName());
    int editType = rs.getEditType();
    if (editType > 0) {
      change.setEditType(editType);
      // change.initChangeWikiMessageForVersion(editType,
      // .getString("log_params"));
    }
    // int logType = rs.getInt("log_type");
    // if (logType > 0) {
    // change.setLogType(logType);
    // change.initChangeWikiMessageForLog(logType, rs.getString("log_params"));
    // }
    change.setVirtualWiki(topic.getVirtualWiki());
    return change;
  }
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.