Search in sources :

Example 41 with RubyArray

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

the class XmlSchema method from_document.

/*
     * call-seq:
     *  from_document(doc)
     *
     * Create a new Schema from the Nokogiri::XML::Document +doc+
     */
@JRubyMethod(meta = true)
public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject document) {
    XmlDocument doc = ((XmlDocument) ((XmlNode) document).document(context));
    RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
    if (!errors.isEmpty()) {
        throw new RaiseException((XmlSyntaxError) errors.first());
    }
    DOMSource source = new DOMSource(doc.getDocument());
    IRubyObject uri = doc.url(context);
    if (!uri.isNil()) {
        source.setSystemId(uri.convertToString().asJavaString());
    }
    return getSchema(context, (RubyClass) klazz, source);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) RubyArray(org.jruby.RubyArray) RaiseException(org.jruby.exceptions.RaiseException) IRubyObject(org.jruby.runtime.builtin.IRubyObject) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 42 with RubyArray

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

the class XmlAttributeDecl method enumeration.

/**
     * FIXME: will enumerations all be of the simple (val1|val2|val3)
     * type string?
     */
@JRubyMethod
public IRubyObject enumeration(ThreadContext context) {
    RubyArray enumVals = RubyArray.newArray(context.getRuntime());
    String atype = ((Element) node).getAttribute("atype");
    if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
        // removed enclosing parens
        String valueStr = atype.substring(1, atype.length() - 1);
        String[] values = valueStr.split("\\|");
        for (int i = 0; i < values.length; i++) {
            enumVals.append(context.getRuntime().newString(values[i]));
        }
    }
    return enumVals;
}
Also used : RubyArray(org.jruby.RubyArray) Element(org.w3c.dom.Element) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 43 with RubyArray

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

the class XmlNode method process_xincludes.

/**
     * call-seq:
     *   process_xincludes(options)
     *
     * Loads and substitutes all xinclude elements below the node. The
     * parser context will be initialized with +options+.
     * 
     */
@JRubyMethod(visibility = Visibility.PRIVATE)
public IRubyObject process_xincludes(ThreadContext context, IRubyObject options) {
    XmlDocument xmlDocument = (XmlDocument) document(context);
    RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
    while (errors.getLength() > 0) {
        XmlSyntaxError error = (XmlSyntaxError) errors.shift(context);
        if (error.toString().contains("Include operation failed")) {
            throw new RaiseException(error);
        }
    }
    return this;
}
Also used : RubyArray(org.jruby.RubyArray) NokogiriHelpers.nodeArrayToRubyArray(nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray) RaiseException(org.jruby.exceptions.RaiseException) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 44 with RubyArray

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

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 45 with RubyArray

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

the class XmlAttributeDecl method enumeration.

/**
 * FIXME: will enumerations all be of the simple (val1|val2|val3)
 * type string?
 */
@JRubyMethod
public IRubyObject enumeration(ThreadContext context) {
    RubyArray enumVals = RubyArray.newArray(context.getRuntime());
    String atype = ((Element) node).getAttribute("atype");
    if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
        // removed enclosing parens
        String valueStr = atype.substring(1, atype.length() - 1);
        String[] values = valueStr.split("\\|");
        for (int i = 0; i < values.length; i++) {
            enumVals.append(context.getRuntime().newString(values[i]));
        }
    }
    return enumVals;
}
Also used : RubyArray(org.jruby.RubyArray) Element(org.w3c.dom.Element) 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