boolean isEndTag = CajaTreeBuilder.isEndTag(start.text);
String tagName = start.text.substring(isEndTag ? 2 : 1);
boolean isHtml = checkName(tagName);
if (isHtml) { tagName = Strings.lower(tagName); }
HtmlAttributes htmlAttrs = new HtmlAttributes(AttributeName.HTML);
boolean hasXmlns = false;
List<Attr> attrs = Lists.newArrayList();
if (!attrStubs.isEmpty()) {
for (AttrStub as : attrStubs) {
String qname = as.nameTok.text;
Attr attrNode;
boolean isAttrHtml;
try {
String name;
if ("xmlns".equals(qname)) {
if (!Namespaces.HTML_NAMESPACE_URI.equals(as.value)) {
// We do not allow overriding of the default namespace when
// parsing HTML.
mq.addMessage(
MessageType.CANNOT_OVERRIDE_DEFAULT_NAMESPACE_IN_HTML,
as.nameTok.pos);
} else {
hasXmlns = true;
}
continue;
} else {
isAttrHtml = isHtml && checkName(qname);
if (isAttrHtml) {
name = Strings.lower(qname);
attrNode = maybeCreateAttributeNs(Namespaces.HTML_NAMESPACE_URI,
name, as);
if (attrNode == null) {
// Ignore this attribute.
continue;
}
} else {
name = AttributeNameFixup.fixupNameFromQname(qname);
attrNode = maybeCreateAttribute(name, as);
if (attrNode == null) {
// Ignore this attribute.
continue;
}
}
}
attrNode.setValue(as.value);
if (needsDebugData) {
Nodes.setFilePositionFor(attrNode, as.nameTok.pos);
Nodes.setFilePositionForValue(attrNode, as.valueTok.pos);
Nodes.setRawValue(attrNode, as.valueTok.text);
}
attrs.add(attrNode);
try {
htmlAttrs.addAttribute(
AttributeName.nameByString(name),
as.value, XmlViolationPolicy.ALLOW);
} catch (SAXException ex) {
if (CajaTreeBuilder.DEBUG) { ex.printStackTrace(); }
}