use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class ReaderNode method getNamespaces.
public IRubyObject getNamespaces(ThreadContext context) {
if (namespaces == null)
return ruby.getNil();
RubyHash hash = RubyHash.newHash(ruby);
Set<String> keys = namespaces.keySet();
for (String key : keys) {
String stringValue = namespaces.get(key);
IRubyObject k = stringOrBlank(context.getRuntime(), key);
IRubyObject v = stringOrBlank(context.getRuntime(), stringValue);
if (context.getRuntime().is1_9())
hash.op_aset19(context, k, v);
else
hash.op_aset(context, k, v);
}
return hash;
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XsltExtensionFunction method call.
public static Object call(String method, Object arg) {
if (XsltStylesheet.getRegistry() == null)
return null;
ThreadContext context = (ThreadContext) XsltStylesheet.getRegistry().get("context");
IRubyObject receiver = (IRubyObject) XsltStylesheet.getRegistry().get("receiver");
if (context == null || receiver == null)
return null;
IRubyObject arg0 = JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), arg);
IRubyObject result = RuntimeHelpers.invoke(context, receiver, method, arg0);
return result.toJava(Object.class);
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class NokogiriXPathFunction method evaluate.
public Object evaluate(List args) throws XPathFunctionException {
if (args.size() != this.arity) {
throw new XPathFunctionException("arity does not match");
}
Ruby ruby = this.handler.getRuntime();
ThreadContext context = ruby.getCurrentContext();
IRubyObject result = RuntimeHelpers.invoke(context, this.handler, this.name, fromObjectToRubyArgs(args));
return fromRubyToObject(result);
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class NokogiriEncodingReaderWrapper method read.
@Override
public int read(byte[] b, int off, int len) {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int copyLength = Math.min(firstChunkLength - firstChunkOff, len);
if (copyLength > 0) {
System.arraycopy(firstChunk, firstChunkOff, b, off, copyLength);
len -= copyLength;
firstChunkOff += copyLength;
}
if (len <= 0)
return copyLength;
IRubyObject returnValue = encodingReader.callMethod(context, "read", ruby.newFixnum(len));
if (returnValue.isNil())
return -1;
ByteList bytes = returnValue.asString().getByteList();
int length = bytes.length();
System.arraycopy(bytes.unsafeBytes(), bytes.getBegin(), b, off + copyLength, length);
return length + copyLength;
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class NokogiriHandler method startElement.
/*
* This has to call either "start_element" or
* "start_element_namespace" depending on whether there are any
* namespace attributes.
*
* Attributes that define namespaces are passed in a separate
* array of of <code>[:prefix, :uri]</code> arrays and are not
* passed with the other attributes.
*/
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
// for attributes other than namespace attrs
RubyArray rubyAttr = RubyArray.newArray(ruby);
// for namespace defining attributes
RubyArray rubyNSAttr = RubyArray.newArray(ruby);
ThreadContext context = ruby.getCurrentContext();
// isFromFragmentHandler();
boolean fromFragmentHandler = false;
for (int i = 0; i < attrs.getLength(); i++) {
String u = attrs.getURI(i);
String qn = attrs.getQName(i);
String ln = attrs.getLocalName(i);
String val = attrs.getValue(i);
String pre;
pre = getPrefix(qn);
if (ln == null || ln.equals(""))
ln = getLocalPart(qn);
if (isNamespace(qn) && !fromFragmentHandler) {
// I haven't figured the reason out yet, but, in somewhere,
// namespace is converted to array in array in array and cause
// TypeError at line 45 in fragment_handler.rb
RubyArray ns = RubyArray.newArray(ruby, 2);
if (ln.equals("xmlns"))
ln = null;
ns.add(stringOrNil(ruby, ln));
ns.add(ruby.newString(val));
rubyNSAttr.add(ns);
} else {
IRubyObject[] args = null;
if (needEmptyAttrCheck) {
if (isEmptyAttr(ln)) {
args = new IRubyObject[3];
args[0] = stringOrNil(ruby, ln);
args[1] = stringOrNil(ruby, pre);
args[2] = stringOrNil(ruby, u);
}
}
if (args == null) {
args = new IRubyObject[4];
args[0] = stringOrNil(ruby, ln);
args[1] = stringOrNil(ruby, pre);
args[2] = stringOrNil(ruby, u);
args[3] = stringOrNil(ruby, val);
}
IRubyObject attr = RuntimeHelpers.invoke(context, attrClass, "new", args);
rubyAttr.add(attr);
}
}
if (localName == null || localName.equals(""))
localName = getLocalPart(qName);
call("start_element_namespace", stringOrNil(ruby, localName), rubyAttr, stringOrNil(ruby, getPrefix(qName)), stringOrNil(ruby, uri), rubyNSAttr);
}
Aggregations