Search in sources :

Example 26 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.

the class XmlComment method init.

@Override
protected void init(ThreadContext context, IRubyObject[] args) {
    if (args.length < 2)
        throw getRuntime().newArgumentError(args.length, 2);
    IRubyObject doc = args[0];
    IRubyObject text = args[1];
    XmlDocument xmlDoc;
    if (doc instanceof XmlDocument) {
        xmlDoc = (XmlDocument) doc;
    } else if (doc instanceof XmlNode) {
        XmlNode xmlNode = (XmlNode) doc;
        xmlDoc = (XmlDocument) xmlNode.document(context);
    } else {
        throw getRuntime().newArgumentError("first argument must be a XML::Document or XML::Node");
    }
    if (xmlDoc != null) {
        Document document = xmlDoc.getDocument();
        Node node = document.createComment(rubyStringToString(text));
        setNode(context, node);
    }
}
Also used : Node(org.w3c.dom.Node) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document)

Example 27 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.

the class HtmlDocument method getInternalSubset.

public IRubyObject getInternalSubset(ThreadContext context) {
    IRubyObject internalSubset = super.getInternalSubset(context);
    if (internalSubset.isNil()) {
        internalSubset = XmlDtd.newEmpty(context.getRuntime(), getDocument(), context.getRuntime().newString(DEFAULT_CONTENT_TYPE), context.getRuntime().newString(DEFAULT_PUBLIC_ID), context.getRuntime().newString(DEFAULT_SYTEM_ID));
        setInternalSubset(internalSubset);
    }
    return internalSubset;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 28 with IRubyObject

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

the class XmlDocument method getInternalSubset.

public IRubyObject getInternalSubset(ThreadContext context) {
    IRubyObject dtd = (IRubyObject) node.getUserData(DTD_INTERNAL_SUBSET);
    if (dtd == null) {
        Document document = getDocument();
        if (document.getUserData(XmlDocument.DTD_RAW_DOCUMENT) != null) {
            dtd = XmlDtd.newFromInternalSubset(context.getRuntime(), document);
        } else if (document.getDoctype() != null) {
            DocumentType docType = document.getDoctype();
            IRubyObject name, publicId, systemId;
            name = publicId = systemId = context.getRuntime().getNil();
            if (docType.getName() != null) {
                name = context.getRuntime().newString(docType.getName());
            }
            if (docType.getPublicId() != null) {
                publicId = context.getRuntime().newString(docType.getPublicId());
            }
            if (docType.getSystemId() != null) {
                systemId = context.getRuntime().newString(docType.getSystemId());
            }
            dtd = XmlDtd.newEmpty(context.getRuntime(), document, name, publicId, systemId);
        } else {
            dtd = context.getRuntime().getNil();
        }
        setInternalSubset(dtd);
    }
    return dtd;
}
Also used : DocumentType(org.w3c.dom.DocumentType) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document)

Example 29 with IRubyObject

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

the class XmlDocumentFragment method trim.

private static IRubyObject trim(ThreadContext context, XmlDocument xmlDocument, RubyString str) {
    // checks whether schema is given. if exists, allows whitespace processing to a parser
    Document document = (Document) xmlDocument.node;
    if (document.getDoctype() != null)
        return str;
    // strips trailing \n off forcefully
    // not to return new object in case of no chomp needed, chomp! is used here.
    IRubyObject result;
    if (context.getRuntime().is1_9())
        result = str.chomp_bang19(context);
    else
        result = str.chomp_bang(context);
    return result.isNil() ? str : result;
}
Also used : Document(org.w3c.dom.Document) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 30 with IRubyObject

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

the class XmlText method accept.

@Override
public void accept(ThreadContext context, SaveContextVisitor visitor) {
    visitor.enter((Text) node);
    Node child = node.getFirstChild();
    while (child != null) {
        IRubyObject nokoNode = getCachedNodeOrCreate(context.getRuntime(), child);
        if (nokoNode instanceof XmlNode) {
            XmlNode cur = (XmlNode) nokoNode;
            cur.accept(context, visitor);
        } else if (nokoNode instanceof XmlNamespace) {
            XmlNamespace cur = (XmlNamespace) nokoNode;
            cur.accept(context, visitor);
        }
        child = child.getNextSibling();
    }
    visitor.leave(node);
}
Also used : Node(org.w3c.dom.Node) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

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