Search in sources :

Example 11 with RubyArray

use of org.jruby.RubyArray in project gocd by gocd.

the class XmlNode method isErrorIncreased.

private boolean isErrorIncreased(RubyArray baseErrors, RubyArray createdErrors) {
    RubyFixnum length = ((RubyArray) createdErrors.op_diff(baseErrors)).length();
    int diff_in_length = (Integer) length.toJava(Integer.class);
    return diff_in_length > 0;
}
Also used : RubyArray(org.jruby.RubyArray) NokogiriHelpers.nodeArrayToRubyArray(nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray) RubyFixnum(org.jruby.RubyFixnum)

Example 12 with RubyArray

use of org.jruby.RubyArray in project gocd by gocd.

the class XmlDomParserContext method getDocumentWithErrorsOrRaiseException.

public XmlDocument getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex) {
    if (options.recover) {
        XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
        this.addErrorsIfNecessary(context, xmlDocument);
        XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
        xmlSyntaxError.setException(ex);
        ((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
        return xmlDocument;
    } else {
        XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
        xmlSyntaxError.setException(ex);
        throw new RaiseException(xmlSyntaxError);
    }
}
Also used : RubyArray(org.jruby.RubyArray) XmlSyntaxError(nokogiri.XmlSyntaxError) RaiseException(org.jruby.exceptions.RaiseException) XmlDocument(nokogiri.XmlDocument)

Example 13 with RubyArray

use of org.jruby.RubyArray in project gocd by gocd.

the class ReaderNode method getAttributesNodes.

public IRubyObject getAttributesNodes() {
    RubyArray array = RubyArray.newArray(ruby);
    if (attributeList != null && attributeList.length > 0) {
        if (document == null) {
            XmlDocument doc = (XmlDocument) XmlDocument.rbNew(ruby.getCurrentContext(), getNokogiriClass(ruby, "Nokogiri::XML::Document"), new IRubyObject[0]);
            document = doc.getDocument();
        }
        for (int i = 0; i < attributeList.length; i++) {
            if (!isNamespace(attributeList.names.get(i))) {
                Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
                attr.setValue(attributeList.values.get(i));
                XmlAttr xmlAttr = (XmlAttr) NokogiriService.XML_ATTR_ALLOCATOR.allocate(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"));
                xmlAttr.setNode(ruby.getCurrentContext(), attr);
                array.append(xmlAttr);
            }
        }
    }
    return array;
}
Also used : RubyArray(org.jruby.RubyArray) XmlDocument(nokogiri.XmlDocument) IRubyObject(org.jruby.runtime.builtin.IRubyObject) XmlAttr(nokogiri.XmlAttr) Attr(org.w3c.dom.Attr) XmlAttr(nokogiri.XmlAttr)

Example 14 with RubyArray

use of org.jruby.RubyArray in project gocd by gocd.

the class XmlDocumentFragment method add_child.

// @Override
public void add_child(ThreadContext context, XmlNode child) {
    // Some magic for DocumentFragment
    Ruby ruby = context.getRuntime();
    XmlNodeSet children = (XmlNodeSet) child.children(context);
    long length = children.length();
    RubyArray childrenArray = children.convertToArray();
    if (length != 0) {
        for (int i = 0; i < length; i++) {
            XmlNode item = (XmlNode) ((XmlNode) childrenArray.aref(ruby.newFixnum(i))).dup_implementation(context, true);
            add_child(context, item);
        }
    }
}
Also used : RubyArray(org.jruby.RubyArray) Ruby(org.jruby.Ruby)

Example 15 with RubyArray

use of org.jruby.RubyArray in project gocd by gocd.

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