예제 #1
0
  @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));
    }
  }
예제 #2
0
  @Override
  public void appendInternalLink(
      String topic,
      String hashSection,
      String topicDescription,
      String cssClass,
      boolean parseRecursive) {
    try {
      String virtualWiki = fParserInput.getVirtualWiki();
      WikiLink wikiLink;
      if (hashSection != null) {
        wikiLink = LinkUtil.parseWikiLink(virtualWiki, topic + "#" + hashSection);
      } else {
        wikiLink = LinkUtil.parseWikiLink(virtualWiki, topic);
      }
      String destination = wikiLink.getDestination();
      String section = wikiLink.getSection();
      String query = wikiLink.getQuery();
      String href = buildTopicUrlNoEdit(fContextPath, virtualWiki, destination, section, query);
      String style = "";
      if (StringUtils.isBlank(topic) && !StringUtils.isBlank(section)) {
        // do not check existence for section links
      } else {
        String articleName = topic.replace('_', ' ');
        if (LinkUtil.isExistingArticle(virtualWiki, articleName) == null) {
          style = "edit";
          href = LinkUtil.buildEditLinkUrl(fContextPath, virtualWiki, topic, query, -1);
        }
      }
      WPATag aTagNode = new WPATag();
      aTagNode.addAttribute("href", href, true);
      aTagNode.addAttribute("class", style, true);
      aTagNode.addObjectAttribute("wikilink", topic);

      pushNode(aTagNode);
      if (parseRecursive) {
        WikipediaParser.parseRecursive(topicDescription.trim(), this, false, true);
      } else {
        aTagNode.addChild(new ContentToken(topicDescription));
      }
      popNode();
    } catch (DataAccessException e1) {
      e1.printStackTrace();
      append(new ContentToken(topicDescription));
    }
  }
예제 #3
0
  public void parseInternalImageLink(String imageNamespace, String name) {
    // see JAMHTMLConverter#imageNodeToText() for the real HTML conversion
    // routine!!!
    ImageFormat imageFormat = ImageFormat.getImageFormat(name, imageNamespace);

    int pxWidth = imageFormat.getWidth();
    String caption = imageFormat.getCaption();
    TagNode divTagNode = new TagNode("div");
    divTagNode.addAttribute("id", "image", false);
    // divTagNode.addAttribute("href", hrefImageLink, false);
    // divTagNode.addAttribute("src", srcImageLink, false);
    divTagNode.addObjectAttribute("wikiobject", imageFormat);
    if (pxWidth != -1) {
      divTagNode.addAttribute("style", "width:" + pxWidth + "px", false);
    }
    pushNode(divTagNode);

    if (caption != null && caption.length() > 0) {

      TagNode captionTagNode = new TagNode("div");
      String clazzValue = "caption";
      String type = imageFormat.getType();
      if (type != null) {
        clazzValue = type + clazzValue;
      }
      captionTagNode.addAttribute("class", clazzValue, false);

      TagStack localStack = WikipediaParser.parseRecursive(caption, this, true, true);
      captionTagNode.addChildren(localStack.getNodeList());
      String altAttribute = captionTagNode.getBodyString();
      imageFormat.setAlt(altAttribute);
      pushNode(captionTagNode);
      // WikipediaParser.parseRecursive(caption, this);
      popNode();
    }

    popNode(); // div
  }