Package info.bliki.htmlcleaner

Examples of info.bliki.htmlcleaner.TagNode


        if (tag instanceof IBodyTag) {
          fWikiModel.popNode();
        }
      }
    } catch (IllegalArgumentException e) {
      TagNode divTagNode = new TagNode("div");
      divTagNode.addAttribute("class", "error", true);
      divTagNode.addChild(new ContentToken("IllegalArgumentException: " + command + " - " + e.getMessage()));
      fWikiModel.append(divTagNode);
      e.printStackTrace();
    } catch (Throwable e) {
      e.printStackTrace();
      TagNode divTagNode = new TagNode("div");
      divTagNode.addAttribute("class", "error", true);
      divTagNode.addChild(new ContentToken(command + ": " + e.getMessage()));
      fWikiModel.append(divTagNode);
      e.printStackTrace();
    }
  }
View Full Code Here


      // }

      int level = wikiModel.incrementRecursionLevel();

      if (level > Configuration.PARSER_RECURSION_LIMIT) {
        TagNode error = new TagNode("span");
        error.addAttribute("class", "error", true);
        error.addChild(new ContentToken("Error - recursion limit exceeded parsing wiki tags."));
        localStack.append(error);
        return localStack;
      }
      // WikipediaParser parser = new WikipediaParser(rawWikitext,
      // wikiModel.isTemplateTopic(), wikiModel.getWikiListener());
      setModel(wikiModel);
      runParser();
      return localStack;
    } catch (InvalidPreWikiTag ipwt) {
      createOnlyLocalStack = true;
      throw ipwt;
    } catch (Exception e) {
      e.printStackTrace();
      TagNode error = new TagNode("span");
      error.addAttribute("class", "error", true);
      error.addChild(new ContentToken(e.getClass().getSimpleName()));
      localStack.append(error);
    } catch (Error e) {
      e.printStackTrace();
      TagNode error = new TagNode("span");
      error.addAttribute("class", "error", true);
      error.addChild(new ContentToken(e.getClass().getSimpleName()));
      localStack.append(error);
    } finally {
      wikiModel.decrementRecursionLevel();
      if (!createOnlyLocalStack) {
        // append the resursively parsed local stack to the global wiki
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public void appendExternalImageLink(String imageSrc, String imageAltText) {
    TagNode spanTagNode = new TagNode("span");
    append(spanTagNode);
    spanTagNode.addAttribute("class", "image", true);
    TagNode imgTagNode = new TagNode("img");
    spanTagNode.addChild(imgTagNode);
    imgTagNode.addAttribute("src", imageSrc, true);
    imgTagNode.addAttribute("alt", imageAltText, true);
    // "nofollow" keyword is not allowed for XHTML
    // imgTagNode.addAttribute("rel", "nofollow", true);
  }
View Full Code Here

   *          link was parsed
   */
  public void appendExternalLink(String uriSchemeName, String link, String linkName, boolean withoutSquareBrackets) {
    link = Utils.escapeXml(link, true, false, false);

    TagNode aTagNode = new TagNode("a");
    aTagNode.addAttribute("href", link, true);
    aTagNode.addAttribute("rel", "nofollow", true);
    if (withoutSquareBrackets) {
      aTagNode.addAttribute("class", "external free", true);
//      aTagNode.addAttribute("title", link, true);
      append(aTagNode);
      aTagNode.addChild(new ContentToken(linkName));
    } else {
      String trimmedText = linkName.trim();
      if (trimmedText.length() > 0) {
        pushNode(aTagNode);
        if (linkName.equals(link)
            // protocol-relative URLs also get auto-numbered if there is no real alias
            || (link.length() >= 2 && link.charAt(0) == '/' && link.charAt(1) == '/'
                && link.substring(2).equals(linkName))) {
          aTagNode.addAttribute("class", "external autonumber", true);
          aTagNode.addChild(new ContentToken("[" + (++fExternalLinksCounter) + "]"));
        } else {
          aTagNode.addAttribute("class", "external text", true);
//          aTagNode.addAttribute("title", link, true);
          WikipediaParser.parseRecursive(trimmedText, this, false, true);
        }
        popNode();
      }
View Full Code Here

  public ITableOfContent appendHead(String rawHead, int headLevel, boolean noToC, int headCounter, int startPosition,
      int endPosition) {
    TagStack localStack = WikipediaParser.parseRecursive(rawHead.trim(), this, true, true);

    WPTag headTagNode = new WPTag("h" + headLevel);
    TagNode spanTagNode = new TagNode("span");
    // Example:
    // <h2><span class="mw-headline" id="Header_level_2">Header level
    // 2</span></h2>
    spanTagNode.addChildren(localStack.getNodeList());
    headTagNode.addChild(spanTagNode);
    String tocHead = headTagNode.getBodyString();
    String anchor = Encoder.encodeDotUrl(tocHead);
    createTableOfContent(false);
    if (!noToC && (headCounter > 3)) {
      fTableOfContentTag.setShowToC(true);
    }
    if (fToCSet.contains(anchor)) {
      String newAnchor = anchor;
      for (int i = 2; i < Integer.MAX_VALUE; i++) {
        newAnchor = anchor + '_' + Integer.toString(i);
        if (!fToCSet.contains(newAnchor)) {
          break;
        }
      }
      anchor = newAnchor;
    }
    fToCSet.add(anchor);
    SectionHeader strPair = new SectionHeader(headLevel, startPosition, endPosition, tocHead, anchor);
    addToTableOfContent(fTableOfContent, strPair, headLevel);
    if (getRecursionLevel() == 1) {
      buildEditLinkUrl(fSectionCounter++);
    }
    spanTagNode.addAttribute("class", "mw-headline", true);
    spanTagNode.addAttribute("id", anchor, true);

    append(headTagNode);
    return fTableOfContentTag;
  }
View Full Code Here

   * {@inheritDoc}
   */
  public void appendInternalImageLink(String hrefImageLink, String srcImageLink, ImageFormat imageFormat) {
    String caption = imageFormat.getCaption();
    String imageType = imageFormat.getType();
    TagNode divInnerTagNode = new TagNode("div");
    divInnerTagNode.addAttribute("id", "image", false);

    if (hrefImageLink.length() != 0) {
      divInnerTagNode.addAttribute("href", hrefImageLink, false);
    }

    divInnerTagNode.addAttribute("src", srcImageLink, false);
    setDefaultThumbWidth(imageFormat);
    divInnerTagNode.addObjectAttribute("wikiobject", imageFormat);
    pushNode(divInnerTagNode);
    try {
      // TODO: test all these cases
      if (caption != null && caption.length() > 0
          && ("frame".equals(imageType) || "thumb".equals(imageType) || "thumbnail".equals(imageType))) {

        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 = imageFormat.getAlt();
        if (altAttribute == null) {
          altAttribute = captionTagNode.getBodyString();
          imageFormat.setAlt(Encoder.encodeHtml(altAttribute));// see issue #25
        }
        pushNode(captionTagNode);
        popNode();
      }
View Full Code Here

    if (replaceColon()) {
      encodedtopic = encodedtopic.replace(':', '/');
    }
    hrefLink = hrefLink.replace("${title}", encodedtopic);

    TagNode aTagNode = new TagNode("a");
    // append(aTagNode);
    aTagNode.addAttribute("href", hrefLink, true);
    // aTagNode.addChild(new ContentToken(linkText));
    pushNode(aTagNode);
    WikipediaParser.parseRecursive(linkText.trim(), this, false, true);
    popNode();
  }
View Full Code Here

        isbnUrl.append(isbnPureText.charAt(index));
      }
    }

    String isbnString = isbnUrl.toString();
    TagNode aTagNode = new TagNode("a");
    append(aTagNode);
    aTagNode.addAttribute("href", isbnString, true);
    aTagNode.addAttribute("class", "external text", true);
    aTagNode.addAttribute("title", isbnString, true);
    aTagNode.addAttribute("rel", "nofollow", true);
    aTagNode.addChild(new ContentToken(isbnPureText));
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public void appendMailtoLink(String link, String linkName, boolean withoutSquareBrackets) {
    TagNode aTagNode = new TagNode("a");
    append(aTagNode);
    aTagNode.addAttribute("href", link, true);
    aTagNode.addAttribute("class", "external free", true);
    aTagNode.addAttribute("title", link, true);
    aTagNode.addAttribute("rel", "nofollow", true);
    aTagNode.addChild(new ContentToken(linkName));
  }
View Full Code Here

      fTagStack.append(stack);
    }
  }

  public TagNode appendToCAnchor(String anchor) {
    TagNode aTagNode = new TagNode("a");
    aTagNode.addAttribute("name", anchor, true);
    aTagNode.addAttribute("id", anchor, true);
    return aTagNode;
  }
View Full Code Here

TOP

Related Classes of info.bliki.htmlcleaner.TagNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.