Beispiel #1
0
  public static ImageFormat getImageFormat(String rawImageLink, String imageNamespace) {
    ImageFormat img = new ImageFormat();
    List<String> list = WikipediaScanner.splitByPipe(rawImageLink, null);
    if (list.size() > 0) {
      String attrValue;
      String token = list.get(0);
      img.setFilename("");
      if (token.length() > imageNamespace.length()
          && token.charAt(imageNamespace.length()) == ':') {
        if (imageNamespace.equalsIgnoreCase(token.substring(0, imageNamespace.length()))) {
          img.setFilename(token.substring(imageNamespace.length() + 1));
          img.setNamespace(imageNamespace);
        }
      }
      String caption;
      for (int j = 1; j < list.size(); j++) {
        caption = list.get(j).trim();
        if (caption.length() > 0) {
          token = caption.toLowerCase();
          int defIndex = token.indexOf("=");
          if (defIndex > 0) {
            token = token.substring(0, defIndex).trim();
            if (token.equals("link")) {
              attrValue = caption.substring(defIndex + 1).trim();
              img.setLink(attrValue);
              continue;
            }
            if (token.equals("alt")) {
              attrValue = caption.substring(defIndex + 1).trim();
              img.setAlt(Encoder.encodeHtml(attrValue));
              continue;
            }
          } else {
            if (token.equals("frame")
                || token.equals("thumb")
                || token.equals("thumbnail")
                || token.equals("border")) {
              img.setType(token);
              continue;
            }

            if (token.equals("right")
                || token.equals("left")
                || token.equals("center")
                || token.equals("none")) {
              img.setLocation(token);
              continue;
            }

            if (token.endsWith("px")) {
              img.setSize(token);
              continue;
            }
          }
          img.setCaption(caption);
        }
      }
    }
    return img;
  }
Beispiel #2
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
  }