コード例 #1
0
ファイル: LinkUtil.java プロジェクト: coowoole/gwtwiki
 /**
  * Utility method for determining if an article name corresponds to a valid wiki link. In this
  * case an "article name" could be an existing topic, a "Special:" page, a user page, an interwiki
  * link, etc. This method will return true if the given name corresponds to a valid special page,
  * user page, topic, or other existing article.
  *
  * @param virtualWiki The virtual wiki for the topic being checked.
  * @param articleName The name of the article that is being checked.
  * @return <code>true</code> if there is an article that exists for the given name and virtual
  *     wiki.
  * @throws DataAccessException Thrown if an error occurs during lookup.
  */
 public static boolean isExistingArticle(String virtualWiki, String articleName)
     throws DataAccessException {
   // if (StringUtils.isBlank(virtualWiki) || StringUtils.isBlank(articleName))
   // {
   if (StringUtils.isBlank(articleName)) {
     return false;
   }
   if (PseudoTopicHandler.isPseudoTopic(articleName)) {
     return true;
   }
   if (InterWikiHandler.isInterWiki(articleName)) {
     return true;
   }
   // if
   // (StringUtils.isBlank(Environment.getValue(Environment.PROP_BASE_FILE_DIR
   // )) || !Environment.getBooleanValue(Environment.PROP_BASE_INITIALIZED)) {
   // // not initialized yet
   // return false;
   // }
   return (WikiBase.getDataHandler().lookupTopic(virtualWiki, articleName, false, null) != null);
 }
コード例 #2
0
ファイル: WikiUtil.java プロジェクト: Eljah/jamwiki
 /**
  * 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));
   }
 }