コード例 #1
0
ファイル: JAMWikiModel.java プロジェクト: Eljah/jamwiki
 /**
  * Build a URL to the topic page for a given topic. This method does NOT verify if the topic
  * exists or if it is a "Special:" page, simply returning the URL for the topic and virtual wiki.
  *
  * @param context The servlet context path. If this value is <code>null</code> then the resulting
  *     URL will NOT include context path, which breaks HTML links but is useful for servlet
  *     redirection URLs.
  * @param virtualWiki The virtual wiki for the link that is being created.
  * @param topicName The name of the topic for which a link is being built.
  * @param section The section of the page (#section) for which a link is being built.
  * @param queryString Query string parameters to append to the link.
  * @throws Exception Thrown if any error occurs while builing the link URL.
  */
 private static String buildTopicUrlNoEdit(
     String context, String virtualWiki, String topicName, String section, String queryString) {
   // TODO same as LinkUtil#buildTopicUrlNoEdit()
   if (StringUtils.isBlank(topicName) && !StringUtils.isBlank(section)) {
     return "#" + Utilities.encodeAndEscapeTopicName(section);
   }
   StringBuilder url = new StringBuilder();
   if (context != null) {
     url.append(context);
   }
   // context never ends with a "/" per servlet specification
   url.append('/');
   // get the virtual wiki, which should have been set by the parent servlet
   url.append(Utilities.encodeAndEscapeTopicName(virtualWiki));
   url.append('/');
   url.append(Utilities.encodeAndEscapeTopicName(topicName));
   if (!StringUtils.isBlank(queryString)) {
     if (queryString.charAt(0) != '?') {
       url.append('?');
     }
     url.append(queryString);
   }
   if (!StringUtils.isBlank(section)) {
     if (section.charAt(0) != '#') {
       url.append('#');
     }
     url.append(Utilities.encodeAndEscapeTopicName(section));
   }
   return url.toString();
 }
コード例 #2
0
ファイル: JAMWikiModel.java プロジェクト: Eljah/jamwiki
  @Override
  public void appendInterWikiLink(String namespace, String title, String topicDescription) {
    String hrefLink = getInterwikiMap().get(namespace.toLowerCase());
    if (hrefLink != null) {
      String virtualWiki = fParserInput.getVirtualWiki();
      WikiLink wikiLink =
          LinkUtil.parseWikiLink(
              virtualWiki, namespace + Namespace.SEPARATOR + title + "|" + topicDescription);
      String destination = wikiLink.getDestination();
      destination =
          destination.substring(
              wikiLink.getNamespace().getLabel(virtualWiki).length()
                  + Namespace.SEPARATOR.length());
      hrefLink = hrefLink.replace("${title}", Utilities.encodeAndEscapeTopicName(title));
      TagNode aTagNode = new TagNode("a");
      aTagNode.addAttribute("href", hrefLink, true);
      aTagNode.addAttribute("class", "interwiki", false);

      pushNode(aTagNode);
      WikipediaParser.parseRecursive(topicDescription.trim(), this, false, true);
      popNode();

    } else {
      append(new ContentToken(topicDescription));
    }
  }