use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method inSpecificScope.
private boolean inSpecificScope(String[] targetNames, String[] baseTypes, String[] extraTypes) {
Iterator<Element> it = stack.descendingIterator();
while (it.hasNext()) {
Element el = it.next();
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;
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method insertEmpty.
Element insertEmpty(Token.StartTag startTag) {
Tag tag = Tag.valueOf(startTag.name());
Element el = new Element(tag, baseUri, startTag.attributes);
insertNode(el);
if (startTag.isSelfClosing()) {
if (tag.isKnownTag()) {
if (tag.isSelfClosing())
// if not acked,
tokeniser.acknowledgeSelfClosingFlag();
// promulagates
// error
} else {
// unknown tag, remember this is self closing for output
tag.setSelfClosing();
// not an distinct error
tokeniser.acknowledgeSelfClosingFlag();
}
}
return el;
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method parseFragment.
List<Node> parseFragment(String inputFragment, Element context, String baseUri, ParseErrorList errors) {
// context may be null
state = HtmlTreeBuilderState.Initial;
initialiseParse(inputFragment, baseUri, errors);
contextElement = context;
fragmentParsing = true;
Element root = null;
if (context != null) {
if (// quirks setup:
context.ownerDocument() != null)
doc.quirksMode(context.ownerDocument().quirksMode());
// initialise the tokeniser state:
String contextTag = context.tagName();
if (StringUtil.in(contextTag, "title", "textarea"))
tokeniser.transition(TokeniserState.Rcdata);
else if (StringUtil.in(contextTag, "iframe", "noembed", "noframes", "style", "xmp"))
tokeniser.transition(TokeniserState.Rawtext);
else if (contextTag.equals("script"))
tokeniser.transition(TokeniserState.ScriptData);
else if (contextTag.equals(("noscript")))
// if scripting
tokeniser.transition(TokeniserState.Data);
else // enabled, rawtext
if (contextTag.equals("plaintext"))
tokeniser.transition(TokeniserState.Data);
else
// default
tokeniser.transition(TokeniserState.Data);
root = new Element(Tag.valueOf("html"), baseUri);
doc.appendChild(root);
stack.push(root);
resetInsertionMode();
// setup form element to nearest form on context (up ancestor
// chain). ensures form controls are associated
// with form correctly
Elements contextChain = context.parents();
contextChain.add(0, context);
for (Element parent : contextChain) {
if (parent instanceof FormElement) {
formElement = (FormElement) parent;
break;
}
}
}
runParser();
if (context != null)
return root.childNodes();
else
return doc.childNodes();
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method reconstructFormattingElements.
void reconstructFormattingElements() {
int size = formattingElements.size();
if (size == 0 || formattingElements.getLast() == null || onStack(formattingElements.getLast()))
return;
Element entry = formattingElements.getLast();
int pos = size - 1;
boolean skip = false;
while (true) {
if (pos == 0) {
// step 4. if none before, skip to 8
skip = true;
break;
}
// step 5. one earlier than
entry = formattingElements.get(--pos);
// entry
if (// step 6 - neither marker nor
entry == null || onStack(entry))
// on stack
break;
// jump to 8, else continue back to 4
}
while (true) {
if (// step 7: on later than entry
!skip)
entry = formattingElements.get(++pos);
// should not occur, as we break at last
Validate.notNull(entry);
// element
// 8. create new element from element, 9 insert into current node,
// onto stack
// can only skip increment from 4.
skip = false;
// todo: avoid fostering
Element newEl = insert(entry.nodeName());
// here?
// newEl.namespace(entry.namespace()); // todo: namespaces
newEl.attributes().addAll(entry.attributes());
// 10. replace entry with new entry
formattingElements.add(pos, newEl);
formattingElements.remove(pos + 1);
// 11
if (// if not last entry in list, jump to 7
pos == size - 1)
break;
}
}
use of com.smartandroid.sa.tag.nodes.Element in project SmartAndroidSource by jaychou2012.
the class HtmlTreeBuilder method insert.
Element insert(String startTagName) {
Element el = new Element(Tag.valueOf(startTagName), baseUri);
insert(el);
return el;
}
Aggregations