I want to display a file inside a cl_gui_textedit
component with line breaks which causes me problems.
I am using the following code to initialize the component
DATA: lo_c_errorviewer TYPE REF TO cl_gui_custom_container.
CREATE OBJECT lo_c_errorviewer
EXPORTING
container_name = 'C_ERROR_MSG'.
CREATE OBJECT go_error_textedit
EXPORTING parent = lo_c_errorviewer.
go_error_textedit->set_toolbar_mode( 0 ).
go_error_textedit->set_statusbar_mode( 0 ).
After some XML processing with the iXML package the binary data of the file is available like this:
types: begin of xml_line,
data(256) type x,
end of xml_line.
data: xml_table type table of xml_line,
xml_size type i.
ostream = streamFactory->create_ostream_itable( xml_table ).
document->render( ostream = ostream recursive = 'X' ).
xml_size = ostream->get_num_written_raw( ).
This should contain line breaks if I am right. The ostream object has "pretty printing" turned on by default.
I searched the reference and the only way to pass the information is via
call method <c_textedit_control> - > set_text_as_stream
which expects a "Standard Table" of characters. How do I convert the data or pass it to the component?
It's easier if you render your XML document into a STRING
straight away, which you can then send to your CL_GUI_TEXTEDIT
control:
data xmlstring type string.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_cstring( xmlstring ).
document->render( ostream = ostream recursive = 'X' ).
...
data textedit type ref to cl_gui_textedit.
create object textedit
exporting
parent = container.
textedit->set_textstream( xmlstring ).
If you must render into binary data, then I suggest you use an XSTRING
for that:
data xmlxstring type xstring.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_xstring( xmlxstring ).
document->render( ostream = ostream recursive = 'X' ).
You can then convert the binary data to a string, using the CL_ABAP_CONV_IN_CE
class provided by SAP:
data converter type ref to cl_abap_conv_in_ce.
converter = cl_abap_conv_in_ce=>create( input = xmlxstring ).
data xmlstring type string.
converter->read( importing data = xmlstring ).
Which you can send to your CL_GUI_TEXTEDIT
control:
data textedit type ref to cl_gui_textedit.
create object textedit
exporting
parent = container.
textedit->set_textstream( xmlstring ).
Note that in case you run into encoding issues, you can set the encoding on the ostream object before rendering, and the converter object allows you to specify encoding when you create it.