*&---------------------------------------------------------------------**& Include ZWEIBO_01*&---------------------------------------------------------------------*TYPES: BEGIN OF ty_result, name TYPE string, value TYPE string, END OF ty_result.TYPES: tt_result TYPE STANDARD TABLE OF ty_result.class lcl_analyzer DEFINITION create private. PUBLIC SECTION. METHODS: analyze IMPORTING iv_company_name TYPE string iv_text TYPE string EXPORTING ev_result TYPE string. CLASS-METHODS:get_instance returning value(RO_INSTANCE) type ref to lcl_analyzer. PRIVATE SECTION. class-data mo_instance type ref to lcl_analyzer . data: mr_TYPE REF TO if_ CONSTANTS: gc_baseurl TYPE string VALUE ' METHODS: constructor, sendrequest IMPORTING iv_company_name TYPE string iv_text TYPE string EXPORTING ev_text TYPE string.ENDCLASS.class lcl_analyzer IMPLEMENTATION. method analyze. sendrequest( EXPORTING iv_company_name = iv_company_name iv_text = iv_text IMPORTING ev_text = ev_result ). ENDMETHOD. method constructor. endmethod. method sendrequest. DATA: lv_url TYPE string, lv_sysubrc TYPE sysubrc, lv_error TYPE string, lv_TYPE i. lv_url = gc_baseurl && cl_iv_text ). CALL METHOD cl_ EXPORTING url = lv_url "proxy_host = 'PROXY' "proxy_service = '8080' "ssl_id = 'ANONYM' IMPORTING client = mr_ EXCEPTIONS argument_not_found = 1 plugin_not_active = 2 internal_error = 3 OTHERS = 4. CHECK sy-subrc = 0. CALL METHOD mr_'GET' ). CALL METHOD mr_ EXCEPTIONS = 1 = 2 = 3. IF sy-subrc <> 0. CALL METHOD mr_ IMPORTING code = lv_sysubrc message = lv_error. mr_). RETURN. ENDIF. CALL METHOD mr_ EXCEPTIONS = 1 = 2 = 3. IF sy-subrc <> 0. CALL METHOD mr_ IMPORTING code = lv_sysubrc message = lv_error. mr_). RETURN. ENDIF. ev_text = mr_). mr_). endmethod. method get_instance. IF mo_instance IS NOT BOUND. CREATE OBJECT mo_instance. ENDIF. ro_instance = mo_instance. endmethod.ENDCLASS.CLASS lcl_weibo_tool DEFINITION. PUBLIC SECTION. METHODS: send FOR EVENT FUNCTION_SELECTED OF CL_GUI_TOOLBAR importing !FCODE, display IMPORTING iv_text TYPE string, constructor IMPORTING iv_editor TYPE REF TO cl_gui_textedit iv_alv TYPE REF TO CL_GUI_ALV_GRID, set_table CHANGING ct_table TYPE tt_result, get_formatted_string IMPORTING it_table TYPE any table EXPORTING ev_text TYPE string. PRIVATE SECTION. TYPES: BEGIN OF mytable_line, line(1024) TYPE c, END OF mytable_line. TYPES: tt_mytable TYPE TABLE OF mytable_line. DATA: lt_mytable TYPE tt_mytable. DATA: mr_editor TYPE REF TO cl_gui_textedit, mr_alv TYPE REF TO CL_GUI_ALV_GRID, mr_result TYPE REF TO data. CONSTANTS: gc_filter TYPE string VALUE ' '.ENDCLASS.CLASS lcl_weibo_tool IMPLEMENTATION. METHOD send. DATA: lv_text TYPE string, ls_line TYPE mytable_line, lv_result TYPE string. CHECK fcode = 'CHECK'. CLEAR: lt_mytable,lv_text. cl_gui_cfw=>flush( ). mr_editor->get_text_as_stream( IMPORTING text = lt_mytable ). CHECK lt_mytable IS NOT INITIAL. get_formatted_string( EXPORTING it_table = lt_mytable IMPORTING ev_text = lv_text ). lcl_analyzer=>get_instance( )->analyze( EXPORTING iv_company_name = 'dummy' iv_text = lv_text IMPORTING ev_result = lv_result ). display( EXPORTING iv_text = lv_result ). ENDMETHOD. method set_table. GET REFERENCE OF ct_table INTO mr_result. endmethod. method display. FIELD-SYMBOLS:
TYPE tt_result. ASSIGN mr_result->* TO
. CLEAR:
. DATA: lt_raw TYPE string_table, lv_line TYPE string, lv_len TYPE i, ls_line TYPE ty_result. SPLIT iv_text AT gc_filter INTO TABLE lt_raw. LOOP AT lt_raw INTO lv_line. ls_line-name = lv_line+0(5). lv_len = strlen( lv_line ) - 6. ls_line-value = lv_line+6(lv_len). APPEND ls_line TO
. ENDLOOP. mr_alv->refresh_table_display( ). endmethod. METHOD constructor. mr_editor = iv_editor. mr_alv = iv_alv. ENDMETHOD. method get_formatted_string. FIELD-SYMBOLS: TYPE mytable_line. DATA: lv_text TYPE string. LOOP AT it_table ASSIGNING . CONCATENATE lv_text -line INTO lv_text. ENDLOOP. ev_text = lv_text. endmethod.ENDCLASS.
暂时没有评论,来抢沙发吧~