Search in sources :

Example 66 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XmlNamespace method createFromAttr.

public static XmlNamespace createFromAttr(Ruby runtime, Attr attr) {
    String prefixValue = getLocalNameForNamespace(attr.getName());
    IRubyObject prefix_value;
    if (prefixValue == null) {
        prefix_value = runtime.getNil();
        prefixValue = "";
    } else {
        prefix_value = RubyString.newString(runtime, prefixValue);
    }
    String hrefValue = attr.getValue();
    IRubyObject href_value = RubyString.newString(runtime, hrefValue);
    // check namespace cache
    XmlDocument xmlDocument = (XmlDocument) getCachedNodeOrCreate(runtime, attr.getOwnerDocument());
    xmlDocument.initializeNamespaceCacheIfNecessary();
    XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefixValue, hrefValue);
    if (xmlNamespace != null)
        return xmlNamespace;
    // creating XmlNamespace instance
    XmlNamespace namespace = (XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
    namespace.init(attr, prefix_value, href_value, prefixValue, hrefValue, xmlDocument);
    // updateing namespace cache
    xmlDocument.getNamespaceCache().put(namespace, attr.getOwnerElement());
    return namespace;
}
Also used : RubyString(org.jruby.RubyString) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 67 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XsltStylesheet method createDocumentFromString.

private IRubyObject createDocumentFromString(ThreadContext context, Ruby runtime, String stringResult) {
    IRubyObject[] args = new IRubyObject[4];
    args[0] = stringOrBlank(runtime, stringResult);
    // url
    args[1] = runtime.getNil();
    // encoding
    args[2] = runtime.getNil();
    RubyClass parse_options = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::ParseOptions");
    if (htmlish) {
        args[3] = parse_options.getConstant("DEFAULT_HTML");
        RubyClass htmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::HTML::Document");
        return RuntimeHelpers.invoke(context, htmlDocumentClass, "parse", args);
    } else {
        args[3] = parse_options.getConstant("DEFAULT_XML");
        RubyClass xmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::XML::Document");
        XmlDocument xmlDocument = (XmlDocument) RuntimeHelpers.invoke(context, xmlDocumentClass, "parse", args);
        if (((Document) xmlDocument.getNode()).getDocumentElement() == null) {
            RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
            RuntimeHelpers.invoke(context, errors, "<<", args[0]);
        }
        return xmlDocument;
    }
}
Also used : RubyArray(org.jruby.RubyArray) JRubyClass(org.jruby.anno.JRubyClass) RubyClass(org.jruby.RubyClass) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 68 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XmlNode method internal_subset.

@JRubyMethod
public IRubyObject internal_subset(ThreadContext context) {
    Document document = getOwnerDocument();
    if (document == null) {
        return context.getRuntime().getNil();
    }
    XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
    IRubyObject xdtd = xdoc.getInternalSubset(context);
    return xdtd;
}
Also used : Document(org.w3c.dom.Document) IRubyObject(org.jruby.runtime.builtin.IRubyObject) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 69 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XmlNode method create_internal_subset.

@JRubyMethod
public IRubyObject create_internal_subset(ThreadContext context, IRubyObject name, IRubyObject external_id, IRubyObject system_id) {
    IRubyObject subset = internal_subset(context);
    if (!subset.isNil()) {
        throw context.getRuntime().newRuntimeError("Document already has internal subset");
    }
    Document document = getOwnerDocument();
    if (document == null) {
        return context.getRuntime().getNil();
    }
    XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
    IRubyObject xdtd = xdoc.createInternalSubset(context, name, external_id, system_id);
    return xdtd;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 70 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XmlNode method create_external_subset.

@JRubyMethod
public IRubyObject create_external_subset(ThreadContext context, IRubyObject name, IRubyObject external_id, IRubyObject system_id) {
    IRubyObject subset = external_subset(context);
    if (!subset.isNil()) {
        throw context.getRuntime().newRuntimeError("Document already has external subset");
    }
    Document document = getOwnerDocument();
    if (document == null) {
        return context.getRuntime().getNil();
    }
    XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
    IRubyObject xdtd = xdoc.createExternalSubset(context, name, external_id, system_id);
    return xdtd;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

IRubyObject (org.jruby.runtime.builtin.IRubyObject)105 JRubyMethod (org.jruby.anno.JRubyMethod)32 Document (org.w3c.dom.Document)27 Ruby (org.jruby.Ruby)25 Node (org.w3c.dom.Node)24 RubyString (org.jruby.RubyString)16 RubyArray (org.jruby.RubyArray)13 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)11 RaiseException (org.jruby.exceptions.RaiseException)10 InputStream (java.io.InputStream)6 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)6 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)6 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)6 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)6 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)6 RubyProc (org.jruby.RubyProc)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)4 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)4