Exemple #1
0
 /**
  * Given an article name, extract an appropriate topic article name. For example, if the article
  * name is "Comments:Topic" then the return value is "Topic".
  *
  * @param virtualWiki The current virtual wiki.
  * @param name The article name from which a topic article name is to be constructed.
  * @return The topic article name for the article name.
  */
 public static String extractTopicLink(String virtualWiki, String name) {
   if (StringUtils.isBlank(name)) {
     throw new IllegalArgumentException("Topic name must not be empty in extractTopicLink");
   }
   WikiLink wikiLink = LinkUtil.parseWikiLink(virtualWiki, name);
   Namespace mainNamespace = Namespace.findMainNamespace(wikiLink.getNamespace());
   if (mainNamespace == null) {
     throw new IllegalArgumentException("Topic " + name + " does not have a main namespace");
   }
   return (!StringUtils.isBlank(mainNamespace.getLabel(virtualWiki)))
       ? mainNamespace.getLabel(virtualWiki) + Namespace.SEPARATOR + wikiLink.getArticle()
       : wikiLink.getArticle();
 }
Exemple #2
0
 /**
  * Given an article name, return the appropriate comments topic article name. For example, if the
  * article name is "Topic" then the return value is "Comments:Topic".
  *
  * @param virtualWiki The current virtual wiki.
  * @param name The article name from which a comments article name is to be constructed.
  * @return The comments article name for the article name.
  */
 public static String extractCommentsLink(String virtualWiki, String name) {
   if (StringUtils.isBlank(name)) {
     throw new IllegalArgumentException("Topic name must not be empty in extractCommentsLink");
   }
   WikiLink wikiLink = LinkUtil.parseWikiLink(virtualWiki, name);
   Namespace commentsNamespace = null;
   try {
     commentsNamespace = Namespace.findCommentsNamespace(wikiLink.getNamespace());
   } catch (DataAccessException e) {
     throw new IllegalStateException("Database error while retrieving comments namespace", e);
   }
   if (commentsNamespace == null) {
     throw new IllegalArgumentException("Topic " + name + " does not have a comments namespace");
   }
   return (!StringUtils.isBlank(commentsNamespace.getLabel(virtualWiki)))
       ? commentsNamespace.getLabel(virtualWiki) + Namespace.SEPARATOR + wikiLink.getArticle()
       : wikiLink.getArticle();
 }
Exemple #3
0
 @Test
 public void testConstructor() throws Throwable {
   WikiLink wikiLink = new WikiLink("/wiki", "en", null);
   assertNull("wikiLink.getQuery()", wikiLink.getQuery());
   assertNull("wikiLink.getSection()", wikiLink.getSection());
   assertNull("wikiLink.getText()", wikiLink.getText());
   assertNull("wikiLink.getArticle()", wikiLink.getArticle());
   assertEquals(
       "wikiLink.getNamespace()", Namespace.namespace(Namespace.MAIN_ID), wikiLink.getNamespace());
   assertNull("wikiLink.getDestination()", wikiLink.getDestination());
   assertFalse("wikiLink.getColon()", wikiLink.getColon());
 }
Exemple #4
0
 /**
  * Utility method for determining if a topic name is valid for use on the Wiki, meaning that it is
  * not empty and does not contain any invalid characters.
  *
  * @param virtualWiki The current virtual wiki.
  * @param name The topic name to validate.
  * @throws WikiException Thrown if the user name is invalid.
  */
 public static void validateTopicName(String virtualWiki, String name) throws WikiException {
   if (StringUtils.isBlank(virtualWiki)) {
     throw new WikiException(new WikiMessage("common.exception.novirtualwiki"));
   }
   if (StringUtils.isBlank(name)) {
     throw new WikiException(new WikiMessage("common.exception.notopic"));
   }
   if (PseudoTopicHandler.isPseudoTopic(name)) {
     throw new WikiException(new WikiMessage("common.exception.pseudotopic", name));
   }
   WikiLink wikiLink = LinkUtil.parseWikiLink(virtualWiki, name);
   String article = StringUtils.trimToNull(wikiLink.getArticle());
   if (StringUtils.startsWith(article, "/")) {
     throw new WikiException(new WikiMessage("common.exception.name", name));
   }
   if (wikiLink.getNamespace().getId().equals(Namespace.SPECIAL_ID)) {
     throw new WikiException(new WikiMessage("common.exception.name", name));
   }
   Matcher m = WikiUtil.INVALID_TOPIC_NAME_PATTERN.matcher(name);
   if (m.find()) {
     throw new WikiException(new WikiMessage("common.exception.name", name));
   }
 }
Exemple #5
0
 @Test
 public void testParseWikiLink() throws Throwable {
   WikiLink result = LinkUtil.parseWikiLink("en", "testLinkUtilRaw");
   assertEquals("result.getArticle()", "testLinkUtilRaw", result.getArticle());
 }
Exemple #6
0
 @Test
 public void testParseWikiLink1() throws Throwable {
   WikiLink result = LinkUtil.parseWikiLink(null, "");
   assertNull("result.getArticle()", result.getArticle());
 }
Exemple #7
0
 @Test
 public void testSetArticle() throws Throwable {
   WikiLink wikiLink = new WikiLink("/wiki", "en", null);
   wikiLink.setArticle("testWikiLinkArticle");
   assertEquals("wikiLink.getArticle()", "testWikiLinkArticle", wikiLink.getArticle());
 }