Package info.bliki.htmlcleaner

Examples of info.bliki.htmlcleaner.TagNode


      String content = contentToken.getContent();
      content = content.replaceAll(" ", " ");
      // content = StringUtils.replace(content, " ", " ");
      wikiText.append(content);
    } else if (node instanceof TagNode) {
      TagNode tagNode = (TagNode) node;

      String name = tagNode.getName();
      HTMLTag tag = fHashMap.get(name);

      if (tag != null) {
        boolean showWithoutTag = false;
        if (fNoDiv && name.equals("div")) {
          showWithoutTag = true;
        }
        if (fNoFont && name.equals("font")) {
          showWithoutTag = true;
        }
        tag.content(this, tagNode, wikiText, showWithoutTag);
      } else {
        if (name.equals("br")) {
          wikiText.append("<br>");
        } else if (name.equals("hr")) {
          wikiText.append("\n----\n");
        } else {
          List children = tagNode.getChildren();
          if (children.size() != 0) {
            nodesToText(children, wikiText);
          }
        }
      }
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

                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if (tag != null) {
                      tag = (TagToken) tag.clone();

                      if (tag instanceof TagNode) {
                        TagNode node = (TagNode) tag;
                        List<NodeAttribute> attributes = tagNode.getAttributesEx();
                        Attribute attr;
                        for (int i = 1; i < attributes.size(); i++) {
                          attr = attributes.get(i);
                          node.addAttribute(attr.getName(), attr.getValue(), true);
                        }
                      }
                      if (tag instanceof HTMLTag) {
                        ((HTMLTag) tag).setTemplate(isTemplate());
                      }
View Full Code Here

      content = content.replaceAll("&quot;", "\"");
      content = content.replaceAll("&amp;", "&");
      content = content.replaceAll("&apos;", "'");
      plainText.append(content);
    } else if (node instanceof TagNode) {
      TagNode tagNode = (TagNode) node;
      List children = tagNode.getChildren();
      if (children.size() != 0) {
        nodesToPlainText(children, plainText);
      }
    }
  }
View Full Code Here

        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();
      return;
    }
  }
View Full Code Here

    // || ext.equalsIgnoreCase("bmp")) {
    // appendExternalImageLink(link, linkName);
    // return;
    // }
    // }
    TagNode aTagNode = new TagNode("a");
    aTagNode.addAttribute("href", link, true);
    aTagNode.addAttribute("rel", "nofollow", true);
    if (withoutSquareBrackets) {
      aTagNode.addAttribute("class", "externallink", 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)) {
          if (withoutSquareBrackets) {
            aTagNode.addAttribute("class", "externallink", true);
            aTagNode.addAttribute("title", link, true);
            aTagNode.addChild(new ContentToken(trimmedText));
          } else {
            aTagNode.addAttribute("class", "external autonumber", true);
            aTagNode.addChild(new ContentToken("["+(++fExternalLinksCounter)+"]"));
          }
        } else {
          aTagNode.addAttribute("class", "externallink", true);
          aTagNode.addAttribute("title", link, true);
          WikipediaParser.parseRecursive(trimmedText, this, false, true);
        }
        popNode();
      }
    }
View Full Code Here

            } else if (item instanceof WPTable) {
              ((WPTable) item).renderPlainText(this, resultBuffer, model);
            } else if (item instanceof HTMLTag) {
              ((HTMLTag) item).getBodyString(resultBuffer);
            } else if (item instanceof TagNode) {
              TagNode node = (TagNode) item;
              Map<String, Object> map = node.getObjectAttributes();
              if (map != null && map.size() > 0) {
              } else {
                node.getBodyString(resultBuffer);
              }
            }
          }
        }
      } finally {
View Full Code Here

                    TagToken tag = fWikiModel.getTokenMap().get(tagName);
                    if (tag != null) {
                      tag = (TagToken) tag.clone();

                      if (tag instanceof TagNode) {
                        TagNode node = (TagNode) tag;
                        List<NodeAttribute> attributes = tagNode.getAttributesEx();
                        Attribute attr;
                        for (int i = 1; i < attributes.size(); i++) {
                          attr = attributes.get(i);
                          node.addAttribute(attr.getName(), attr.getValue(), true);
                        }
                      }
                      if (tag instanceof HTMLTag) {
                        ((HTMLTag) tag).setTemplate(isTemplate());
                      }
View Full Code Here

        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

  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

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.