Search in sources :

Example 1 with ReaderNode

use of nokogiri.internals.ReaderNode in project nokogiri by sparklemotion.

the class XmlReader method setAndRaiseErrorsIfAny.

private IRubyObject setAndRaiseErrorsIfAny(final Ruby runtime, final RaiseException ex) throws RaiseException {
    final ReaderNode currentNode = currentNode();
    if (currentNode == null) {
        return runtime.getNil();
    }
    if (currentNode.isError()) {
        RubyArray<?> errors = (RubyArray) getInstanceVariable("@errors");
        IRubyObject error = currentNode.toSyntaxError();
        errors.append(error);
        setInstanceVariable("@errors", errors);
        throw ex != null ? ex : ((XmlSyntaxError) error).toThrowable();
    }
    if (ex != null) {
        throw ex;
    }
    return this;
}
Also used : RubyArray(org.jruby.RubyArray) ReaderNode(nokogiri.internals.ReaderNode) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 2 with ReaderNode

use of nokogiri.internals.ReaderNode in project nokogiri by sparklemotion.

the class XmlReader method getOuterXml.

private String getOuterXml() {
    ReaderNode current = currentNode();
    if (current == null || current.depth < 0) {
        return null;
    }
    if (current instanceof ClosingNode) {
        return "<" + current.name + "/>";
    }
    StringBuilder sb = new StringBuilder();
    for (int i = position; i <= current.endOffset; i++) {
        sb.append(nodeQueue.get(i).getString());
    }
    return new String(sb);
}
Also used : ReaderNode(nokogiri.internals.ReaderNode) ClosingNode(nokogiri.internals.ReaderNode.ClosingNode) XMLString(org.apache.xerces.xni.XMLString)

Example 3 with ReaderNode

use of nokogiri.internals.ReaderNode in project gocd by gocd.

the class XmlReader method getOuterXml.

private String getOuterXml() {
    ReaderNode current = currentNode();
    if (current.depth < 0)
        return null;
    if (current instanceof ClosingNode) {
        return "<" + current.name + "/>";
    }
    StringBuffer sb = new StringBuffer();
    for (int i = position; i <= current.endOffset; i++) {
        sb.append(nodeQueue.get(i).getString());
    }
    return new String(sb);
}
Also used : ReaderNode(nokogiri.internals.ReaderNode) ClosingNode(nokogiri.internals.ReaderNode.ClosingNode) XMLString(org.apache.xerces.xni.XMLString)

Example 4 with ReaderNode

use of nokogiri.internals.ReaderNode in project gocd by gocd.

the class XmlReader method empty_element_p.

@JRubyMethod(name = { "empty_element?", "self_closing?" })
public IRubyObject empty_element_p(ThreadContext context) {
    ReaderNode readerNode = currentNode();
    ensureNodeClosed(context);
    if (readerNode == null)
        return context.getRuntime().getNil();
    if (!(readerNode instanceof ElementNode))
        context.getRuntime().getFalse();
    return RubyBoolean.newBoolean(context.getRuntime(), !readerNode.hasChildren);
}
Also used : ReaderNode(nokogiri.internals.ReaderNode) ElementNode(nokogiri.internals.ReaderNode.ElementNode) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 5 with ReaderNode

use of nokogiri.internals.ReaderNode in project nokogiri by sparklemotion.

the class XmlReader method empty_element_p.

@JRubyMethod(name = { "empty_element?", "self_closing?" })
public IRubyObject empty_element_p(ThreadContext context) {
    ReaderNode readerNode = currentNode();
    ensureNodeClosed(context);
    if (readerNode == null) {
        return context.getRuntime().getNil();
    }
    if (!(readerNode instanceof ElementNode)) {
        context.getRuntime().getFalse();
    }
    return RubyBoolean.newBoolean(context.getRuntime(), !readerNode.hasChildren);
}
Also used : ReaderNode(nokogiri.internals.ReaderNode) ElementNode(nokogiri.internals.ReaderNode.ElementNode) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

ReaderNode (nokogiri.internals.ReaderNode)5 ClosingNode (nokogiri.internals.ReaderNode.ClosingNode)2 ElementNode (nokogiri.internals.ReaderNode.ElementNode)2 XMLString (org.apache.xerces.xni.XMLString)2 JRubyMethod (org.jruby.anno.JRubyMethod)2 RubyArray (org.jruby.RubyArray)1 IRubyObject (org.jruby.runtime.builtin.IRubyObject)1