Search in sources :

Example 1 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project gocd by gocd.

the class NokogiriErrorHandler method getErrorsReadyForRuby.

public List<IRubyObject> getErrorsReadyForRuby(ThreadContext context) {
    Ruby runtime = context.getRuntime();
    List<IRubyObject> res = new ArrayList<IRubyObject>();
    for (int i = 0; i < errors.size(); i++) {
        XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
        xmlSyntaxError.setException(errors.get(i));
        res.add(xmlSyntaxError);
    }
    return res;
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError) ArrayList(java.util.ArrayList) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Example 2 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project gocd by gocd.

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) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
        xmlSyntaxError.setException(ex);
        ((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
        return xmlDocument;
    } else {
        XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
        xmlSyntaxError.setException(ex);
        throw new RaiseException(xmlSyntaxError);
    }
}
Also used : RubyArray(org.jruby.RubyArray) XmlSyntaxError(nokogiri.XmlSyntaxError) RaiseException(org.jruby.exceptions.RaiseException) XmlDocument(nokogiri.XmlDocument)

Example 3 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project nokogiri by sparklemotion.

the class HtmlDomParserContext method parse.

@Override
public XmlDocument parse(ThreadContext context, RubyClass klass, IRubyObject url) {
    XmlDocument xmlDoc = super.parse(context, klass, url);
    // https://github.com/sparklemotion/nokogiri/issues/2130
    if (!options.recover && errorHandler.getErrors().size() > 0) {
        XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
        String exceptionMsg = String.format("%s: '%s'", "Parser without recover option encountered error or warning", errorHandler.getErrors().get(0));
        xmlSyntaxError.setException(new Exception(exceptionMsg));
        throw xmlSyntaxError.toThrowable();
    }
    return xmlDoc;
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError) XmlDocument(nokogiri.XmlDocument) XNIException(org.apache.xerces.xni.XNIException)

Example 4 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project gocd by gocd.

the class SchemaErrorHandler method warning.

public void warning(SAXParseException ex) throws SAXException {
    XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
    xmlSyntaxError.setException(ex);
    this.errors.append(xmlSyntaxError);
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError)

Example 5 with XmlSyntaxError

use of nokogiri.XmlSyntaxError in project gocd by gocd.

the class SchemaErrorHandler method error.

public void error(SAXParseException ex) throws SAXException {
    XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
    xmlSyntaxError.setException(ex);
    this.errors.append(xmlSyntaxError);
}
Also used : XmlSyntaxError(nokogiri.XmlSyntaxError)

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