Search in sources :

Example 1 with RubyClass

use of org.jruby.RubyClass in project nokogiri by sparklemotion.

the class XmlDomParserContext method parse.

/**
     * Must call setInputSource() before this method.
     */
public XmlDocument parse(ThreadContext context, IRubyObject klazz, IRubyObject url) {
    XmlDocument xmlDoc;
    try {
        Document doc = do_parse();
        xmlDoc = wrapDocument(context, (RubyClass) klazz, doc);
        xmlDoc.setUrl(url);
        addErrorsIfNecessary(context, xmlDoc);
        return xmlDoc;
    } catch (SAXException e) {
        return getDocumentWithErrorsOrRaiseException(context, (RubyClass) klazz, e);
    } catch (IOException e) {
        return getDocumentWithErrorsOrRaiseException(context, (RubyClass) klazz, e);
    }
}
Also used : XmlDocument(nokogiri.XmlDocument) RubyClass(org.jruby.RubyClass) IOException(java.io.IOException) Document(org.w3c.dom.Document) XmlDocument(nokogiri.XmlDocument) SAXException(org.xml.sax.SAXException)

Example 2 with RubyClass

use of org.jruby.RubyClass in project nokogiri by sparklemotion.

the class NokogiriService method createSaxModule.

private void createSaxModule(Ruby ruby, RubyModule xmlSaxModule, RubyModule htmlSaxModule) {
    RubyClass xmlSaxParserContext = xmlSaxModule.defineClassUnder("ParserContext", ruby.getObject(), XML_SAXPARSER_CONTEXT_ALLOCATOR);
    xmlSaxParserContext.defineAnnotatedMethods(XmlSaxParserContext.class);
    RubyClass xmlSaxPushParser = xmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), XML_SAXPUSHPARSER_ALLOCATOR);
    xmlSaxPushParser.defineAnnotatedMethods(XmlSaxPushParser.class);
    RubyClass htmlSaxPushParser = htmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), HTML_SAXPUSHPARSER_ALLOCATOR);
    htmlSaxPushParser.defineAnnotatedMethods(HtmlSaxPushParser.class);
    RubyClass htmlSaxParserContext = htmlSaxModule.defineClassUnder("ParserContext", xmlSaxParserContext, HTML_SAXPARSER_CONTEXT_ALLOCATOR);
    htmlSaxParserContext.defineAnnotatedMethods(HtmlSaxParserContext.class);
}
Also used : RubyClass(org.jruby.RubyClass)

Example 3 with RubyClass

use of org.jruby.RubyClass in project nokogiri by sparklemotion.

the class NokogiriService method init.

private void init(Ruby ruby) {
    RubyModule nokogiri = ruby.defineModule("Nokogiri");
    RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
    RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
    RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
    RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
    RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");
    createJavaLibraryVersionConstants(ruby, nokogiri);
    createNokogiriModule(ruby, nokogiri);
    createSyntaxErrors(ruby, nokogiri, xmlModule);
    RubyClass xmlNode = createXmlModule(ruby, xmlModule);
    createHtmlModule(ruby, htmlModule);
    createDocuments(ruby, xmlModule, htmlModule, xmlNode);
    createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
    createXsltModule(ruby, xsltModule);
    nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
}
Also used : RubyModule(org.jruby.RubyModule) RubyClass(org.jruby.RubyClass)

Example 4 with RubyClass

use of org.jruby.RubyClass in project nokogiri by sparklemotion.

the class NokogiriService method createXsltModule.

private void createXsltModule(Ruby ruby, RubyModule xsltModule) {
    RubyClass stylesheet = xsltModule.defineClassUnder("Stylesheet", ruby.getObject(), XSLT_STYLESHEET_ALLOCATOR);
    stylesheet.defineAnnotatedMethods(XsltStylesheet.class);
    xsltModule.defineAnnotatedMethod(XsltStylesheet.class, "register");
}
Also used : RubyClass(org.jruby.RubyClass)

Example 5 with RubyClass

use of org.jruby.RubyClass in project nokogiri by sparklemotion.

the class NokogiriService method createSyntaxErrors.

private void createSyntaxErrors(Ruby ruby, RubyModule nokogiri, RubyModule xmlModule) {
    RubyClass syntaxError = nokogiri.defineClassUnder("SyntaxError", ruby.getStandardError(), ruby.getStandardError().getAllocator());
    RubyClass xmlSyntaxError = xmlModule.defineClassUnder("SyntaxError", syntaxError, XML_SYNTAXERROR_ALLOCATOR);
    xmlSyntaxError.defineAnnotatedMethods(XmlSyntaxError.class);
}
Also used : RubyClass(org.jruby.RubyClass)

Aggregations

RubyClass (org.jruby.RubyClass)29 JRubyClass (org.jruby.anno.JRubyClass)9 RubyModule (org.jruby.RubyModule)8 JRubyMethod (org.jruby.anno.JRubyMethod)7 Ruby (org.jruby.Ruby)4 Document (org.w3c.dom.Document)4 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)3 RubyString (org.jruby.RubyString)3 IOException (java.io.IOException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 XmlDocument (nokogiri.XmlDocument)2 RubyArray (org.jruby.RubyArray)2 IRubyObject (org.jruby.runtime.builtin.IRubyObject)2 SAXException (org.xml.sax.SAXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Finalizable (org.jruby.Finalizable)1 RaiseException (org.jruby.exceptions.RaiseException)1