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

The following examples show how to use org.jsoup.helper.StringUtil#join() . 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
Source Project: astor   File: Element.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a CSS selector that will uniquely select this element.
 * <p>
 * If the element has an ID, returns #id;
 * otherwise returns the parent (if any) CSS selector, followed by {@literal '>'},
 * followed by a unique selector for the element (tag.class.class:nth-child(n)).
 * </p>
 *
 * @return the CSS Path that can be used to retrieve the element in a selector.
 */
public String cssSelector() {
    if (id().length() > 0)
        return "#" + id();

    // Translate HTML namespace ns:tag to CSS namespace syntax ns|tag
    String tagName = tagName().replace(':', '|');
    StringBuilder selector = new StringBuilder(tagName);
    String classes = StringUtil.join(classNames(), ".");
    if (classes.length() > 0)
        selector.append('.').append(classes);

    if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node
        return selector.toString();

    selector.insert(0, " > ");
    if (parent().select(selector.toString()).size() > 1)
        selector.append(String.format(
            ":nth-child(%d)", elementSiblingIndex() + 1));

    return parent().cssSelector() + selector.toString();
}
 
Example 2
Source Project: astor   File: Element.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a CSS selector that will uniquely select this element.
 * <p>
 * If the element has an ID, returns #id;
 * otherwise returns the parent (if any) CSS selector, followed by {@literal '>'},
 * followed by a unique selector for the element (tag.class.class:nth-child(n)).
 * </p>
 *
 * @return the CSS Path that can be used to retrieve the element in a selector.
 */
public String cssSelector() {
    if (id().length() > 0)
        return "#" + id();

    // Translate HTML namespace ns:tag to CSS namespace syntax ns|tag
    String tagName = tagName().replace(':', '|');
    StringBuilder selector = new StringBuilder(tagName);
    String classes = StringUtil.join(classNames(), ".");
    if (classes.length() > 0)
        selector.append('.').append(classes);

    if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node
        return selector.toString();

    selector.insert(0, " > ");
    if (parent().select(selector.toString()).size() > 1)
        selector.append(String.format(
            ":nth-child(%d)", elementSiblingIndex() + 1));

    return parent().cssSelector() + selector.toString();
}
 
Example 3
Source Project: astor   File: Element.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a CSS selector that will uniquely select this element.
 * <p>
 * If the element has an ID, returns #id;
 * otherwise returns the parent (if any) CSS selector, followed by {@literal '>'},
 * followed by a unique selector for the element (tag.class.class:nth-child(n)).
 * </p>
 *
 * @return the CSS Path that can be used to retrieve the element in a selector.
 */
public String cssSelector() {
    if (id().length() > 0)
        return "#" + id();

    // Translate HTML namespace ns:tag to CSS namespace syntax ns|tag
    String tagName = tagName().replace(':', '|');
    StringBuilder selector = new StringBuilder(tagName);
    String classes = StringUtil.join(classNames(), ".");
    if (classes.length() > 0)
        selector.append('.').append(classes);

    if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node
        return selector.toString();

    selector.insert(0, " > ");
    if (parent().select(selector.toString()).size() > 1)
        selector.append(String.format(
            ":nth-child(%d)", elementSiblingIndex() + 1));

    return parent().cssSelector() + selector.toString();
}
 
Example 4
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}
 
Example 5
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}
 
Example 6
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}
 
Example 7
@Override
public String toString() {
    return StringUtil.join(evaluators, ", ");
}
 
Example 8
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}
 
Example 9
@Override
public String toString() {
    return StringUtil.join(evaluators, ", ");
}
 
Example 10
Source Project: jsoup-learning   File: CombiningEvaluator.java    License: MIT License 4 votes vote down vote up
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}
 
Example 11
Source Project: xsoup   File: CombiningEvaluator.java    License: MIT License 4 votes vote down vote up
@Override
public String toString() {
    return StringUtil.join(evaluators, " ");
}