Search in sources :

Example 6 with RubyClass

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

the class XsltStylesheet method parse_stylesheet_doc.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject parse_stylesheet_doc(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    ensureFirstArgIsDocument(runtime, args[0]);
    XmlDocument xmlDoc = (XmlDocument) args[0];
    ensureDocumentHasNoError(context, xmlDoc);
    Document doc = ((XmlDocument) xmlDoc.dup_implementation(context, true)).getDocument();
    XsltStylesheet xslt = (XsltStylesheet) NokogiriService.XSLT_STYLESHEET_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
    try {
        xslt.init(args[1], doc);
    } catch (TransformerConfigurationException ex) {
        throw runtime.newRuntimeError("could not parse xslt stylesheet");
    }
    return xslt;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) JRubyClass(org.jruby.anno.JRubyClass) RubyClass(org.jruby.RubyClass) Document(org.w3c.dom.Document) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 7 with RubyClass

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

the class HtmlSaxParserContext method parse_memory.

@JRubyMethod(name = "memory", meta = true)
public static IRubyObject parse_memory(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());
    String javaEncoding = findEncoding(context, encoding);
    if (javaEncoding != null) {
        String input = applyEncoding(rubyStringToString(data), javaEncoding);
        ByteArrayInputStream istream = new ByteArrayInputStream(input.getBytes());
        ctx.setInputSource(istream);
        ctx.getInputSource().setEncoding(javaEncoding);
    }
    return ctx;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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 8 with RubyClass

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

the class HtmlSaxParserContext method parse_file.

@JRubyMethod(name = "file", meta = true)
public static IRubyObject parse_file(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.setInputSourceFile(context, data);
    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 9 with RubyClass

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

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)

Example 10 with RubyClass

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

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)

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