use of org.jruby.anno.JRubyMethod in project gocd by gocd.
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.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method internal_subset.
@JRubyMethod
public IRubyObject internal_subset(ThreadContext context) {
Document document = getOwnerDocument();
if (document == null) {
return context.getRuntime().getNil();
}
XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
IRubyObject xdtd = xdoc.getInternalSubset(context);
return xdtd;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method create_internal_subset.
@JRubyMethod
public IRubyObject create_internal_subset(ThreadContext context, IRubyObject name, IRubyObject external_id, IRubyObject system_id) {
IRubyObject subset = internal_subset(context);
if (!subset.isNil()) {
throw context.getRuntime().newRuntimeError("Document already has internal subset");
}
Document document = getOwnerDocument();
if (document == null) {
return context.getRuntime().getNil();
}
XmlDocument xdoc = (XmlDocument) getCachedNodeOrCreate(context.getRuntime(), document);
IRubyObject xdtd = xdoc.createInternalSubset(context, name, external_id, system_id);
return xdtd;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method attribute_nodes.
@JRubyMethod
public IRubyObject attribute_nodes(ThreadContext context) {
NamedNodeMap nodeMap = this.node.getAttributes();
Ruby ruby = context.getRuntime();
if (nodeMap == null) {
return ruby.newEmptyArray();
}
RubyArray attr = ruby.newArray();
for (int i = 0; i < nodeMap.getLength(); i++) {
if ((doc instanceof HtmlDocument) || !NokogiriHelpers.isNamespace(nodeMap.item(i))) {
attr.append(getCachedNodeOrCreate(context.getRuntime(), nodeMap.item(i)));
}
}
return attr;
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class XmlNode method attribute.
@JRubyMethod(name = { "attribute", "attr" })
public IRubyObject attribute(ThreadContext context, IRubyObject name) {
NamedNodeMap attrs = this.node.getAttributes();
Node attr = attrs.getNamedItem(rubyStringToString(name));
if (attr == null) {
return context.getRuntime().getNil();
}
return getCachedNodeOrCreate(context.getRuntime(), attr);
}
Aggregations