use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
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;
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class XmlNode method external_subset.
@JRubyMethod
public IRubyObject external_subset(ThreadContext context) {
Document document = getOwnerDocument();
if (document == null) {
return context.getRuntime().getNil();
}
XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
IRubyObject xdtd = xdoc.getExternalSubset(context);
return xdtd;
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class XmlNode method lang.
@JRubyMethod
public IRubyObject lang(ThreadContext context) {
IRubyObject currentObj = this;
while (!currentObj.isNil()) {
XmlNode currentNode = asXmlNode(context, currentObj);
IRubyObject lang = currentNode.getAttribute(context.getRuntime(), "xml:lang");
if (!lang.isNil()) {
return lang;
}
currentObj = currentNode.parent(context);
}
return context.nil;
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
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;
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class XmlNode method adoptAs.
/**
* Adopt XmlNode <code>other</code> into the document of
* <code>this</code> using the specified scheme.
*/
protected IRubyObject adoptAs(ThreadContext context, AdoptScheme scheme, IRubyObject other_) {
XmlNode other = asXmlNode(context, other_);
// this.doc might be null since this node can be empty node.
if (this.doc != null) {
other.setDocument(context, this.doc);
}
IRubyObject nodeOrTags = other;
Node thisNode = node;
Node otherNode = other.node;
try {
Document prev = otherNode.getOwnerDocument();
Document doc = thisNode.getOwnerDocument();
clearXpathContext(prev);
clearXpathContext(doc);
if (doc != null && doc != otherNode.getOwnerDocument()) {
Node ret = doc.adoptNode(otherNode);
// FIXME: this is really a hack, see documentation of fixUserData() for more details.
fixUserData(prev, ret);
if (ret == null) {
throw context.getRuntime().newRuntimeError("Failed to take ownership of node");
}
otherNode = ret;
}
Node parent = thisNode.getParentNode();
switch(scheme) {
case CHILD:
Node[] children = adoptAsChild(context, thisNode, otherNode);
if (children.length == 1 && otherNode == children[0]) {
break;
} else {
nodeOrTags = nodeArrayToRubyArray(context.getRuntime(), children);
}
break;
case PREV_SIBLING:
adoptAsPrevSibling(context, parent, thisNode, otherNode);
break;
case NEXT_SIBLING:
adoptAsNextSibling(context, parent, thisNode, otherNode);
break;
case REPLACEMENT:
adoptAsReplacement(context, parent, thisNode, otherNode);
break;
}
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.toString());
}
if (otherNode.getNodeType() == Node.TEXT_NODE) {
coalesceTextNodes(context, other, scheme);
}
if (this instanceof XmlDocument) {
((XmlDocument) this).resetNamespaceCache(context);
}
other.relink_namespace(context);
return nodeOrTags;
}
Aggregations