Search in sources :

Example 1 with SourceHandler

use of nu.validator.source.SourceHandler in project validator by validator.

the class MessageEmitterAdapter method messageWithExact.

private void messageWithExact(MessageType type, Exception message, String systemId, int oneBasedLine, int oneBasedColumn, int[] start) throws SAXException {
    if (start != null && !sourceCode.getIsCss()) {
        oneBasedColumn = oneBasedColumn + start[2];
    }
    systemId = batchMode ? systemId : null;
    startMessage(type, scrub(shortenDataUri(systemId)), oneBasedLine, oneBasedColumn, oneBasedLine, oneBasedColumn, true);
    messageText(message);
    Location location = sourceCode.newLocatorLocation(oneBasedLine, oneBasedColumn);
    if (sourceCode.isWithinKnownSource(location)) {
        SourceHandler sourceHandler = emitter.startSource();
        if (sourceHandler != null) {
            sourceCode.exactError(location, sourceHandler);
        }
        emitter.endSource();
    } else {
        sourceCode.rememberExactError(location);
    }
    elaboration(message);
    endMessage();
}
Also used : SourceHandler(nu.validator.source.SourceHandler) Location(nu.validator.source.Location)

Example 2 with SourceHandler

use of nu.validator.source.SourceHandler in project validator by validator.

the class MessageEmitterAdapter method messageWithRange.

private void messageWithRange(MessageType type, Exception message, String systemId, int oneBasedLine, int oneBasedColumn, int[] start) throws SAXException {
    if (start != null && !sourceCode.getIsCss()) {
        oneBasedColumn = oneBasedColumn + start[2];
    }
    systemId = batchMode ? systemId : null;
    Location rangeLast = sourceCode.newLocatorLocation(oneBasedLine, oneBasedColumn);
    if (!sourceCode.isWithinKnownSource(rangeLast)) {
        messageWithoutExtract(type, message, null, oneBasedLine, oneBasedColumn);
        return;
    }
    Location rangeStart = sourceCode.rangeStartForRangeLast(rangeLast);
    if (start != null) {
        if (sourceCode.getIsCss()) {
            rangeStart = sourceCode.newLocatorLocation(start[0], start[1]);
        } else {
            rangeStart = sourceCode.newLocatorLocation(start[0], start[1] + start[2]);
        }
    }
    startMessage(type, scrub(shortenDataUri(systemId)), rangeStart.getLine() + 1, rangeStart.getColumn() + 1, oneBasedLine, oneBasedColumn, false);
    messageText(message);
    SourceHandler sourceHandler = emitter.startSource();
    if (sourceHandler != null) {
        if (start != null) {
            sourceCode.addLocatorLocation(rangeStart.getLine() + 1, rangeStart.getColumn());
        }
        sourceCode.rangeEndError(rangeStart, rangeLast, sourceHandler);
    }
    emitter.endSource();
    elaboration(message);
    endMessage();
}
Also used : SourceHandler(nu.validator.source.SourceHandler) Location(nu.validator.source.Location)

Example 3 with SourceHandler

use of nu.validator.source.SourceHandler 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 4 with SourceHandler

use of nu.validator.source.SourceHandler in project validator by validator.

the class MessageEmitterAdapter method messageWithLine.

private void messageWithLine(MessageType type, Exception message, String systemId, int oneBasedLine) throws SAXException {
    systemId = batchMode ? systemId : null;
    if (!sourceCode.isWithinKnownSource(oneBasedLine)) {
        throw new RuntimeException("Bug. Line out of range!");
    }
    startMessage(type, scrub(shortenDataUri(systemId)), oneBasedLine, -1, oneBasedLine, -1, false);
    messageText(message);
    SourceHandler sourceHandler = emitter.startSource();
    if (sourceHandler != null) {
        sourceCode.lineError(oneBasedLine, sourceHandler);
    }
    emitter.endSource();
    elaboration(message);
    endMessage();
}
Also used : SourceHandler(nu.validator.source.SourceHandler)

Aggregations

SourceHandler (nu.validator.source.SourceHandler)4 Location (nu.validator.source.Location)2 DocumentFragment (nu.validator.saxtree.DocumentFragment)1