use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class EncodingHandler method get.
@JRubyMethod(name = "[]", meta = true)
public static IRubyObject get(ThreadContext context, IRubyObject _klass, IRubyObject keyObj) {
Ruby ruby = context.getRuntime();
String key = keyObj.toString();
String value = map.get(key);
if (value == null)
return ruby.getNil();
return new EncodingHandler(ruby, getNokogiriClass(ruby, "Nokogiri::EncodingHandler"), value);
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class HtmlElementDescription method sub_elements.
@JRubyMethod()
public IRubyObject sub_elements(ThreadContext context) {
Ruby ruby = context.getRuntime();
List<String> subs = findSubElements(element);
IRubyObject[] ary = new IRubyObject[subs.size()];
for (int i = 0; i < subs.size(); ++i) {
ary[i] = ruby.newString(subs.get(i));
}
return ruby.newArray(ary);
}
use of org.jruby.anno.JRubyMethod in project gocd by gocd.
the class HtmlSaxParserContext method parse_io.
@JRubyMethod(name = "io", meta = true)
public static IRubyObject parse_io(ThreadContext context, IRubyObject klazz, IRubyObject data, IRubyObject encoding) {
HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
ctx.initialize(context.getRuntime());
ctx.setInputSource(context, data, context.getRuntime().getNil());
String javaEncoding = findEncoding(context, encoding);
if (javaEncoding != null) {
ctx.getInputSource().setEncoding(javaEncoding);
}
return ctx;
}
use of org.jruby.anno.JRubyMethod in project nokogiri by sparklemotion.
the class HtmlDocument method rbNew.
@JRubyMethod(name = "new", meta = true, rest = true, required = 0)
public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
HtmlDocument htmlDocument;
try {
Document docNode = createNewDocument();
htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
htmlDocument.setDocumentNode(context, docNode);
} catch (Exception ex) {
throw context.getRuntime().newRuntimeError("couldn't create document: " + ex);
}
RuntimeHelpers.invoke(context, htmlDocument, "initialize", args);
return htmlDocument;
}
use of org.jruby.anno.JRubyMethod in project nokogiri by sparklemotion.
the class XsltStylesheet method parse_stylesheet_doc.
@JRubyMethod(meta = true, rest = true)
public static IRubyObject parse_stylesheet_doc(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
ensureFirstArgIsDocument(runtime, args[0]);
XmlDocument xmlDoc = (XmlDocument) args[0];
ensureDocumentHasNoError(context, xmlDoc);
Document doc = ((XmlDocument) xmlDoc.dup_implementation(context, true)).getDocument();
XsltStylesheet xslt = (XsltStylesheet) NokogiriService.XSLT_STYLESHEET_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
try {
xslt.init(args[1], doc);
} catch (TransformerConfigurationException ex) {
throw runtime.newRuntimeError("could not parse xslt stylesheet");
}
return xslt;
}
Aggregations