Search in sources :

Example 16 with RubyClass

use of org.jruby.RubyClass in project gocd by gocd.

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 17 with RubyClass

use of org.jruby.RubyClass in project gocd by gocd.

the class NokogiriService method createHtmlModule.

private void createHtmlModule(Ruby ruby, RubyModule htmlModule) {
    RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(), HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
    htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
    RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(), HTML_ENTITY_LOOKUP_ALLOCATOR);
    htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
}
Also used : RubyClass(org.jruby.RubyClass)

Example 18 with RubyClass

use of org.jruby.RubyClass in project gocd by gocd.

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 19 with RubyClass

use of org.jruby.RubyClass in project gocd by gocd.

the class HtmlSaxParserContext method parse_io.

@JRubyMethod(name = "io", meta = true)
public static IRubyObject parse_io(ThreadContext context, IRubyObject klazz, IRubyObject data, IRubyObject encoding) {
    HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
    ctx.initialize(context.getRuntime());
    ctx.setInputSource(context, data, context.getRuntime().getNil());
    String javaEncoding = findEncoding(context, encoding);
    if (javaEncoding != null) {
        ctx.getInputSource().setEncoding(javaEncoding);
    }
    return ctx;
}
Also used : JRubyClass(org.jruby.anno.JRubyClass) RubyClass(org.jruby.RubyClass) RubyString(org.jruby.RubyString) NokogiriHelpers.rubyStringToString(nokogiri.internals.NokogiriHelpers.rubyStringToString) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 20 with RubyClass

use of org.jruby.RubyClass in project gocd by gocd.

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)

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