use of nu.validator.xml.AttributesImpl in project validator by validator.
the class MessageEmitterAdapter method listInputTypesForAttribute.
private void listInputTypesForAttribute(XhtmlSaxEmitter xhtmlSaxEmitter, String attributeName, boolean bad) throws SAXException {
String[] typeNames = validInputTypesByAttributeName.get(attributeName);
int typeCount = typeNames.length;
String wrapper = (bad ? "b" : "span");
String highlight = (bad ? " highlight" : "");
if (typeCount > 1 || "value".equals(attributeName)) {
addText(xhtmlSaxEmitter, " ");
AttributesImpl attributesImpl = new AttributesImpl();
attributesImpl.addAttribute("class", "inputattrtypes" + highlight);
xhtmlSaxEmitter.startElement(wrapper, attributesImpl);
addText(xhtmlSaxEmitter, "when ");
xhtmlSaxEmitter.startElement("code");
addText(xhtmlSaxEmitter, "type");
xhtmlSaxEmitter.endElement("code", "code");
addText(xhtmlSaxEmitter, " is ");
if ("value".equals(attributeName)) {
addText(xhtmlSaxEmitter, "not ");
addHyperlink(xhtmlSaxEmitter, "file", SPEC_LINK_URI + fragmentIdByInputType.get("file"));
addText(xhtmlSaxEmitter, " or ");
addHyperlink(xhtmlSaxEmitter, "image", SPEC_LINK_URI + fragmentIdByInputType.get("image"));
} else {
for (int i = 1; i < typeCount; i++) {
String typeName = typeNames[i];
if (i > 1) {
addText(xhtmlSaxEmitter, " ");
}
if (typeCount > 2 && i == typeCount - 1) {
addText(xhtmlSaxEmitter, "or ");
}
addHyperlink(xhtmlSaxEmitter, typeName, SPEC_LINK_URI + fragmentIdByInputType.get(typeName));
if (i < typeCount - 1 && typeCount > 3) {
addText(xhtmlSaxEmitter, ",");
}
}
}
xhtmlSaxEmitter.endElement(wrapper);
} else {
AttributesImpl attributesImpl = new AttributesImpl();
attributesImpl.addAttribute("class", "inputattrtypes");
xhtmlSaxEmitter.startElement("span", attributesImpl);
xhtmlSaxEmitter.endElement("span");
}
}
use of nu.validator.xml.AttributesImpl in project validator by validator.
the class Html5SpecBuilder method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if ("p" == localName && NS == uri) {
return;
}
switch(state) {
case AWAITING_HEADING:
if ("h4" == localName && NS == uri) {
referenceText.setLength(0);
currentId = atts.getValue("", "id");
currentName = null;
state = State.IN_H4;
}
break;
case IN_H4:
if ("code" == localName && NS == uri) {
nameText.setLength(0);
state = State.IN_CODE_IN_H4;
}
break;
case IN_CODE_IN_H4:
break;
case AWAITING_ELEMENT_DL:
if ("dl" == localName && NS == uri && "element".equals(atts.getValue("", "class"))) {
state = State.IN_ELEMENT_DL_START;
}
break;
case IN_ELEMENT_DL_START:
if ("dt" == localName && NS == uri) {
referenceText.setLength(0);
state = State.IN_CATEGORIES_DT;
} else {
throw new SAXParseException("Malformed spec: Expected dt in dl.", locator);
}
break;
case IN_CATEGORIES_DT:
if ("a" == localName && NS == uri) {
state = State.IN_CATEGORIES_DT;
break;
}
case IN_CONTEXT_DT:
if ("a" == localName && NS == uri) {
state = State.IN_CONTEXT_DT;
break;
}
case IN_CONTENT_MODEL_DT:
if ("a" == localName && NS == uri) {
state = State.IN_CONTENT_MODEL_DT;
break;
}
case IN_TAG_OMISSION_DT:
if ("a" == localName && NS == uri) {
state = State.IN_TAG_OMISSION_DT;
break;
}
case IN_ATTRIBUTES_DT:
if ("a" == localName && NS == uri) {
state = State.IN_ATTRIBUTES_DT;
break;
}
throw new SAXParseException("Malformed spec: Not expecting children in dts.", locator);
case CAPTURING_CATEGORIES_DDS:
case CAPTURING_CONTEXT_DDS:
case CAPTURING_CONTENT_MODEL_DDS:
case CAPTURING_TAG_OMISSION_DDS:
case CAPTURING_ATTRIBUTES_DDS:
if ("dt" == localName && NS == uri && captureDepth == 0) {
ignoreTextNodes = true;
DocumentFragment fragment = (DocumentFragment) fragmentBuilder.getRoot();
fragmentBuilder = null;
referenceText.setLength(0);
if (state == State.CAPTURING_CATEGORIES_DDS) {
categoriesByElement.put(currentName, fragment);
state = State.IN_CONTEXT_DT;
} else if (state == State.CAPTURING_CONTEXT_DDS) {
contextsByElement.put(currentName, fragment);
state = State.IN_CONTENT_MODEL_DT;
} else if (state == State.CAPTURING_CONTENT_MODEL_DDS) {
contentModelsByElement.put(currentName, fragment);
state = State.IN_TAG_OMISSION_DT;
} else if (state == State.CAPTURING_TAG_OMISSION_DDS) {
state = State.IN_ATTRIBUTES_DT;
} else {
attributesByElement.put(currentName, fragment);
state = State.AWAITING_HEADING;
}
} else {
captureDepth++;
String href = null;
if ("a" == localName && NS == uri && (href = atts.getValue("", "href")) != null) {
if (href.startsWith("#")) {
href = SPEC_LINK_URI + href;
}
AttributesImpl attributesImpl = new AttributesImpl();
attributesImpl.addAttribute("href", href);
fragmentBuilder.startElement(uri, localName, qName, attributesImpl);
} else {
fragmentBuilder.startElement(uri, localName, qName, EmptyAttributes.EMPTY_ATTRIBUTES);
}
}
break;
}
}
Aggregations