Search in sources :

Example 1 with RubyArray

use of org.jruby.RubyArray in project enumerable by hraberg.

the class JRubyTestBase method javaInRubyToRuby.

protected static IRubyObject javaInRubyToRuby(Ruby ruby, Object value) {
    if (value instanceof List<?> && !(value instanceof RubyArray)) {
        RubyArray array = RubyArray.newArray(ruby);
        array.addAll((Collection<?>) value);
        return array;
    }
    if (value instanceof Map<?, ?> && !(value instanceof RubyHash)) {
        RubyHash hash = RubyHash.newHash(ruby);
        hash.putAll((Map<?, ?>) value);
        return hash;
    }
    return javaToRuby(ruby, value);
}
Also used : RubyArray(org.jruby.RubyArray) RubyHash(org.jruby.RubyHash)

Example 2 with RubyArray

use of org.jruby.RubyArray in project nokogiri by sparklemotion.

the class XmlElement method accept.

@Override
public void accept(ThreadContext context, SaveContextVisitor visitor) {
    visitor.enter((Element) node);
    XmlNodeSet xmlNodeSet = (XmlNodeSet) children(context);
    if (xmlNodeSet.length() > 0) {
        RubyArray nodes = xmlNodeSet.nodes;
        for (int i = 0; i < nodes.size(); i++) {
            Object item = nodes.eltInternal(i);
            if (item instanceof XmlNode) {
                ((XmlNode) item).accept(context, visitor);
            } else if (item instanceof XmlNamespace) {
                ((XmlNamespace) item).accept(context, visitor);
            }
        }
    }
    visitor.leave((Element) node);
}
Also used : RubyArray(org.jruby.RubyArray)

Example 3 with RubyArray

use of org.jruby.RubyArray in project nokogiri by sparklemotion.

the class XmlNode method element_children.

@JRubyMethod(name = { "element_children", "elements" })
public IRubyObject element_children(ThreadContext context) {
    List<Node> elementNodes = new ArrayList<Node>();
    addElements(node, elementNodes, false);
    if (elementNodes.size() == 0)
        return XmlNodeSet.newEmptyNodeSet(context);
    RubyArray array = NokogiriHelpers.nodeArrayToRubyArray(context.getRuntime(), elementNodes.toArray(new Node[0]));
    XmlNodeSet xmlNodeSet = XmlNodeSet.newXmlNodeSet(context, array);
    return xmlNodeSet;
}
Also used : RubyArray(org.jruby.RubyArray) NokogiriHelpers.nodeArrayToRubyArray(nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray) NokogiriHelpers.clearCachedNode(nokogiri.internals.NokogiriHelpers.clearCachedNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 4 with RubyArray

use of org.jruby.RubyArray in project nokogiri by sparklemotion.

the class XmlNode method accept.

// Users might extend XmlNode. This method works for such a case.
public void accept(ThreadContext context, SaveContextVisitor visitor) {
    visitor.enter(node);
    XmlNodeSet xmlNodeSet = (XmlNodeSet) children(context);
    if (xmlNodeSet.length() > 0) {
        RubyArray array = (RubyArray) xmlNodeSet.to_a(context);
        for (int i = 0; i < array.getLength(); i++) {
            Object item = array.get(i);
            if (item instanceof XmlNode) {
                XmlNode cur = (XmlNode) item;
                cur.accept(context, visitor);
            } else if (item instanceof XmlNamespace) {
                XmlNamespace cur = (XmlNamespace) item;
                cur.accept(context, visitor);
            }
        }
    }
    visitor.leave(node);
}
Also used : RubyArray(org.jruby.RubyArray) NokogiriHelpers.nodeArrayToRubyArray(nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 5 with RubyArray

use of org.jruby.RubyArray in project nokogiri by sparklemotion.

the class XmlNode method namespace_definitions.

/**
     * Return an array of XmlNamespace nodes based on the attributes
     * of this node.
     */
@JRubyMethod
public IRubyObject namespace_definitions(ThreadContext context) {
    // don't use namespace_definitions cache anymore since
    // namespaces might be deleted. Reflecting the result of 
    // namesapce removals is complicated, so the cache might not be
    // updated.
    Ruby ruby = context.getRuntime();
    RubyArray namespace_definitions = ruby.newArray();
    if (doc == null)
        return namespace_definitions;
    if (doc instanceof HtmlDocument)
        return namespace_definitions;
    List<XmlNamespace> namespaces = ((XmlDocument) doc).getNamespaceCache().get(node);
    for (XmlNamespace namespace : namespaces) {
        namespace_definitions.append(namespace);
    }
    return namespace_definitions;
}
Also used : RubyArray(org.jruby.RubyArray) NokogiriHelpers.nodeArrayToRubyArray(nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

RubyArray (org.jruby.RubyArray)65 JRubyMethod (org.jruby.anno.JRubyMethod)34 Ruby (org.jruby.Ruby)26 IRubyObject (org.jruby.runtime.builtin.IRubyObject)26 NokogiriHelpers.nodeArrayToRubyArray (nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray)13 RubyString (org.jruby.RubyString)13 IOException (java.io.IOException)11 RaiseException (org.jruby.exceptions.RaiseException)10 ArrayList (java.util.ArrayList)8 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)8 RubyClass (org.jruby.RubyClass)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)5 RubyFixnum (org.jruby.RubyFixnum)5 ThreadContext (org.jruby.runtime.ThreadContext)5 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)4 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 ASN1String (org.bouncycastle.asn1.ASN1String)4 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)4 RubyModule (org.jruby.RubyModule)4