Search in sources :

Example 1 with AbstractDatatype

use of nu.validator.datatype.AbstractDatatype in project validator by validator.

the class Html5AttributeDatatypeBuilder method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    switch(state) {
        case AWAITING_WIKI_BODY:
        case AWAITING_H3:
            return;
        case IN_HEADLINE:
            if (depth == 0) {
                try {
                    String name = stringBuilder.toString();
                    AbstractDatatype datatype = (AbstractDatatype) datatypeLibrary.createDatatype(name);
                    currentClass = datatype.getClass();
                    treeBuilder = new TreeBuilder(true, true);
                    treeBuilder.startElement(NS, "dt", "dt", EmptyAttributes.EMPTY_ATTRIBUTES);
                    String dt = "Syntax of " + datatype.getName() + ":";
                    treeBuilder.characters(dt.toCharArray(), 0, dt.length());
                    treeBuilder.endElement(NS, "dt", "dt");
                    state = State.AWAITING_P;
                } catch (DatatypeException e) {
                    System.out.println(String.format("Warning: No datatype class for \"%s\".", stringBuilder.toString().trim()));
                    state = State.AWAITING_H3;
                }
            } else {
                depth--;
            }
            return;
        case AWAITING_P:
            // should be impossible
            state = State.AWAITING_H3;
            return;
        case IN_P:
            if (depth == 0) {
                treeBuilder.endElement(NS, "dt", "dt");
                adviceByClass.put(currentClass, (DocumentFragment) treeBuilder.getRoot());
                state = State.AWAITING_H3;
            } else {
                depth--;
                treeBuilder.endElement(uri, localName, qName);
            }
            return;
    }
}
Also used : DatatypeException(org.relaxng.datatype.DatatypeException) AbstractDatatype(nu.validator.datatype.AbstractDatatype) TreeBuilder(nu.validator.saxtree.TreeBuilder)

Aggregations

AbstractDatatype (nu.validator.datatype.AbstractDatatype)1 TreeBuilder (nu.validator.saxtree.TreeBuilder)1 DatatypeException (org.relaxng.datatype.DatatypeException)1