use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
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 gocd by gocd.
the class XsltStylesheet method createDocumentFromString.
private IRubyObject createDocumentFromString(ThreadContext context, Ruby runtime, String stringResult) {
IRubyObject[] args = new IRubyObject[4];
args[0] = stringOrBlank(runtime, stringResult);
// url
args[1] = runtime.getNil();
// encoding
args[2] = runtime.getNil();
RubyClass parse_options = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::ParseOptions");
if (htmlish) {
args[3] = parse_options.getConstant("DEFAULT_HTML");
RubyClass htmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::HTML::Document");
return RuntimeHelpers.invoke(context, htmlDocumentClass, "parse", args);
} else {
args[3] = parse_options.getConstant("DEFAULT_XML");
RubyClass xmlDocumentClass = getNokogiriClass(runtime, "Nokogiri::XML::Document");
XmlDocument xmlDocument = (XmlDocument) RuntimeHelpers.invoke(context, xmlDocumentClass, "parse", args);
if (((Document) xmlDocument.getNode()).getDocumentElement() == null) {
RubyArray errors = (RubyArray) xmlDocument.getInstanceVariable("@errors");
RuntimeHelpers.invoke(context, errors, "<<", args[0]);
}
return xmlDocument;
}
}
use of org.jruby.runtime.builtin.IRubyObject 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.runtime.builtin.IRubyObject 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.runtime.builtin.IRubyObject 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;
}
Aggregations