Search in sources :

Example 6 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project nokogiri by sparklemotion.

the class XmlDomParserContext method mapErrors.

public static RubyArray mapErrors(ThreadContext context, NokogiriErrorHandler errorHandler) {
    final Ruby runtime = context.runtime;
    final List<Exception> errors = errorHandler.getErrors();
    final IRubyObject[] errorsAry = new IRubyObject[errors.size()];
    for (int i = 0; i < errors.size(); i++) {
        XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(runtime);
        xmlSyntaxError.setException(errors.get(i));
        errorsAry[i] = xmlSyntaxError;
    }
    return runtime.newArrayNoCopy(errorsAry);
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) RaiseException(org.jruby.exceptions.RaiseException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 7 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project nokogiri by sparklemotion.

the class XmlDomParserContext method getDocumentWithErrorsOrRaiseException.

public XmlDocument getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex) {
    if (options.recover) {
        XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
        this.addErrorsIfNecessary(context, xmlDocument);
        XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
        xmlSyntaxError.setException(ex);
        ((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
        return xmlDocument;
    } else {
        XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
        xmlSyntaxError.setException(ex);
        throw xmlSyntaxError.toThrowable();
    }
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError) XmlDocument(nokogiri.XmlDocument)

Aggregations

XmlSyntaxError (nokogiri.XmlSyntaxError)7 XmlDocument (nokogiri.XmlDocument)3 Ruby (org.jruby.Ruby)2 RaiseException (org.jruby.exceptions.RaiseException)2 IRubyObject (org.jruby.runtime.builtin.IRubyObject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XNIException (org.apache.xerces.xni.XNIException)1 RubyArray (org.jruby.RubyArray)1 SAXException (org.xml.sax.SAXException)1