Package org.jsoup.nodes

Examples of org.jsoup.nodes.Node


  private String retrieveContent(final Document documentFragment) {
    String strippedString = "";
    List<Node> children = documentFragment.body().childNodes();
    for (int pos = 0; pos < children.size(); pos++) {
      Node node = children.get(pos);
      String text = getTextFromNode(node);
      if (!text.equals("")) {
        if (strippedString.equals("") || strippedString.endsWith(" ") || strippedString.endsWith("/")
            || strippedString.endsWith(".") || strippedString.endsWith(":")) {
          // directly add the text if the string is empty or ends with a space, slash, dot, doublepoint
View Full Code Here


  @Override
  public Index getIndexInParent(final Node node, final boolean byType) {
    String type = byType ? getName(node) : Selector.UNIVERSAL_TAG;

    List<? extends Node> children;
    Node parent = node.parent();
    if (parent==null)
      children = Collections.emptyList();
    else
      children = getChildNodes(parent, type);
View Full Code Here

    public NodeTraversor(NodeVisitor visitor) {
        this.visitor = visitor;
    }

    public void traverse(Node root) {
        Node node = root;
        int depth = 0;
       
        while (node != null) {
            visitor.head(node, depth);
            if (node.childNodes().size() > 0) {
                node = node.childNode(0);
                depth++;
            } else {
                while (node.nextSibling() == null && depth > 0) {
                    visitor.tail(node, depth);
                    node = node.parent();
                    depth--;
                }
                visitor.tail(node, depth);
                if (node == root)
                    break;
                node = node.nextSibling();
            }
        }
    }
View Full Code Here

                text = helper.getMessage(key, paramMap);
            } catch (InvalidMessageException e) {
                logger.warn("failed to get the message. key=" + key, e);
                text = '!' + key + '!';
            }
            Node node;
            if (text.startsWith(ExtNodeConstants.MSG_NODE_ATTRVALUE_TEXT_PREFIX)) {
                node = ElementUtil.text(text.substring(ExtNodeConstants.MSG_NODE_ATTRVALUE_TEXT_PREFIX.length()));
            } else if (text.startsWith(ExtNodeConstants.MSG_NODE_ATTRVALUE_HTML_PREFIX)) {
                node = ElementUtil.parseAsSingle(text.substring(ExtNodeConstants.MSG_NODE_ATTRVALUE_HTML_PREFIX.length()));
            } else {
View Full Code Here

    public static final class IsEmpty extends Evaluator {
    @Override
    public boolean matches(Element root, Element element) {
          List<Node> family = element.childNodes();
          for (int i = 0; i < family.size(); i++) {
            Node n = family.get(i);
            if (!(n instanceof Comment || n instanceof XmlDeclaration || n instanceof DocumentType)) return false;
          }
          return true;
    }
View Full Code Here

    return StringUtils.multiply('`', max + 1);
  }

  private String getTextNodeText(TextNode tn, boolean normalText) {
    String input = normalText ? tn.text() : tn.getWholeText();
    Node prev = tn.previousSibling();
    Node next = tn.nextSibling();
    boolean parentIsBlock = isBlock(tn.parent());
    if(isBlock(prev)) {
      input = ltrim(input);
    } else if(prev == null && parentIsBlock) {
      input = ltrim(input);
View Full Code Here

  private Rules checkInword(Element node, DocumentConverter converter) {
    Rules result = new Rules();
    Options.InWordEmphasis iwe = converter.options.getInWordEmphasis();
    if(!iwe.isEmphasisPreserved() || iwe.isAdditionalSpacingNeeded()) {
      // peek behind for inline styling
      Node n = node.previousSibling();
      if(n != null && n instanceof TextNode) {
        TextNode tn = (TextNode)n;
        String text = tn.text();
        if(INWORD_CHARACTER.matcher(text.substring(text.length()-1)).matches()) {
          result.emphasisPreserved = iwe.isEmphasisPreserved();
View Full Code Here

  }

  public static String readAnnotation(Node node) {
      if (null == node) return null;

      Node preceding = node.previousSibling();

      //if this is a text node, then match for annotations
      return readAnnotation(node.outerHtml());       
  }
View Full Code Here

  // TESTING jsoup.nodes.Node

  public List<Node> findSiblings(Node node) {
      Preconditions.checkNotNull(node);
   
      Node parent = node.parent();
      if (null == parent) return null;

      return parent.childNodes();              
  }
View Full Code Here

    chain.addWidget(new HeaderWidget(new TerminalWidgetChain(),
        Maps.<String, String>newHashMap(), compiler));

    List<Node> nodes = HtmlParser.parse("<html>" + requireString + "</html>");
    Node node = nodes.get(0).childNode(0);

    WidgetChain inner = Chains.terminal();
    if (!node.childNodes().isEmpty())
      inner = Chains.singleton(new TextWidget(node.childNode(0).toString(), compiler));

    chain.addWidget(new RequireWidget(new XmlWidget(inner, node.nodeName(), compiler,
        HtmlTemplateCompiler.parseAttribs(node.attributes()))));
    chain.addWidget(new RequireWidget(new XmlWidget(inner, node.nodeName(), compiler,
        HtmlTemplateCompiler.parseAttribs(node.attributes()))));
    chain.addWidget(new RequireWidget(new XmlWidget(inner, node.nodeName(), compiler,
        HtmlTemplateCompiler.parseAttribs(node.attributes()))));

    //render
    chain.render(new Object(), respond);

    final String expected = "<head>" + requireString + "</head>";
View Full Code Here

TOP

Related Classes of org.jsoup.nodes.Node

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.