use of nu.validator.saxtree.DocumentFragment in project validator by validator.
the class MessageEmitterAdapter method elaborateDatatypes.
private void elaborateDatatypes(Map<String, DatatypeException> map) throws SAXException {
Set<DocumentFragment> fragments = new HashSet<>();
for (Map.Entry<String, DatatypeException> entry : map.entrySet()) {
DatatypeException ex = entry.getValue();
if (ex instanceof Html5DatatypeException) {
Html5DatatypeException ex5 = (Html5DatatypeException) ex;
DocumentFragment fragment = HTML5_DATATYPE_ADVICE.get(ex5.getDatatypeClass());
if (fragment != null) {
fragments.add(fragment);
}
}
}
if (!fragments.isEmpty()) {
ContentHandler ch = emitter.startElaboration();
if (ch != null) {
TreeParser treeParser = new TreeParser(ch, null);
XhtmlSaxEmitter xhtmlSaxEmitter = new XhtmlSaxEmitter(ch);
xhtmlSaxEmitter.startElement("dl");
for (DocumentFragment fragment : fragments) {
treeParser.parse(fragment);
}
xhtmlSaxEmitter.endElement("dl");
}
emitter.endElaboration();
}
}
use of nu.validator.saxtree.DocumentFragment 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