Search in sources :

Example 1 with TreeBuilder

use of nu.validator.saxtree.TreeBuilder in project validator by validator.

the class Html5SpecBuilder method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if ("p" == localName && NS == uri) {
        return;
    }
    switch(state) {
        case AWAITING_HEADING:
            break;
        case IN_H4:
            if ("h4" == localName && NS == uri) {
                Matcher m = ELEMENT.matcher(referenceText);
                if (m.matches()) {
                    String ln = nameText.toString().intern();
                    if ("" == ln) {
                        throw new SAXParseException("Malformed spec: no element" + currentName, locator);
                    }
                    if (currentId == null) {
                        state = State.AWAITING_HEADING;
                    // throw new SAXParseException(
                    // "Malformed spec: no element id.", locator);
                    }
                    state = State.AWAITING_ELEMENT_DL;
                } else {
                    currentId = null;
                    nameText.setLength(0);
                    state = State.AWAITING_HEADING;
                }
            }
            break;
        case IN_CODE_IN_H4:
            if ("code" == localName && NS == uri) {
                state = State.IN_H4;
            }
            break;
        case AWAITING_ELEMENT_DL:
            break;
        case IN_ELEMENT_DL_START:
            throw new SAXParseException("Malformed spec: no children in element dl.", locator);
        case IN_CATEGORIES_DT:
            if ("a" == localName && NS == uri) {
                Matcher m = CATEGORIES.matcher(referenceText);
                if (m.matches()) {
                    state = State.CAPTURING_CATEGORIES_DDS;
                    captureDepth = 0;
                    fragmentBuilder = new TreeBuilder(true, true);
                } else {
                    throw new SAXParseException("Malformed spec: Expected dt to be categories dt but it was not.", locator);
                }
            }
            break;
        case IN_CONTEXT_DT:
            if ("a" == localName && NS == uri) {
                Matcher m = CONTEXT.matcher(referenceText);
                if (m.matches()) {
                    state = State.CAPTURING_CONTEXT_DDS;
                    captureDepth = 0;
                    fragmentBuilder = new TreeBuilder(true, true);
                } else {
                    System.err.printf("Line: %d Col: %d\n", locator.getLineNumber(), locator.getColumnNumber());
                    throw new SAXParseException("Malformed spec at element " + currentName.getLocalName() + " (" + currentId + "): Expected dt to be context dt but it was not.", locator);
                }
            }
            break;
        case IN_CONTENT_MODEL_DT:
            if ("a" == localName && NS == uri) {
                Matcher m = CONTENT_MODEL.matcher(referenceText);
                if (m.matches()) {
                    state = State.CAPTURING_CONTENT_MODEL_DDS;
                    captureDepth = 0;
                    fragmentBuilder = new TreeBuilder(true, true);
                } else {
                    throw new SAXParseException("Malformed spec: Expected dt to be content-model dt but it was not.", locator);
                }
            }
            break;
        case IN_TAG_OMISSION_DT:
            if ("a" == localName && NS == uri) {
                Matcher m = TAG_OMISSION.matcher(referenceText);
                if (m.matches()) {
                    state = State.CAPTURING_TAG_OMISSION_DDS;
                    captureDepth = 0;
                    fragmentBuilder = new TreeBuilder(true, true);
                } else {
                    throw new SAXParseException("Malformed spec: Expected dt to be tag-omission dt but it was not.", locator);
                }
            }
            break;
        case IN_ATTRIBUTES_DT:
            if ("a" == localName && NS == uri) {
                Matcher m = ATTRIBUTES.matcher(referenceText);
                if (m.matches()) {
                    state = State.CAPTURING_ATTRIBUTES_DDS;
                    captureDepth = 0;
                    fragmentBuilder = new TreeBuilder(true, true);
                } else {
                    throw new SAXParseException("Malformed spec: Expected dt to be content-attributes dt but it was not.", locator);
                }
            }
            break;
        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) {
                break;
            }
            if (captureDepth == 0) {
                throw new SAXParseException("Malformed spec: Did not see following dt when capturing dds.", locator);
            }
            captureDepth--;
            fragmentBuilder.endElement(uri, localName, qName);
            break;
    }
}
Also used : Matcher(java.util.regex.Matcher) SAXParseException(org.xml.sax.SAXParseException) TreeBuilder(nu.validator.saxtree.TreeBuilder)

Example 2 with TreeBuilder

use of nu.validator.saxtree.TreeBuilder 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)

Example 3 with TreeBuilder

use of nu.validator.saxtree.TreeBuilder in project validator by validator.

the class ImageReportAdviceBuilder method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    switch(state) {
        case AWAITING_H2:
            return;
        case AWAITING_HEADLINE:
            if (depth == 0) {
                state = State.AWAITING_H2;
            } else {
                depth--;
            }
            return;
        case IN_HEADLINE:
            if (depth == 0) {
                state = State.AWAITING_H2_END;
            } else {
                depth--;
            }
            return;
        case AWAITING_H2_END:
            if (depth == 0) {
                treeBuilder = new TreeBuilder(true, true);
                state = State.IN_PROSE;
            } else {
                depth--;
            }
            return;
        case IN_PROSE:
            depth--;
            treeBuilder.endElement(uri, localName, qName);
            return;
    }
}
Also used : TreeBuilder(nu.validator.saxtree.TreeBuilder)

Aggregations

TreeBuilder (nu.validator.saxtree.TreeBuilder)3 Matcher (java.util.regex.Matcher)1 AbstractDatatype (nu.validator.datatype.AbstractDatatype)1 DatatypeException (org.relaxng.datatype.DatatypeException)1 SAXParseException (org.xml.sax.SAXParseException)1