Search in sources :

Example 11 with DatatypeException

use of org.relaxng.datatype.DatatypeException in project validator by validator.

the class MessageEmitterAdapter method vnuElementNameMessageText.

private void vnuElementNameMessageText(VnuBadElementNameException e) throws SAXException {
    MessageTextHandler messageTextHandler = emitter.startText();
    if (messageTextHandler != null) {
        boolean isWarning = false;
        Map<String, DatatypeException> datatypeErrors = e.getExceptions();
        for (Map.Entry<String, DatatypeException> entry : datatypeErrors.entrySet()) {
            DatatypeException dex = entry.getValue();
            if (dex instanceof Html5DatatypeException) {
                Html5DatatypeException ex5 = (Html5DatatypeException) dex;
                if (ex5.isWarning()) {
                    isWarning = true;
                }
            }
        }
        if (isWarning) {
            messageTextString(messageTextHandler, POTENTIALLY_BAD_ELEMENT_NAME, false);
        } else {
            messageTextString(messageTextHandler, BAD_ELEMENT_NAME, false);
        }
        messageTextString(messageTextHandler, SPACE, false);
        codeString(messageTextHandler, e.getElementName());
        emitDatatypeErrors(messageTextHandler, e.getExceptions());
    }
    emitter.endText();
}
Also used : Html5DatatypeException(nu.validator.datatype.Html5DatatypeException) DatatypeException(org.relaxng.datatype.DatatypeException) Html5DatatypeException(nu.validator.datatype.Html5DatatypeException) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 12 with DatatypeException

use of org.relaxng.datatype.DatatypeException 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 13 with DatatypeException

use of org.relaxng.datatype.DatatypeException in project validator by validator.

the class BaseUriTracker method push.

private void push(String relative, String language, Direction dir) {
    String lang = "";
    boolean langSpecified = false;
    if (language != null) {
        try {
            if (!"".equals(language)) {
                Language.THE_INSTANCE.checkValid(language);
            }
            lang = language;
            langSpecified = true;
        } catch (DatatypeException e) {
        }
    }
    Node curr = peek();
    URL base = curr.currentAbsolute;
    if (!langSpecified) {
        lang = curr.lang;
    }
    boolean rtl;
    switch(dir) {
        case RTL:
            rtl = true;
            break;
        case LTR:
            rtl = false;
            break;
        default:
            rtl = curr.rtl;
            break;
    }
    if (relative == null) {
        stack.addLast(new Node(base, null, lang, langSpecified, rtl));
    } else {
        URL newBase;
        String ascii = null;
        try {
            if (base != null) {
                try {
                    newBase = base.resolve(relative);
                } catch (GalimatiasParseException e) {
                    newBase = base;
                }
            } else {
                try {
                    newBase = URL.parse((new URI(ascii)).toString());
                } catch (GalimatiasParseException e) {
                    newBase = null;
                }
            }
        } catch (Exception e) {
            newBase = base;
        }
        stack.addLast(new Node(newBase, ascii, lang, langSpecified, rtl));
    }
}
Also used : DatatypeException(org.relaxng.datatype.DatatypeException) GalimatiasParseException(io.mola.galimatias.GalimatiasParseException) URI(java.net.URI) URL(io.mola.galimatias.URL) SAXException(org.xml.sax.SAXException) GalimatiasParseException(io.mola.galimatias.GalimatiasParseException) DatatypeException(org.relaxng.datatype.DatatypeException)

Aggregations

DatatypeException (org.relaxng.datatype.DatatypeException)13 Html5DatatypeException (nu.validator.datatype.Html5DatatypeException)11 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeMap (java.util.TreeMap)7 BadAttributeValueException (com.thaiopensource.relaxng.exceptions.BadAttributeValueException)3 VnuBadAttrValueException (nu.validator.checker.VnuBadAttrValueException)3 VnuBadElementNameException (nu.validator.checker.VnuBadElementNameException)3 ImpossibleAttributeIgnoredException (com.thaiopensource.relaxng.exceptions.ImpossibleAttributeIgnoredException)2 OnlyTextNotAllowedException (com.thaiopensource.relaxng.exceptions.OnlyTextNotAllowedException)2 OutOfContextElementException (com.thaiopensource.relaxng.exceptions.OutOfContextElementException)2 RequiredAttributesMissingException (com.thaiopensource.relaxng.exceptions.RequiredAttributesMissingException)2 RequiredAttributesMissingOneOfException (com.thaiopensource.relaxng.exceptions.RequiredAttributesMissingOneOfException)2 RequiredElementsMissingException (com.thaiopensource.relaxng.exceptions.RequiredElementsMissingException)2 RequiredElementsMissingOneOfException (com.thaiopensource.relaxng.exceptions.RequiredElementsMissingOneOfException)2 StringNotAllowedException (com.thaiopensource.relaxng.exceptions.StringNotAllowedException)2 TextNotAllowedException (com.thaiopensource.relaxng.exceptions.TextNotAllowedException)2 UnfinishedElementException (com.thaiopensource.relaxng.exceptions.UnfinishedElementException)2 UnfinishedElementOneOfException (com.thaiopensource.relaxng.exceptions.UnfinishedElementOneOfException)2 UnknownElementException (com.thaiopensource.relaxng.exceptions.UnknownElementException)2