Search in sources :

Example 1 with Options

use of nokogiri.internals.ParserContext.Options in project nokogiri by sparklemotion.

the class XmlReader method from_io.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject from_io(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
    // Only to pass the  source test.
    Ruby runtime = context.getRuntime();
    // Not nil allowed!
    if (args[0].isNil())
        throw runtime.newArgumentError("io cannot be nil");
    XmlReader reader = (XmlReader) NokogiriService.XML_READER_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Reader"));
    reader.init(runtime);
    reader.setInstanceVariable("@source", args[0]);
    reader.setInstanceVariable("@errors", runtime.newArray());
    IRubyObject url = context.nil;
    if (args.length > 1)
        url = args[1];
    if (args.length > 2)
        reader.setInstanceVariable("@encoding", args[2]);
    Options options;
    if (args.length > 3) {
        options = new ParserContext.Options((Long) args[3].toJava(Long.class));
    } else {
        // use the default options RECOVER | NONET
        options = new ParserContext.Options(2048 | 1);
    }
    InputStream in = new UncloseableInputStream(new IOInputStream(args[0]));
    reader.setInput(context, in, url, options);
    return reader;
}
Also used : Options(nokogiri.internals.ParserContext.Options) Options(nokogiri.internals.ParserContext.Options) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IOInputStream(org.jruby.util.IOInputStream) InputStream(java.io.InputStream) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IRubyObject(org.jruby.runtime.builtin.IRubyObject) ParserContext(nokogiri.internals.ParserContext) Ruby(org.jruby.Ruby) IOInputStream(org.jruby.util.IOInputStream) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 2 with Options

use of nokogiri.internals.ParserContext.Options in project gocd by gocd.

the class XmlReader method from_io.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject from_io(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
    // Only to pass the  source test.
    Ruby runtime = context.getRuntime();
    // Not nil allowed!
    if (args[0].isNil())
        throw runtime.newArgumentError("io cannot be nil");
    XmlReader reader = (XmlReader) NokogiriService.XML_READER_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Reader"));
    reader.init(runtime);
    reader.setInstanceVariable("@source", args[0]);
    reader.setInstanceVariable("@errors", runtime.newArray());
    IRubyObject url = context.nil;
    if (args.length > 1)
        url = args[1];
    if (args.length > 2)
        reader.setInstanceVariable("@encoding", args[2]);
    Options options;
    if (args.length > 3) {
        options = new ParserContext.Options((Long) args[3].toJava(Long.class));
    } else {
        // use the default options RECOVER | NONET
        options = new ParserContext.Options(2048 | 1);
    }
    InputStream in = new UncloseableInputStream(new IOInputStream(args[0]));
    reader.setInput(context, in, url, options);
    return reader;
}
Also used : Options(nokogiri.internals.ParserContext.Options) Options(nokogiri.internals.ParserContext.Options) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IOInputStream(org.jruby.util.IOInputStream) InputStream(java.io.InputStream) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IRubyObject(org.jruby.runtime.builtin.IRubyObject) ParserContext(nokogiri.internals.ParserContext) Ruby(org.jruby.Ruby) IOInputStream(org.jruby.util.IOInputStream) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 3 with Options

use of nokogiri.internals.ParserContext.Options in project gocd by gocd.

the class XmlReader method from_memory.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject from_memory(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
    // args[0]: string, args[1]: url, args[2]: encoding, args[3]: options
    Ruby runtime = context.getRuntime();
    // Not nil allowed!
    if (args[0].isNil())
        throw runtime.newArgumentError("string cannot be nil");
    XmlReader reader = (XmlReader) NokogiriService.XML_READER_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Reader"));
    reader.init(runtime);
    reader.setInstanceVariable("@source", args[0]);
    reader.setInstanceVariable("@errors", runtime.newArray());
    IRubyObject url = context.nil;
    if (args.length > 1)
        url = args[1];
    if (args.length > 2)
        reader.setInstanceVariable("@encoding", args[2]);
    Options options;
    if (args.length > 3) {
        options = new ParserContext.Options((Long) args[3].toJava(Long.class));
    } else {
        // use the default options RECOVER | NONET
        options = new ParserContext.Options(2048 | 1);
    }
    IRubyObject stringIO = NokogiriService.getNokogiriClassCache(context.getRuntime()).get("StringIO").newInstance(context, args[0], Block.NULL_BLOCK);
    InputStream in = new UncloseableInputStream(new IOInputStream(stringIO));
    reader.setInput(context, in, url, options);
    return reader;
}
Also used : Options(nokogiri.internals.ParserContext.Options) Options(nokogiri.internals.ParserContext.Options) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IOInputStream(org.jruby.util.IOInputStream) InputStream(java.io.InputStream) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IRubyObject(org.jruby.runtime.builtin.IRubyObject) ParserContext(nokogiri.internals.ParserContext) Ruby(org.jruby.Ruby) IOInputStream(org.jruby.util.IOInputStream) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 4 with Options

use of nokogiri.internals.ParserContext.Options in project nokogiri by sparklemotion.

the class XmlReader method from_memory.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject from_memory(ThreadContext context, IRubyObject cls, IRubyObject[] args) {
    // args[0]: string, args[1]: url, args[2]: encoding, args[3]: options
    Ruby runtime = context.getRuntime();
    // Not nil allowed!
    if (args[0].isNil())
        throw runtime.newArgumentError("string cannot be nil");
    XmlReader reader = (XmlReader) NokogiriService.XML_READER_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Reader"));
    reader.init(runtime);
    reader.setInstanceVariable("@source", args[0]);
    reader.setInstanceVariable("@errors", runtime.newArray());
    IRubyObject url = context.nil;
    if (args.length > 1)
        url = args[1];
    if (args.length > 2)
        reader.setInstanceVariable("@encoding", args[2]);
    Options options;
    if (args.length > 3) {
        options = new ParserContext.Options((Long) args[3].toJava(Long.class));
    } else {
        // use the default options RECOVER | NONET
        options = new ParserContext.Options(2048 | 1);
    }
    IRubyObject stringIO = runtime.getClass("StringIO").newInstance(context, args[0], Block.NULL_BLOCK);
    InputStream in = new UncloseableInputStream(new IOInputStream(stringIO));
    reader.setInput(context, in, url, options);
    return reader;
}
Also used : Options(nokogiri.internals.ParserContext.Options) Options(nokogiri.internals.ParserContext.Options) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IOInputStream(org.jruby.util.IOInputStream) InputStream(java.io.InputStream) UncloseableInputStream(nokogiri.internals.UncloseableInputStream) IRubyObject(org.jruby.runtime.builtin.IRubyObject) ParserContext(nokogiri.internals.ParserContext) Ruby(org.jruby.Ruby) IOInputStream(org.jruby.util.IOInputStream) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

InputStream (java.io.InputStream)4 ParserContext (nokogiri.internals.ParserContext)4 Options (nokogiri.internals.ParserContext.Options)4 UncloseableInputStream (nokogiri.internals.UncloseableInputStream)4 Ruby (org.jruby.Ruby)4 JRubyMethod (org.jruby.anno.JRubyMethod)4 IRubyObject (org.jruby.runtime.builtin.IRubyObject)4 IOInputStream (org.jruby.util.IOInputStream)4