Java Code Examples for org.jsoup.helper.StringUtil#in()

The following examples show how to use org.jsoup.helper.StringUtil#in() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void head(Node node, int depth) {
	String name = node.nodeName();
	if (node instanceof TextNode) {
		append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
	} else if (name.equals("ul")) {
		listNesting++;
	} else if (name.equals("li")) {
		append("\n ");
		for (int i = 1; i < listNesting; i++) {
			append("  ");
		}
		if (listNesting == 1) {
			append("* ");
		} else {
			append("- ");
		}
	} else if (name.equals("dt")) {
		append("  ");
	} else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr")) {
		append("\n");
	}
}
 
Example 2
boolean inSelectScope(String targetName) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element el = stack.get(pos);
        String elName = el.nodeName();
        if (elName.equals(targetName))
            return true;
        if (!StringUtil.in(elName, TagSearchSelectScope)) // all elements except
            return false;
    }
    Validate.fail("Should not be reachable");
    return false;
}
 
Example 3
public void tail(Node node, int depth) {
    String name = node.nodeName();
    if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
        append("\n");
    else if (name.equals("a"))
        append(String.format(" <%s>", node.absUrl("href")));
}
 
Example 4
boolean inSelectScope(String targetName) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element el = stack.get(pos);
        String elName = el.nodeName();
        if (elName.equals(targetName))
            return true;
        if (!StringUtil.in(elName, TagSearchSelectScope)) // all elements except
            return false;
    }
    Validate.fail("Should not be reachable");
    return false;
}
 
Example 5
private boolean inSpecificScope(String[] targetNames, String[] baseTypes, String[] extraTypes) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element el = stack.get(pos);
        String elName = el.nodeName();
        if (StringUtil.in(elName, targetNames))
            return true;
        if (StringUtil.in(elName, baseTypes))
            return false;
        if (extraTypes != null && StringUtil.in(elName, extraTypes))
            return false;
    }
    Validate.fail("Should not be reachable");
    return false;
}
 
Example 6
Source Project: xsoup   File: XTokenQueue.java    License: MIT License 5 votes vote down vote up
public static String trimQuotes(String str) {
    Validate.isTrue(str != null && str.length() > 0);
    String quote = str.substring(0, 1);
    if (StringUtil.in(quote, "\"", "'")) {
        Validate.isTrue(str.endsWith(quote), "Quote" + " for " + str + " is incomplete!");
        str = str.substring(1, str.length() - 1);
    }
    return str;
}
 
Example 7
private boolean inSpecificScope(String[] targetNames, String[] baseTypes, String[] extraTypes) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element el = stack.get(pos);
        String elName = el.nodeName();
        if (StringUtil.in(elName, targetNames))
            return true;
        if (StringUtil.in(elName, baseTypes))
            return false;
        if (extraTypes != null && StringUtil.in(elName, extraTypes))
            return false;
    }
    Validate.fail("Should not be reachable");
    return false;
}
 
Example 8
Source Project: jsoup-learning   File: HtmlTreeBuilder.java    License: MIT License 5 votes vote down vote up
boolean isSpecial(Element el) {
    // todo: mathml's mi, mo, mn
    // todo: svg's foreigObject, desc, title
    String name = el.nodeName();
    return StringUtil.in(name, "address", "applet", "area", "article", "aside", "base", "basefont", "bgsound",
            "blockquote", "body", "br", "button", "caption", "center", "col", "colgroup", "command", "dd",
            "details", "dir", "div", "dl", "dt", "embed", "fieldset", "figcaption", "figure", "footer", "form",
            "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html",
            "iframe", "img", "input", "isindex", "li", "link", "listing", "marquee", "menu", "meta", "nav",
            "noembed", "noframes", "noscript", "object", "ol", "p", "param", "plaintext", "pre", "script",
            "section", "select", "style", "summary", "table", "tbody", "td", "textarea", "tfoot", "th", "thead",
            "title", "tr", "ul", "wbr", "xmp");
}
 
Example 9
@Override
public void tail(Node node, int depth) {
	String name = node.nodeName();
	if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5")) {
		append("\n");
	} else if (StringUtil.in(name, "th", "td")) {
		append(" ");
	} else if (name.equals("a")) {
		append(String.format(" <%s>", node.absUrl("href")));
	} else if (name.equals("ul")) {
		listNesting--;
	}
}
 
Example 10
private void clearStackToContext(String... nodeNames) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element next = stack.get(pos);
        if (StringUtil.in(next.nodeName(), nodeNames) || next.nodeName().equals("html"))
            break;
        else
            stack.remove(pos);
    }
}
 
Example 11
public static String trimQuotes(String str) {
    Validate.isTrue(str != null && str.length() > 0);
    String quote = str.substring(0, 1);
    if (StringUtil.in(quote, "\"", "'")) {
        Validate.isTrue(str.endsWith(quote), "Quote" + " for " + str + " is incomplete!");
        str = str.substring(1, str.length() - 1);
    }
    return str;
}
 
Example 12
Source Project: echo   File: HtmlToPlainText.java    License: Apache License 2.0 5 votes vote down vote up
public void head(Node node, int depth) {
  String name = node.nodeName();
  if (node instanceof TextNode) {
    append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
  } else if (name.equals("li")) {
    append("\n * ");
  } else if (name.equals("dt")) {
    append("  ");
  } else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr")) {
    append("\n");
  }
}
 
Example 13
Source Project: echo   File: HtmlToPlainText.java    License: Apache License 2.0 5 votes vote down vote up
public void tail(Node node, int depth) {
  String name = node.nodeName();
  if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5")) {
    append("\n");
  } else if (name.equals("a")) {
    append(String.format(" <%s>", node.absUrl("href")));
  }
}
 
Example 14
private void append(String text) {
    if (text.startsWith("\n"))
        width = 0; // reset counter if starts with a newline. only from formats above, not in natural text
    if (text.equals(" ") &&
            (accum.length() == 0 || StringUtil.in(accum.substring(accum.length() - 1), " ", "\n")))
        return; // don't accumulate long runs of empty spaces

    if (text.length() + width > maxWidth) { // won't fit, needs to wrap
        String words[] = text.split("\\s+");
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            boolean last = i == words.length - 1;
            if (!last) // insert a space if not the last word
                word = word + " ";
            if (word.length() + width > maxWidth) { // wrap and reset counter
                accum.append("\n").append(word);
                width = word.length();
            } else {
                accum.append(word);
                width += word.length();
            }
        }
    } else { // fits as is, without need to wrap text
        accum.append(text);
        width += text.length();
    }
}
 
Example 15
void popStackToClose(String... elNames) {
    for (int pos = stack.size() -1; pos >= 0; pos--) {
        Element next = stack.get(pos);
        stack.remove(pos);
        if (StringUtil.in(next.nodeName(), elNames))
            break;
    }
}
 
Example 16
Source Project: jsoup-learning   File: HtmlTreeBuilder.java    License: MIT License 5 votes vote down vote up
private void clearStackToContext(String... nodeNames) {
    Iterator<Element> it = stack.descendingIterator();
    while (it.hasNext()) {
        Element next = it.next();
        if (StringUtil.in(next.nodeName(), nodeNames) || next.nodeName().equals("html"))
            break;
        else
            it.remove();
    }
}
 
Example 17
Source Project: jsoup-learning   File: HtmlTreeBuilder.java    License: MIT License 5 votes vote down vote up
void popStackToClose(String... elNames) {
    Iterator<Element> it = stack.descendingIterator();
    while (it.hasNext()) {
        Element next = it.next();
        if (StringUtil.in(next.nodeName(), elNames)) {
            it.remove();
            break;
        } else {
            it.remove();
        }
    }
}
 
Example 18
boolean isSpecial(Element el) {
    // todo: mathml's mi, mo, mn
    // todo: svg's foreigObject, desc, title
    String name = el.nodeName();
    return StringUtil.in(name, TagSearchSpecial);
}
 
Example 19
boolean isSpecial(Element el) {
    // todo: mathml's mi, mo, mn
    // todo: svg's foreigObject, desc, title
    String name = el.nodeName();
    return StringUtil.in(name, TagSearchSpecial);
}
 
Example 20
/**
 11.2.5.2 Closing elements that have implied end tags<p/>
 When the steps below require the UA to generate implied end tags, then, while the current node is a dd element, a
 dt element, an li element, an option element, an optgroup element, a p element, an rp element, or an rt element,
 the UA must pop the current node off the stack of open elements.

 @param excludeTag If a step requires the UA to generate implied end tags but lists an element to exclude from the
 process, then the UA must perform the above steps as if that element was not in the above list.
 */
void generateImpliedEndTags(String excludeTag) {
    while ((excludeTag != null && !currentElement().nodeName().equals(excludeTag)) &&
            StringUtil.in(currentElement().nodeName(), TagSearchEndTags))
        pop();
}