Example #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;
  }
Example #2
0
 public String parseFunction(char[] src, int beginIndex, int endIndex, IWikiModel model)
     throws IOException {
   List<String> list = new ArrayList<String>();
   WikipediaScanner.splitByPipe(src, beginIndex, endIndex, list);
   if (list.size() > 0) {
     String result = parse(list.get(0), model);
     return URLEncoder.encode(result, Connector.UTF8_CHARSET);
   }
   return null;
 }