use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method namespace.
@JRubyMethod
public IRubyObject namespace(ThreadContext context) {
if (doc instanceof HtmlDocument)
return context.getRuntime().getNil();
NokogiriNamespaceCache nsCache = NokogiriHelpers.getNamespaceCacheFormNode(node);
String prefix = node.getPrefix();
XmlNamespace namespace = nsCache.get(prefix == null ? "" : prefix, node.getNamespaceURI());
if (namespace == null || namespace.isEmpty()) {
return context.getRuntime().getNil();
}
return namespace;
}
use of org.jruby.anno.JRubyMethod 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;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method content.
@JRubyMethod(name = { "content", "text", "inner_text" })
public IRubyObject content(ThreadContext context) {
if (!node.hasChildNodes() && node.getNodeValue() == null && (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE))
return context.nil;
String textContent;
if (this instanceof XmlDocument) {
Node node = ((Document) this.node).getDocumentElement();
if (node == null) {
textContent = "";
} else {
Node documentElement = ((Document) this.node).getDocumentElement();
StringBuffer buffer = new StringBuffer();
getTextContentRecursively(context, buffer, documentElement);
textContent = buffer.toString();
}
} else {
StringBuffer buffer = new StringBuffer();
getTextContentRecursively(context, buffer, node);
textContent = buffer.toString();
}
NokogiriHelpers.convertEncodingByNKFIfNecessary(context.getRuntime(), (XmlDocument) document(context), textContent);
return stringOrNil(context.getRuntime(), textContent);
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlDocument method wrapJavaDocument.
@JRubyMethod(meta = true)
public static IRubyObject wrapJavaDocument(ThreadContext context, IRubyObject klazz, IRubyObject arg) {
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::Document"));
RuntimeHelpers.invoke(context, xmlDocument, "initialize");
Document document = (Document) arg.toJava(Document.class);
xmlDocument.setDocumentNode(context, document);
return xmlDocument;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlDocument method root_set.
@JRubyMethod(name = "root=")
public IRubyObject root_set(ThreadContext context, IRubyObject newRoot_) {
// should be nil.
if (newRoot_ instanceof RubyNil) {
getDocument().getDocumentElement().setUserData(NokogiriHelpers.VALID_ROOT_NODE, false, null);
return newRoot_;
}
XmlNode newRoot = asXmlNode(context, newRoot_);
IRubyObject root = root(context);
if (root.isNil()) {
Node newRootNode;
if (getDocument() == newRoot.getOwnerDocument()) {
newRootNode = newRoot.node;
} else {
// must copy otherwise newRoot may exist in two places
// with different owner document.
newRootNode = getDocument().importNode(newRoot.node, true);
}
add_child_node(context, getCachedNodeOrCreate(context.getRuntime(), newRootNode));
} else {
Node rootNode = asXmlNode(context, root).node;
((XmlNode) getCachedNodeOrCreate(context.getRuntime(), rootNode)).replace_node(context, newRoot);
}
return newRoot;
}
Aggregations