Search in sources :

Example 11 with ThreadContext

use of org.jruby.runtime.ThreadContext 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);
}
Also used : XPathFunctionException(javax.xml.xpath.XPathFunctionException) ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Example 12 with ThreadContext

use of org.jruby.runtime.ThreadContext 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);
}
Also used : RubyArray(org.jruby.RubyArray) ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 13 with ThreadContext

use of org.jruby.runtime.ThreadContext in project nokogiri by sparklemotion.

the class NokogiriXPathFunction method evaluate.

public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != this.arity) {
        throw new XPathFunctionException("arity does not match");
    }
    final Ruby runtime = this.handler.getRuntime();
    ThreadContext context = runtime.getCurrentContext();
    IRubyObject result = RuntimeHelpers.invoke(context, this.handler, this.name, fromObjectToRubyArgs(runtime, args));
    return fromRubyToObject(runtime, result);
}
Also used : XPathFunctionException(javax.xml.xpath.XPathFunctionException) ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Example 14 with ThreadContext

use of org.jruby.runtime.ThreadContext in project gocd by gocd.

the class NokogiriHandler method call.

private void call(String methodName, IRubyObject argument) {
    ThreadContext context = ruby.getCurrentContext();
    RuntimeHelpers.invoke(context, document(context), methodName, argument);
}
Also used : ThreadContext(org.jruby.runtime.ThreadContext)

Example 15 with ThreadContext

use of org.jruby.runtime.ThreadContext in project jruby-openssl by jruby.

the class X509Attribute method newAttribute.

static X509Attribute newAttribute(final Ruby runtime, final ASN1ObjectIdentifier type, final ASN1Set values) throws IOException {
    X509Attribute attribute = new X509Attribute(runtime, _Attribute(runtime));
    attribute.objectId = type;
    final ThreadContext context = runtime.getCurrentContext();
    attribute.value = ASN1.decodeObject(context, _ASN1(runtime), values);
    return attribute;
}
Also used : ThreadContext(org.jruby.runtime.ThreadContext)

Aggregations

ThreadContext (org.jruby.runtime.ThreadContext)25 IRubyObject (org.jruby.runtime.builtin.IRubyObject)11 Ruby (org.jruby.Ruby)7 RubyArray (org.jruby.RubyArray)5 RubyClass (org.jruby.RubyClass)4 RubyString (org.jruby.RubyString)4 IOException (java.io.IOException)3 XPathFunctionException (javax.xml.xpath.XPathFunctionException)3 ByteList (org.jruby.util.ByteList)3 PublicKey (java.security.PublicKey)2 ArrayList (java.util.ArrayList)2 X500Name (org.bouncycastle.asn1.x500.X500Name)2 RubyHash (org.jruby.RubyHash)2 RubyModule (org.jruby.RubyModule)2 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 List (java.util.List)1