Exemple #1
0
 protected static void setupSpecialPage(
     Locale locale,
     String virtualWiki,
     String topicName,
     WikiUser user,
     boolean adminOnly,
     Connection conn)
     throws Exception {
   logger.info("Setting up special page " + virtualWiki + " / " + topicName);
   String contents = Utilities.readSpecialPage(locale, topicName);
   Topic topic = new Topic();
   topic.setName(topicName);
   topic.setVirtualWiki(virtualWiki);
   topic.setTopicContent(contents);
   topic.setAdminOnly(adminOnly);
   // FIXME - hard coding
   TopicVersion topicVersion =
       new TopicVersion(
           user, user.getLastLoginIpAddress(), "Automatically created by system setup", contents);
   WikiBase.getDataHandler()
       .writeTopic(
           topic,
           topicVersion,
           Utilities.parserDocument(topic.getTopicContent(), virtualWiki, topicName),
           true,
           conn);
 }
Exemple #2
0
 private void preview(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = JAMWikiServlet.getTopicFromRequest(request);
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   String contents = (String) request.getParameter("contents");
   Topic previewTopic = new Topic();
   previewTopic.setName(topicName);
   previewTopic.setTopicContent(contents);
   previewTopic.setVirtualWiki(virtualWiki);
   pageInfo.setAction(WikiPageInfo.ACTION_EDIT_PREVIEW);
   next.addObject("contents", contents);
   viewTopic(request, next, pageInfo, null, previewTopic, false);
 }
Exemple #3
0
 /**
  * Initialize topic values for a Topic object. This method will check to see if a topic with the
  * specified name exists, and if it does exist then that topic will be returned. Otherwise a new
  * topic will be initialized, setting initial parameters such as topic name, virtual wiki, and
  * topic type.
  *
  * @param virtualWiki The virtual wiki name for the topic being initialized.
  * @param topicName The name of the topic being initialized.
  * @return A new topic object with basic fields initialized, or if a topic with the given name
  *     already exists then the pre-existing topic is returned.
  * @throws Exception Thrown if any error occurs while retrieving or initializing the topic object.
  */
 protected static Topic initializeTopic(String virtualWiki, String topicName) throws Exception {
   WikiUtil.validateTopicName(topicName);
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic != null) {
     return topic;
   }
   topic = new Topic();
   topic.setName(topicName);
   topic.setVirtualWiki(virtualWiki);
   WikiLink wikiLink = LinkUtil.parseWikiLink(topicName);
   String namespace = wikiLink.getNamespace();
   if (namespace != null) {
     if (namespace.equals(NamespaceHandler.NAMESPACE_CATEGORY)) {
       topic.setTopicType(Topic.TYPE_CATEGORY);
     } else if (namespace.equals(NamespaceHandler.NAMESPACE_TEMPLATE)) {
       topic.setTopicType(Topic.TYPE_TEMPLATE);
     }
   }
   return topic;
 }
 protected void writeTopic(HttpServletRequest request, String editComment) throws Exception {
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   String topicName =
       NamespaceHandler.NAMESPACE_JAMWIKI
           + NamespaceHandler.NAMESPACE_SEPARATOR
           + Utilities.decodeFromRequest(filename(request));
   String contents =
       "<pre><nowiki>\n" + Utilities.readFile(filename(request)) + "\n</nowiki></pre>";
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic == null) {
     topic = new Topic();
     topic.setVirtualWiki(virtualWiki);
     topic.setName(topicName);
   }
   topic.setTopicContent(contents);
   topic.setReadOnly(true);
   topic.setTopicType(Topic.TYPE_SYSTEM_FILE);
   WikiUser user = Utilities.currentUser();
   TopicVersion topicVersion =
       new TopicVersion(user, request.getRemoteAddr(), editComment, contents);
   WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, true, null);
 }