use of org.jruby.RubyString in project gocd by gocd.
the class HtmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
byte[] data = null;
if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
data = chunk.convertToString().getBytes();
} else {
terminateTask(context);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::SyntaxError"));
throw new RaiseException(xmlSyntaxError);
}
int errorCount0 = parserTask.getErrorCount();
;
if (isLast.isTrue()) {
IRubyObject document = invoke(context, this, "document");
invoke(context, document, "end_document");
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(new ByteArrayInputStream(data));
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.RubyString in project cucumber-jvm by cucumber.
the class JRubyStepDefinition method matchedArguments.
@Override
public List<Argument> matchedArguments(Step step) {
RubyString stepName = stepdefRunner.getRuntime().newString(step.getName());
IRubyObject arguments = stepdefRunner.callMethod("matched_arguments", stepName);
return toJava(arguments);
}
use of org.jruby.RubyString in project gocd by gocd.
the class XmlSaxPushParser method native_write.
@JRubyMethod
public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
try {
initialize_task(context);
} catch (IOException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
byte[] data = null;
if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
data = chunk.convertToString().getBytes();
} else {
terminateTask(context);
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
throw new RaiseException(xmlSyntaxError);
}
int errorCount0 = parserTask.getErrorCount();
;
if (isLast.isTrue()) {
IRubyObject document = invoke(context, this, "document");
invoke(context, document, "end_document");
terminateTask(context);
} else {
try {
Future<Void> task = stream.addChunk(new ByteArrayInputStream(data));
task.get();
} catch (ClosedStreamException ex) {
// this means the stream is closed, ignore this exception
} catch (Exception e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
terminateTask(context);
throw new RaiseException(parserTask.getLastError(), true);
}
return this;
}
use of org.jruby.RubyString in project gocd by gocd.
the class XmlNode method native_write_to.
/**
* @param args {IRubyObject io,
* IRubyObject encoding,
* IRubyObject indentString,
* IRubyObject options}
*/
@JRubyMethod(required = 4, visibility = Visibility.PRIVATE)
public IRubyObject native_write_to(ThreadContext context, IRubyObject[] args) {
IRubyObject io = args[0];
IRubyObject encoding = args[1];
IRubyObject indentString = args[2];
IRubyObject options = args[3];
String encString = encoding.isNil() ? null : rubyStringToString(encoding);
SaveContextVisitor visitor = new SaveContextVisitor((Integer) options.toJava(Integer.class), rubyStringToString(indentString), encString, isHtmlDoc(context), isFragment(), 0);
accept(context, visitor);
IRubyObject rubyString = null;
if (NokogiriHelpers.isUTF8(encString)) {
rubyString = stringOrNil(context.getRuntime(), visitor.toString());
} else {
try {
byte[] bytes = NokogiriHelpers.convertEncoding(Charset.forName(encString), visitor.toString());
rubyString = stringOrNil(context.getRuntime(), bytes);
} catch (CharacterCodingException e) {
throw context.getRuntime().newRuntimeError(e.getMessage());
}
}
RuntimeHelpers.invoke(context, io, "write", rubyString);
return io;
}
use of org.jruby.RubyString in project nokogiri by sparklemotion.
the class XsltStylesheet method getTemplatesFromStreamSource.
private Templates getTemplatesFromStreamSource() throws TransformerConfigurationException {
if (stylesheet instanceof RubyString) {
StringReader reader = new StringReader(stylesheet.asJavaString());
StreamSource xsltStreamSource = new StreamSource(reader);
return factory.newTemplates(xsltStreamSource);
}
return null;
}
Aggregations