use of org.jruby.RubyArray in project gocd by gocd.
the class XmlNode method isErrorIncreased.
private boolean isErrorIncreased(RubyArray baseErrors, RubyArray createdErrors) {
RubyFixnum length = ((RubyArray) createdErrors.op_diff(baseErrors)).length();
int diff_in_length = (Integer) length.toJava(Integer.class);
return diff_in_length > 0;
}
use of org.jruby.RubyArray in project gocd by gocd.
the class XmlDomParserContext method getDocumentWithErrorsOrRaiseException.
public XmlDocument getDocumentWithErrorsOrRaiseException(ThreadContext context, RubyClass klazz, Exception ex) {
if (options.recover) {
XmlDocument xmlDocument = getInterruptedOrNewXmlDocument(context, klazz);
this.addErrorsIfNecessary(context, xmlDocument);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
((RubyArray) xmlDocument.getInstanceVariable("@errors")).append(xmlSyntaxError);
return xmlDocument;
} else {
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
throw new RaiseException(xmlSyntaxError);
}
}
use of org.jruby.RubyArray in project gocd by gocd.
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.RubyArray in project gocd by gocd.
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 XmlNode method namespace_definitions.
/**
* Return an array of XmlNamespace nodes based on the attributes
* of this node.
*/
@JRubyMethod
public IRubyObject namespace_definitions(ThreadContext context) {
// don't use namespace_definitions cache anymore since
// namespaces might be deleted. Reflecting the result of
// namesapce removals is complicated, so the cache might not be
// updated.
Ruby ruby = context.getRuntime();
RubyArray namespace_definitions = ruby.newArray();
if (doc == null)
return namespace_definitions;
if (doc instanceof HtmlDocument)
return namespace_definitions;
List<XmlNamespace> namespaces = ((XmlDocument) doc).getNamespaceCache().get(node);
for (XmlNamespace namespace : namespaces) {
namespace_definitions.append(namespace);
}
return namespace_definitions;
}
Aggregations