use of nokogiri.internals.SaveContextVisitor 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 nokogiri.internals.SaveContextVisitor in project nokogiri by sparklemotion.
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(RubyFixnum.fix2int(options), rubyStringToString(indentString), encString, isHtmlDoc(context), isFragment(), 0);
accept(context, visitor);
final IRubyObject rubyString;
if (NokogiriHelpers.isUTF8(encString)) {
rubyString = convertString(context.getRuntime(), visitor.getInternalBuffer());
} else {
ByteBuffer bytes = convertEncoding(Charset.forName(encString), visitor.getInternalBuffer());
ByteList str = new ByteList(bytes.array(), bytes.arrayOffset(), bytes.remaining());
rubyString = RubyString.newString(context.getRuntime(), str);
}
RuntimeHelpers.invoke(context, io, "write", rubyString);
return io;
}
Aggregations