use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method resetInsertionMode.
void resetInsertionMode() {
boolean last = false;
Iterator<Element> it = stack.descendingIterator();
while (it.hasNext()) {
Element node = it.next();
if (!it.hasNext()) {
last = true;
node = contextElement;
}
String name = node.nodeName();
if ("select".equals(name)) {
transition(HtmlTreeBuilderState.InSelect);
// frag
break;
} else if (("td".equals(name) || "td".equals(name) && !last)) {
transition(HtmlTreeBuilderState.InCell);
break;
} else if ("tr".equals(name)) {
transition(HtmlTreeBuilderState.InRow);
break;
} else if ("tbody".equals(name) || "thead".equals(name) || "tfoot".equals(name)) {
transition(HtmlTreeBuilderState.InTableBody);
break;
} else if ("caption".equals(name)) {
transition(HtmlTreeBuilderState.InCaption);
break;
} else if ("colgroup".equals(name)) {
transition(HtmlTreeBuilderState.InColumnGroup);
// frag
break;
} else if ("table".equals(name)) {
transition(HtmlTreeBuilderState.InTable);
break;
} else if ("head".equals(name)) {
transition(HtmlTreeBuilderState.InBody);
// frag
break;
} else if ("body".equals(name)) {
transition(HtmlTreeBuilderState.InBody);
break;
} else if ("frameset".equals(name)) {
transition(HtmlTreeBuilderState.InFrameset);
// frag
break;
} else if ("html".equals(name)) {
transition(HtmlTreeBuilderState.BeforeHead);
// frag
break;
} else if (last) {
transition(HtmlTreeBuilderState.InBody);
// frag
break;
}
}
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class Selector method select.
/**
* Find elements matching selector.
*
* @param query
* CSS selector
* @param roots
* root elements to descend into
* @return matching elements, empty if not
*/
public static Elements select(String query, Iterable<Element> roots) {
Validate.notEmpty(query);
Validate.notNull(roots);
LinkedHashSet<Element> elements = new LinkedHashSet<Element>();
for (Element root : roots) {
elements.addAll(select(query, root));
}
return new Elements(elements);
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class ListLinks method main.
public static void main(String[] args) throws IOException {
Validate.isTrue(args.length == 1, "usage: supply url to fetch");
String url = args[0];
print("Fetching %s...", url);
Document doc = SmartTag.connect(url).get();
Elements links = doc.select("a[href]");
Elements media = doc.select("[src]");
Elements imports = doc.select("link[href]");
print("\nMedia: (%d)", media.size());
for (Element src : media) {
if (src.tagName().equals("img"))
print(" * %s: <%s> %sx%s (%s)", src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"), trim(src.attr("alt"), 20));
else
print(" * %s: <%s>", src.tagName(), src.attr("abs:src"));
}
print("\nImports: (%d)", imports.size());
for (Element link : imports) {
print(" * %s <%s> (%s)", link.tagName(), link.attr("abs:href"), link.attr("rel"));
}
print("\nLinks: (%d)", links.size());
for (Element link : links) {
print(" * a: <%s> (%s)", link.attr("abs:href"), trim(link.text(), 35));
}
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method insert.
Element insert(Token.StartTag startTag) {
// won't generate this fake end tag.
if (startTag.isSelfClosing()) {
Element el = insertEmpty(startTag);
stack.add(el);
// handles <script />,
tokeniser.transition(TokeniserState.Data);
// otherwise needs
// breakout steps from
// script data
// ensure we get out
tokeniser.emit(new Token.EndTag(el.tagName()));
// processing
return el;
}
Element el = new Element(Tag.valueOf(startTag.name()), baseUri, startTag.attributes);
insert(el);
return el;
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method clearFormattingElementsToLastMarker.
void clearFormattingElementsToLastMarker() {
while (!formattingElements.isEmpty()) {
Element el = formattingElements.peekLast();
formattingElements.removeLast();
if (el == null)
break;
}
}
Aggregations