use of org.jruby.RubyArray 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.RubyArray in project nokogiri by sparklemotion.
the class XmlAttributeDecl method enumeration.
/**
* FIXME: will enumerations all be of the simple (val1|val2|val3)
* type string?
*/
@JRubyMethod
public IRubyObject enumeration(ThreadContext context) {
RubyArray enumVals = RubyArray.newArray(context.getRuntime());
String atype = ((Element) node).getAttribute("atype");
if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
// removed enclosing parens
String valueStr = atype.substring(1, atype.length() - 1);
String[] values = valueStr.split("\\|");
for (int i = 0; i < values.length; i++) {
enumVals.append(context.getRuntime().newString(values[i]));
}
}
return enumVals;
}
use of org.jruby.RubyArray in project nokogiri by sparklemotion.
the class XmlNode method process_xincludes.
/**
* call-seq:
* process_xincludes(options)
*
* Loads and substitutes all xinclude elements below the node. The
* parser context will be initialized with +options+.
*
*/
@JRubyMethod(visibility = Visibility.PRIVATE)
public IRubyObject process_xincludes(ThreadContext context, IRubyObject options) {
XmlDocument xmlDocument = (XmlDocument) document(context);
RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
while (errors.getLength() > 0) {
XmlSyntaxError error = (XmlSyntaxError) errors.shift(context);
if (error.toString().contains("Include operation failed")) {
throw new RaiseException(error);
}
}
return this;
}
use of org.jruby.RubyArray in project nokogiri by sparklemotion.
the class XmlDocumentFragment method add_child.
//@Override
public void add_child(ThreadContext context, XmlNode child) {
// Some magic for DocumentFragment
Ruby ruby = context.getRuntime();
XmlNodeSet children = (XmlNodeSet) child.children(context);
long length = children.length();
RubyArray childrenArray = children.convertToArray();
if (length != 0) {
for (int i = 0; i < length; i++) {
XmlNode item = (XmlNode) ((XmlNode) childrenArray.aref(ruby.newFixnum(i))).dup_implementation(context, true);
add_child(context, item);
}
}
}
use of org.jruby.RubyArray in project gocd by gocd.
the class XmlAttributeDecl method enumeration.
/**
* FIXME: will enumerations all be of the simple (val1|val2|val3)
* type string?
*/
@JRubyMethod
public IRubyObject enumeration(ThreadContext context) {
RubyArray enumVals = RubyArray.newArray(context.getRuntime());
String atype = ((Element) node).getAttribute("atype");
if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
// removed enclosing parens
String valueStr = atype.substring(1, atype.length() - 1);
String[] values = valueStr.split("\\|");
for (int i = 0; i < values.length; i++) {
enumVals.append(context.getRuntime().newString(values[i]));
}
}
return enumVals;
}
Aggregations