use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class XmlComment method init.
@Override
protected void init(ThreadContext context, IRubyObject[] args) {
if (args.length < 2)
throw getRuntime().newArgumentError(args.length, 2);
IRubyObject doc = args[0];
IRubyObject text = args[1];
XmlDocument xmlDoc;
if (doc instanceof XmlDocument) {
xmlDoc = (XmlDocument) doc;
} else if (doc instanceof XmlNode) {
XmlNode xmlNode = (XmlNode) doc;
xmlDoc = (XmlDocument) xmlNode.document(context);
} else {
throw getRuntime().newArgumentError("first argument must be a XML::Document or XML::Node");
}
if (xmlDoc != null) {
Document document = xmlDoc.getDocument();
Node node = document.createComment(rubyStringToString(text));
setNode(context, node);
}
}
use of org.jruby.runtime.builtin.IRubyObject in project nokogiri by sparklemotion.
the class HtmlDocument method getInternalSubset.
public IRubyObject getInternalSubset(ThreadContext context) {
IRubyObject internalSubset = super.getInternalSubset(context);
if (internalSubset.isNil()) {
internalSubset = XmlDtd.newEmpty(context.getRuntime(), getDocument(), context.getRuntime().newString(DEFAULT_CONTENT_TYPE), context.getRuntime().newString(DEFAULT_PUBLIC_ID), context.getRuntime().newString(DEFAULT_SYTEM_ID));
setInternalSubset(internalSubset);
}
return internalSubset;
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XmlDocument method getInternalSubset.
public IRubyObject getInternalSubset(ThreadContext context) {
IRubyObject dtd = (IRubyObject) node.getUserData(DTD_INTERNAL_SUBSET);
if (dtd == null) {
Document document = getDocument();
if (document.getUserData(XmlDocument.DTD_RAW_DOCUMENT) != null) {
dtd = XmlDtd.newFromInternalSubset(context.getRuntime(), document);
} else if (document.getDoctype() != null) {
DocumentType docType = document.getDoctype();
IRubyObject name, publicId, systemId;
name = publicId = systemId = context.getRuntime().getNil();
if (docType.getName() != null) {
name = context.getRuntime().newString(docType.getName());
}
if (docType.getPublicId() != null) {
publicId = context.getRuntime().newString(docType.getPublicId());
}
if (docType.getSystemId() != null) {
systemId = context.getRuntime().newString(docType.getSystemId());
}
dtd = XmlDtd.newEmpty(context.getRuntime(), document, name, publicId, systemId);
} else {
dtd = context.getRuntime().getNil();
}
setInternalSubset(dtd);
}
return dtd;
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XmlDocumentFragment method trim.
private static IRubyObject trim(ThreadContext context, XmlDocument xmlDocument, RubyString str) {
// checks whether schema is given. if exists, allows whitespace processing to a parser
Document document = (Document) xmlDocument.node;
if (document.getDoctype() != null)
return str;
// strips trailing \n off forcefully
// not to return new object in case of no chomp needed, chomp! is used here.
IRubyObject result;
if (context.getRuntime().is1_9())
result = str.chomp_bang19(context);
else
result = str.chomp_bang(context);
return result.isNil() ? str : result;
}
use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.
the class XmlText method accept.
@Override
public void accept(ThreadContext context, SaveContextVisitor visitor) {
visitor.enter((Text) node);
Node child = node.getFirstChild();
while (child != null) {
IRubyObject nokoNode = getCachedNodeOrCreate(context.getRuntime(), child);
if (nokoNode instanceof XmlNode) {
XmlNode cur = (XmlNode) nokoNode;
cur.accept(context, visitor);
} else if (nokoNode instanceof XmlNamespace) {
XmlNamespace cur = (XmlNamespace) nokoNode;
cur.accept(context, visitor);
}
child = child.getNextSibling();
}
visitor.leave(node);
}
Aggregations