Search in sources :

Example 91 with JRubyMethod

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

the class XmlNode method create_internal_subset.

@JRubyMethod
public IRubyObject create_internal_subset(ThreadContext context, IRubyObject name, IRubyObject external_id, IRubyObject system_id) {
    IRubyObject subset = internal_subset(context);
    if (!subset.isNil()) {
        throw context.getRuntime().newRuntimeError("Document already has internal subset");
    }
    Document document = getOwnerDocument();
    if (document == null) {
        return context.getRuntime().getNil();
    }
    XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
    IRubyObject xdtd = xdoc.createInternalSubset(context, name, external_id, system_id);
    return xdtd;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 92 with JRubyMethod

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

the class HtmlEntityLookup method get.

/**
     * Looks up an HTML entity <code>key</code>.
     *
     * The description is a bit lacking.
     */
@JRubyMethod()
public IRubyObject get(ThreadContext context, IRubyObject key) {
    Ruby ruby = context.getRuntime();
    String name = key.toString();
    int val = HTMLEntities.get(name);
    if (val == -1)
        return ruby.getNil();
    IRubyObject edClass = ruby.getClassFromPath("Nokogiri::HTML::EntityDescription");
    IRubyObject edObj = invoke(context, edClass, "new", ruby.newFixnum(val), ruby.newString(name), ruby.newString(name + " entity"));
    return edObj;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 93 with JRubyMethod

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

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) NokogiriHelpers.rubyStringToString(nokogiri.internals.NokogiriHelpers.rubyStringToString) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 94 with JRubyMethod

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

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) NokogiriHelpers.rubyStringToString(nokogiri.internals.NokogiriHelpers.rubyStringToString) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 95 with JRubyMethod

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

the class HtmlEntityLookup method get.

/**
 * Looks up an HTML entity <code>key</code>.
 *
 * The description is a bit lacking.
 */
@JRubyMethod()
public IRubyObject get(ThreadContext context, IRubyObject key) {
    Ruby ruby = context.getRuntime();
    String name = key.toString();
    int val = HTMLEntities.get(name);
    if (val == -1)
        return ruby.getNil();
    IRubyObject edClass = ruby.getClassFromPath("Nokogiri::HTML::EntityDescription");
    IRubyObject edObj = invoke(context, edClass, "new", ruby.newFixnum(val), ruby.newString(name), ruby.newString(name + " entity"));
    return edObj;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) 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