Search in sources :

Example 61 with JRubyMethod

use of org.jruby.anno.JRubyMethod in project gocd by gocd.

the class EncodingHandler method get.

@JRubyMethod(name = "[]", meta = true)
public static IRubyObject get(ThreadContext context, IRubyObject _klass, IRubyObject keyObj) {
    Ruby ruby = context.getRuntime();
    String key = keyObj.toString();
    String value = map.get(key);
    if (value == null)
        return ruby.getNil();
    return new EncodingHandler(ruby, getNokogiriClass(ruby, "Nokogiri::EncodingHandler"), value);
}
Also used : Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 62 with JRubyMethod

use of org.jruby.anno.JRubyMethod in project gocd by gocd.

the class HtmlElementDescription method sub_elements.

@JRubyMethod()
public IRubyObject sub_elements(ThreadContext context) {
    Ruby ruby = context.getRuntime();
    List<String> subs = findSubElements(element);
    IRubyObject[] ary = new IRubyObject[subs.size()];
    for (int i = 0; i < subs.size(); ++i) {
        ary[i] = ruby.newString(subs.get(i));
    }
    return ruby.newArray(ary);
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 63 with JRubyMethod

use of org.jruby.anno.JRubyMethod 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 64 with JRubyMethod

use of org.jruby.anno.JRubyMethod in project nokogiri by sparklemotion.

the class HtmlDocument method rbNew.

@JRubyMethod(name = "new", meta = true, rest = true, required = 0)
public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
    HtmlDocument htmlDocument;
    try {
        Document docNode = createNewDocument();
        htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
        htmlDocument.setDocumentNode(context, docNode);
    } catch (Exception ex) {
        throw context.getRuntime().newRuntimeError("couldn't create document: " + ex);
    }
    RuntimeHelpers.invoke(context, htmlDocument, "initialize", args);
    return htmlDocument;
}
Also used : Document(org.w3c.dom.Document) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 65 with JRubyMethod

use of org.jruby.anno.JRubyMethod in project nokogiri by sparklemotion.

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)

Aggregations

JRubyMethod (org.jruby.anno.JRubyMethod)103 IRubyObject (org.jruby.runtime.builtin.IRubyObject)32 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)31 Ruby (org.jruby.Ruby)31 Node (org.w3c.dom.Node)29 RubyString (org.jruby.RubyString)28 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)23 Document (org.w3c.dom.Document)19 RubyArray (org.jruby.RubyArray)17 NokogiriHelpers.nodeArrayToRubyArray (nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray)12 Element (org.w3c.dom.Element)12 NokogiriHelpers.convertString (nokogiri.internals.NokogiriHelpers.convertString)10 JRubyClass (org.jruby.anno.JRubyClass)10 RaiseException (org.jruby.exceptions.RaiseException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)8 RubyClass (org.jruby.RubyClass)7 InputStream (java.io.InputStream)6 NokogiriNamespaceCache (nokogiri.internals.NokogiriNamespaceCache)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4