Creating a BSP Extension Element for editing in Word
This weblog will show you how to create a BSP Element that makes use of Microsofts DSO Framer to embed word into a BSP page. This makes it possible to edit server side word documents using a BSP page.
The following screen capture shows the word document with tables and embedded images.
The example is using Word XML format for the document (WML). The initial value for the document is determined in the controller.
The class has a single attribute.
ms_data type string private
This is used to store the current data.
The two redefined methods.
The do_request method creates the view and initialises the data.
DATA: lv_comp TYPE string,
lo_view TYPE REF TO if_bsp_page.
If the data is initial then use a default hello world
IF ms_data IS INITIAL.
‘<w:t>Hello, word World.</w:t>’
INTO ms_data SEPARATED BY cl_abap_char_utilities=>cr_lf.
Create and display the views
lo_view = create_view( view_name = ‘editorview.htm’ ).
lo_view->set_attribute( name = ‘ms_document’ value = ms_data ).
call_view( lo_view ).
The do_handle_data method retrieves the changed data and stores it in an instance attribute of the controller.
DATA lv_line LIKE LINE OF form_fields.
Get the hiddendata field from the form processing.
READ TABLE form_fields INTO lv_line WITH KEY name =’hiddendata’.
IF sy-subrc EQ 0.
ms_data = lv_line-value.
The BSP element is responsible for creating the HTML that renders the control on the display.
Create the Element with the a single attribute
A single attribute containing the document data is used.
This is the main part of the example. It generates the HTML and stores the data for the control in an XML island. The island is one possible approach to the data, setting the value for a form field is another option, but this may require encoding of the data for storage.
The example also includes 2 delays. There may be an event that can be used to load the data to the framer once the control loads, but as yet we haven’t found it. For the sake of this example a delay is used between laoding the control and setting its data. In practice this is really bad as a race condition is created. However for the sake of demonstration it works for now.
lv_wordml TYPE string,
lv_id TYPE string,
lv_string TYPE string.
The ID of the form field for processing the data.
lv_id = ‘”HIDDENDATA”‘.
An XML data island is used to store the data. This could also be directly assigned to the hidden field
Insert two VBScript functions and XML data island into page
INTO lv_string SEPARATED BY cl_abap_char_utilities=>cr_lf.
Insert the control for the DSO framer
print_string( lv_string ).
This adds the script to the form validation. This can also be achieved via an onClientClick
for the button
DATA: lo_formx TYPE REF TO cl_htmlb_form,
lv_text TYPE string.
lo_formx ?= me->get_class_named_parent( ‘CL_HTMLB_FORM’ ).
IF lo_formx IS NOT INITIAL.
CONCATENATE lo_formx->setup_validation ‘ if (!ZjaDoValidate( )) return false; ‘”#EC NOTEXT
With this in place and the DSO framer installed on your PC (I guess this won’t work on my Mac) you can run the BSP application and make edits to the document. I had no problem creating tables and embedding images, such is the beauty of WML.
Thanks also go to Jesse Bush and Steve Keyes for finding the DSP framer and figuring out how to use it.+