use of org.jruby.RubyClass in project gocd by gocd.
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;
}
use of org.jruby.RubyClass in project gocd by gocd.
the class HtmlSaxParserContext method parse_memory.
@JRubyMethod(name = "memory", meta = true)
public static IRubyObject parse_memory(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());
String javaEncoding = findEncoding(context, encoding);
if (javaEncoding != null) {
String input = applyEncoding(rubyStringToString(data), javaEncoding);
ByteArrayInputStream istream = new ByteArrayInputStream(input.getBytes());
ctx.setInputSource(istream);
ctx.getInputSource().setEncoding(javaEncoding);
}
return ctx;
}
use of org.jruby.RubyClass in project gocd by gocd.
the class HtmlSaxParserContext method parse_file.
@JRubyMethod(name = "file", meta = true)
public static IRubyObject parse_file(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.setInputSourceFile(context, data);
String javaEncoding = findEncoding(context, encoding);
if (javaEncoding != null) {
ctx.getInputSource().setEncoding(javaEncoding);
}
return ctx;
}
use of org.jruby.RubyClass in project gocd by gocd.
the class NokogiriService method createSyntaxErrors.
private void createSyntaxErrors(Ruby ruby, RubyModule nokogiri, RubyModule xmlModule) {
RubyClass syntaxError = nokogiri.defineClassUnder("SyntaxError", ruby.getStandardError(), ruby.getStandardError().getAllocator());
RubyClass xmlSyntaxError = xmlModule.defineClassUnder("SyntaxError", syntaxError, XML_SYNTAXERROR_ALLOCATOR);
xmlSyntaxError.defineAnnotatedMethods(XmlSyntaxError.class);
}
use of org.jruby.RubyClass in project gocd by gocd.
the class NokogiriService method init.
private void init(Ruby ruby) {
RubyModule nokogiri = ruby.defineModule("Nokogiri");
RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");
createJavaLibraryVersionConstants(ruby, nokogiri);
createNokogiriModule(ruby, nokogiri);
createSyntaxErrors(ruby, nokogiri, xmlModule);
RubyClass xmlNode = createXmlModule(ruby, xmlModule);
createHtmlModule(ruby, htmlModule);
createDocuments(ruby, xmlModule, htmlModule, xmlNode);
createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
createXsltModule(ruby, xsltModule);
nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
}
Aggregations