Search in sources :

Example 1 with DocumentFragment

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

the class MessageEmitterAdapter method end.

public void end(String successMessage, String failureMessage, String language) throws SAXException {
    ResultHandler resultHandler = emitter.startResult();
    if (resultHandler != null) {
        if (isIndeterminate()) {
            resultHandler.startResult(Result.INDETERMINATE);
            resultHandler.characters(INDETERMINATE_MESSAGE, 0, INDETERMINATE_MESSAGE.length);
            resultHandler.endResult();
        } else if (isErrors()) {
            resultHandler.startResult(Result.FAILURE);
            resultHandler.characters(failureMessage.toCharArray(), 0, failureMessage.length());
            resultHandler.endResult();
        } else {
            resultHandler.startResult(Result.SUCCESS);
            resultHandler.characters(successMessage.toCharArray(), 0, successMessage.length());
            resultHandler.endResult();
        }
    }
    emitter.endResult();
    if (imageCollector != null) {
        DocumentFragment instruction = IMAGE_REPORT_GENERAL;
        boolean fatal = false;
        if (getFatalErrors() > 0) {
            fatal = true;
            instruction = IMAGE_REPORT_FATAL;
        } else if (imageCollector.isEmpty()) {
            instruction = IMAGE_REPORT_EMPTY;
        }
        ImageReviewHandler imageReviewHandler = emitter.startImageReview(instruction, fatal);
        if (imageReviewHandler != null && !fatal) {
            emitImageReview(imageReviewHandler);
        }
        emitter.endImageReview();
    }
    if (showSource) {
        SourceHandler sourceHandler = emitter.startFullSource(lineOffset);
        if (sourceHandler != null) {
            sourceCode.emitSource(sourceHandler);
        }
        emitter.endFullSource();
    }
    emitter.endMessages(language);
}
Also used : SourceHandler(nu.validator.source.SourceHandler) DocumentFragment(nu.validator.saxtree.DocumentFragment)

Example 2 with DocumentFragment

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

the class MessageEmitterAdapter method elaborateContentModelandContext.

private void elaborateContentModelandContext(Name parent, Name child) throws SAXException {
    DocumentFragment contentModelDds = spec.contentModelDescription(parent);
    DocumentFragment contextDds = spec.contextDescription(child);
    if (contentModelDds != null || contextDds != null) {
        ContentHandler ch = emitter.startElaboration();
        if (ch != null) {
            TreeParser treeParser = new TreeParser(ch, null);
            XhtmlSaxEmitter xhtmlSaxEmitter = new XhtmlSaxEmitter(ch);
            xhtmlSaxEmitter.startElement("dl");
            if (contextDds != null) {
                emitContextDt(xhtmlSaxEmitter, child);
                treeParser.parse(contextDds);
            }
            if (contentModelDds != null) {
                emitContentModelDt(xhtmlSaxEmitter, parent);
                treeParser.parse(contentModelDds);
            }
            xhtmlSaxEmitter.endElement("dl");
        }
        emitter.endElaboration();
    }
}
Also used : TreeParser(nu.validator.saxtree.TreeParser) XhtmlSaxEmitter(nu.validator.xml.XhtmlSaxEmitter) DocumentFragment(nu.validator.saxtree.DocumentFragment) ContentHandler(org.xml.sax.ContentHandler)

Example 3 with DocumentFragment

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

the class ImageReportAdviceBuilder method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    switch(state) {
        case AWAITING_H2:
            if ("h2" == localName && NS == uri) {
                depth = 0;
                state = State.AWAITING_HEADLINE;
            }
            return;
        case AWAITING_HEADLINE:
            if (depth == 0 && "span" == localName && NS == uri && "mw-headline".equals(atts.getValue("", "class"))) {
                state = State.IN_HEADLINE;
            } else {
                depth++;
            }
            return;
        case IN_HEADLINE:
            depth++;
            return;
        case AWAITING_H2_END:
            depth++;
            return;
        case IN_PROSE:
            String href = null;
            if (NS == uri && "a" == localName) {
                if ((href = atts.getValue("", "href")) != null) {
                    AttributesImpl ai = new AttributesImpl();
                    ai.addAttribute("href", href);
                    depth++;
                    treeBuilder.startElement(uri, localName, qName, ai);
                }
            } else if (NS == uri && "div" == localName && ("printfooter".equals(atts.getValue("", "class")))) {
                fragments.add((DocumentFragment) treeBuilder.getRoot());
                treeBuilder = null;
                state = State.AWAITING_H2;
            } else if (depth == 0 && "h2" == localName && NS == uri) {
                fragments.add((DocumentFragment) treeBuilder.getRoot());
                treeBuilder = null;
                depth = 0;
                state = State.AWAITING_HEADLINE;
            } else {
                depth++;
                treeBuilder.startElement(uri, localName, qName, EmptyAttributes.EMPTY_ATTRIBUTES);
            }
    }
}
Also used : AttributesImpl(nu.validator.xml.AttributesImpl) DocumentFragment(nu.validator.saxtree.DocumentFragment)

Example 4 with DocumentFragment

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

the class MessageEmitterAdapter method elaborateElementSpecificAttributes.

private void elaborateElementSpecificAttributes(Name elt, Name attribute) throws SAXException {
    if ("input".equals(elt.getLocalName())) {
        ContentHandler ch = emitter.startElaboration();
        if (ch != null) {
            XhtmlSaxEmitter xhtmlSaxEmitter = new XhtmlSaxEmitter(ch);
            elaborateInputAttributes(xhtmlSaxEmitter, elt, attribute);
        }
        emitter.endElaboration();
    } else {
        DocumentFragment dds = spec.elementSpecificAttributesDescription(elt);
        if (dds != null) {
            ContentHandler ch = emitter.startElaboration();
            if (ch != null) {
                TreeParser treeParser = new TreeParser(ch, null);
                XhtmlSaxEmitter xhtmlSaxEmitter = new XhtmlSaxEmitter(ch);
                xhtmlSaxEmitter.startElement("dl");
                emitElementSpecificAttributesDt(xhtmlSaxEmitter, elt);
                treeParser.parse(dds);
                xhtmlSaxEmitter.endElement("dl");
            }
            emitter.endElaboration();
        }
    }
}
Also used : TreeParser(nu.validator.saxtree.TreeParser) XhtmlSaxEmitter(nu.validator.xml.XhtmlSaxEmitter) ContentHandler(org.xml.sax.ContentHandler) DocumentFragment(nu.validator.saxtree.DocumentFragment)

Example 5 with DocumentFragment

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

the class MessageEmitterAdapter method elaborateContentModel.

/**
 * @param elt
 * @throws SAXException
 */
private void elaborateContentModel(Name elt) throws SAXException {
    DocumentFragment dds = spec.contentModelDescription(elt);
    if (dds != null) {
        ContentHandler ch = emitter.startElaboration();
        if (ch != null) {
            TreeParser treeParser = new TreeParser(ch, null);
            XhtmlSaxEmitter xhtmlSaxEmitter = new XhtmlSaxEmitter(ch);
            xhtmlSaxEmitter.startElement("dl");
            emitContentModelDt(xhtmlSaxEmitter, elt);
            treeParser.parse(dds);
            xhtmlSaxEmitter.endElement("dl");
        }
        emitter.endElaboration();
    }
}
Also used : TreeParser(nu.validator.saxtree.TreeParser) XhtmlSaxEmitter(nu.validator.xml.XhtmlSaxEmitter) DocumentFragment(nu.validator.saxtree.DocumentFragment) ContentHandler(org.xml.sax.ContentHandler)

Aggregations

DocumentFragment (nu.validator.saxtree.DocumentFragment)7 TreeParser (nu.validator.saxtree.TreeParser)4 XhtmlSaxEmitter (nu.validator.xml.XhtmlSaxEmitter)4 ContentHandler (org.xml.sax.ContentHandler)4 AttributesImpl (nu.validator.xml.AttributesImpl)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Html5DatatypeException (nu.validator.datatype.Html5DatatypeException)1 SourceHandler (nu.validator.source.SourceHandler)1 DatatypeException (org.relaxng.datatype.DatatypeException)1 SAXParseException (org.xml.sax.SAXParseException)1