use of org.jruby.RubyClass in project gocd by gocd.
the class NokogiriService method createDocuments.
private void createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node) {
RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
xmlDocument.defineAnnotatedMethods(XmlDocument.class);
//RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
}
use of org.jruby.RubyClass 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.RubyClass in project gocd by gocd.
the class XmlNode method rbNew.
/**
* Allocate a new object, perform initialization, call that
* object's initialize method, and call any block passing the
* object as the only argument. If <code>cls</code> is
* Nokogiri::XML::Node, creates a new Nokogiri::XML::Element
* instead.
*
* This static method seems to be inherited, strangely enough.
* E.g. creating a new XmlAttr from Ruby code calls this method if
* XmlAttr does not define its own 'new' method.
*
* Since there is some Java bookkeeping that always needs to
* happen, we don't define the 'initialize' method in Java because
* we'd have to count on subclasses calling 'super'.
*
* The main consequence of this is that every subclass needs to
* define its own 'new' method.
*
* As a convenience, this method does the following:
*
* <ul>
*
* <li>allocates a new object using the allocator assigned to
* <code>cls</code></li>
*
* <li>calls the Java method init(); subclasses can override this,
* otherwise they should implement a specific 'new' method</li>
*
* <li>invokes the Ruby initializer</li>
*
* <li>if a block is given, calls the block with the new node as
* the argument</li>
*
* </ul>
*
* -pmahoney
*/
@JRubyMethod(name = "new", meta = true, rest = true)
public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args, Block block) {
Ruby ruby = context.getRuntime();
RubyClass klazz = (RubyClass) cls;
if (cls.equals(getNokogiriClass(ruby, "Nokogiri::XML::Node"))) {
klazz = getNokogiriClass(ruby, "Nokogiri::XML::Element");
}
XmlNode xmlNode = (XmlNode) klazz.allocate();
xmlNode.init(context, args);
xmlNode.callInit(args, block);
if (xmlNode.node == null)
context.getRuntime().newRuntimeError("NODE IS NULL");
if (block.isGiven())
block.call(context, xmlNode);
return xmlNode;
}
use of org.jruby.RubyClass in project gocd by gocd.
the class NokogiriService method createNokogiriModule.
private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {
;
RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
encHandler.defineAnnotatedMethods(EncodingHandler.class);
}
use of org.jruby.RubyClass in project gocd by gocd.
the class NokogiriService method createXmlModule.
private RubyClass createXmlModule(Ruby ruby, RubyModule xmlModule) {
RubyClass node = xmlModule.defineClassUnder("Node", ruby.getObject(), XML_NODE_ALLOCATOR);
node.defineAnnotatedMethods(XmlNode.class);
RubyClass attr = xmlModule.defineClassUnder("Attr", node, XML_ATTR_ALLOCATOR);
attr.defineAnnotatedMethods(XmlAttr.class);
RubyClass attrDecl = xmlModule.defineClassUnder("AttributeDecl", node, XML_ATTRIBUTE_DECL_ALLOCATOR);
attrDecl.defineAnnotatedMethods(XmlAttributeDecl.class);
RubyClass characterData = xmlModule.defineClassUnder("CharacterData", node, null);
RubyClass comment = xmlModule.defineClassUnder("Comment", characterData, XML_COMMENT_ALLOCATOR);
comment.defineAnnotatedMethods(XmlComment.class);
RubyClass text = xmlModule.defineClassUnder("Text", characterData, XML_TEXT_ALLOCATOR);
text.defineAnnotatedMethods(XmlText.class);
RubyModule cdata = xmlModule.defineClassUnder("CDATA", text, XML_CDATA_ALLOCATOR);
cdata.defineAnnotatedMethods(XmlCdata.class);
RubyClass dtd = xmlModule.defineClassUnder("DTD", node, XML_DTD_ALLOCATOR);
dtd.defineAnnotatedMethods(XmlDtd.class);
RubyClass documentFragment = xmlModule.defineClassUnder("DocumentFragment", node, XML_DOCUMENT_FRAGMENT_ALLOCATOR);
documentFragment.defineAnnotatedMethods(XmlDocumentFragment.class);
RubyClass element = xmlModule.defineClassUnder("Element", node, XML_ELEMENT_ALLOCATOR);
element.defineAnnotatedMethods(XmlElement.class);
RubyClass elementContent = xmlModule.defineClassUnder("ElementContent", ruby.getObject(), XML_ELEMENT_CONTENT_ALLOCATOR);
elementContent.defineAnnotatedMethods(XmlElementContent.class);
RubyClass elementDecl = xmlModule.defineClassUnder("ElementDecl", node, XML_ELEMENT_DECL_ALLOCATOR);
elementDecl.defineAnnotatedMethods(XmlElementDecl.class);
RubyClass entityDecl = xmlModule.defineClassUnder("EntityDecl", node, XML_ENTITY_DECL_ALLOCATOR);
entityDecl.defineAnnotatedMethods(XmlEntityDecl.class);
entityDecl.defineConstant("INTERNAL_GENERAL", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL));
entityDecl.defineConstant("EXTERNAL_GENERAL_PARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_PARSED));
entityDecl.defineConstant("EXTERNAL_GENERAL_UNPARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_UNPARSED));
entityDecl.defineConstant("INTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PARAMETER));
entityDecl.defineConstant("EXTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_PARAMETER));
entityDecl.defineConstant("INTERNAL_PREDEFINED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PREDEFINED));
RubyClass entref = xmlModule.defineClassUnder("EntityReference", node, XML_ENTITY_REFERENCE_ALLOCATOR);
entref.defineAnnotatedMethods(XmlEntityReference.class);
RubyClass namespace = xmlModule.defineClassUnder("Namespace", ruby.getObject(), XML_NAMESPACE_ALLOCATOR);
namespace.defineAnnotatedMethods(XmlNamespace.class);
RubyClass nodeSet = xmlModule.defineClassUnder("NodeSet", ruby.getObject(), XML_NODESET_ALLOCATOR);
nodeSet.defineAnnotatedMethods(XmlNodeSet.class);
RubyClass pi = xmlModule.defineClassUnder("ProcessingInstruction", node, XML_PROCESSING_INSTRUCTION_ALLOCATOR);
pi.defineAnnotatedMethods(XmlProcessingInstruction.class);
RubyClass reader = xmlModule.defineClassUnder("Reader", ruby.getObject(), XML_READER_ALLOCATOR);
reader.defineAnnotatedMethods(XmlReader.class);
RubyClass schema = xmlModule.defineClassUnder("Schema", ruby.getObject(), XML_SCHEMA_ALLOCATOR);
schema.defineAnnotatedMethods(XmlSchema.class);
RubyClass relaxng = xmlModule.defineClassUnder("RelaxNG", schema, XML_RELAXNG_ALLOCATOR);
relaxng.defineAnnotatedMethods(XmlRelaxng.class);
RubyClass xpathContext = xmlModule.defineClassUnder("XPathContext", ruby.getObject(), XML_XPATHCONTEXT_ALLOCATOR);
xpathContext.defineAnnotatedMethods(XmlXpathContext.class);
return node;
}
Aggregations