use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
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;
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class ReaderNode method getNamespaces.
public IRubyObject getNamespaces(ThreadContext context) {
final Ruby runtime = context.runtime;
if (namespaces == null)
return runtime.getNil();
RubyHash hash = RubyHash.newHash(runtime);
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
IRubyObject k = stringOrBlank(runtime, entry.getKey());
IRubyObject v = stringOrBlank(runtime, entry.getValue());
// hash.op_aset(context, k, v)
hash.fastASetCheckString(runtime, k, v);
}
return hash;
}
use of org.jruby.runtime.builtin.IRubyObject 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);
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
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);
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
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;
}
}
Aggregations