<commit_before>*&---------------------------------------------------------------------*
*&  Include           ZABAPGIT_GUI_ASSET_MANAGER
*&---------------------------------------------------------------------*

CLASS lcl_gui_asset_manager DEFINITION FINAL CREATE PRIVATE FRIENDS lcl_gui.
  PUBLIC SECTION.

    METHODS get_asset
      IMPORTING iv_asset_name  TYPE string
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_images
      RETURNING VALUE(rt_images) TYPE tt_web_assets.

  PRIVATE SECTION.

    METHODS get_inline_asset
      IMPORTING iv_asset_name  TYPE string
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_mime_asset
      IMPORTING iv_asset_name  TYPE c
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_inline_images
      RETURNING VALUE(rt_images) TYPE tt_web_assets.

ENDCLASS. "lcl_gui_asset_manager

CLASS lcl_gui_asset_manager IMPLEMENTATION.

  METHOD get_asset.

    DATA: lv_asset_name TYPE string,
          lv_mime_name  TYPE wwwdatatab-objid.

    lv_asset_name = to_upper( iv_asset_name ).

    CASE lv_asset_name.
      WHEN 'CSS_COMMON'.
        lv_mime_name = 'ZABAPGIT_CSS_COMMON'.
      WHEN 'JS_COMMON'.
        lv_mime_name = 'ZABAPGIT_JS_COMMON'.
      WHEN OTHERS.
        lcx_exception=>raise( |Improper resource name: { iv_asset_name }| ).
    ENDCASE.

    rv_data = get_mime_asset( lv_mime_name ).
    IF rv_data IS INITIAL. " Fallback to inline asset
      rv_data = get_inline_asset( lv_asset_name ).
    ENDIF.

    IF rv_data IS INITIAL.
      lcx_exception=>raise( |Failed to get GUI resource: { iv_asset_name }| ).
    ENDIF.

  ENDMETHOD.  " get_asset.

  METHOD get_mime_asset.

    DATA: ls_key    TYPE wwwdatatab,
          lv_size_c TYPE wwwparams-value,
          lv_size   TYPE i,
          lt_w3mime TYPE STANDARD TABLE OF w3mime.

    ls_key-relid = 'MI'.
    ls_key-objid = iv_asset_name.

    " Get exact file size
    CALL FUNCTION 'WWWPARAMS_READ'
      EXPORTING
        relid            = ls_key-relid
        objid            = ls_key-objid
        name             = 'filesize'
      IMPORTING
        value            = lv_size_c
      EXCEPTIONS
        entry_not_exists = 1.

    IF sy-subrc IS NOT INITIAL.
      RETURN.
    ENDIF.

    lv_size = lv_size_c.

    " Get binary data
    CALL FUNCTION 'WWWDATA_IMPORT'
      EXPORTING
        key               = ls_key
      TABLES
        mime              = lt_w3mime
      EXCEPTIONS
        wrong_object_type = 1
        import_error      = 2.

    IF sy-subrc IS NOT INITIAL.
      RETURN.
    ENDIF.

    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
      EXPORTING
        input_length = lv_size
      IMPORTING
        buffer       = rv_data
      TABLES
        binary_tab   = lt_w3mime
      EXCEPTIONS
        failed       = 1 ##FM_SUBRC_OK.

  ENDMETHOD.  " get_mime_asset.

  METHOD get_images.

    FIELD-SYMBOLS <image> LIKE LINE OF rt_images.

    rt_images = get_inline_images( ).

    " Convert to xstring
    LOOP AT rt_images ASSIGNING <image>.
      CALL FUNCTION 'SSFC_BASE64_DECODE'
        EXPORTING
          b64data = <image>-base64
        IMPORTING
          bindata = <image>-content
        EXCEPTIONS
          OTHERS  = 1.
      ASSERT sy-subrc = 0. " Image data error
    ENDLOOP.

  ENDMETHOD.  " get_images.

  METHOD get_inline_asset.

    DATA: lt_data TYPE ty_string_tt,
          lv_str  TYPE string.

    CASE iv_asset_name.
      WHEN 'CSS_COMMON'.
        " @@abapmerge include zabapgit_css_common.w3mi.data.css > _inline '$$'.
      WHEN 'JS_COMMON'.
        " @@abapmerge include zabapgit_js_common.w3mi.data.js > _inline '$$'.
      WHEN OTHERS.
        lcx_exception=>raise( |No inline resource: { iv_asset_name }| ).
    ENDCASE.

    CONCATENATE LINES OF lt_data INTO lv_str SEPARATED BY gc_newline.

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = lv_str
      IMPORTING
        buffer = rv_data
      EXCEPTIONS<commit_msg>fix syntax error in build<commit_after>*&---------------------------------------------------------------------*
*&  Include           ZABAPGIT_GUI_ASSET_MANAGER
*&---------------------------------------------------------------------*

CLASS lcl_gui_asset_manager DEFINITION FINAL CREATE PRIVATE FRIENDS lcl_gui.
  PUBLIC SECTION.

    METHODS get_asset
      IMPORTING iv_asset_name  TYPE string
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_images
      RETURNING VALUE(rt_images) TYPE tt_web_assets.

  PRIVATE SECTION.

    METHODS get_inline_asset
      IMPORTING iv_asset_name  TYPE string
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_mime_asset
      IMPORTING iv_asset_name  TYPE c
      RETURNING VALUE(rv_data) TYPE xstring
      RAISING   lcx_exception.

    METHODS get_inline_images
      RETURNING VALUE(rt_images) TYPE tt_web_assets.

ENDCLASS. "lcl_gui_asset_manager

CLASS lcl_gui_asset_manager IMPLEMENTATION.

  METHOD get_asset.

    DATA: lv_asset_name TYPE string,
          lv_mime_name  TYPE wwwdatatab-objid.

    lv_asset_name = to_upper( iv_asset_name ).

    CASE lv_asset_name.
      WHEN 'CSS_COMMON'.
        lv_mime_name = 'ZABAPGIT_CSS_COMMON'.
      WHEN 'JS_COMMON'.
        lv_mime_name = 'ZABAPGIT_JS_COMMON'.
      WHEN OTHERS.
        lcx_exception=>raise( |Improper resource name: { iv_asset_name }| ).
    ENDCASE.

    rv_data = get_mime_asset( lv_mime_name ).
    IF rv_data IS INITIAL. " Fallback to inline asset
      rv_data = get_inline_asset( lv_asset_name ).
    ENDIF.

    IF rv_data IS INITIAL.
      lcx_exception=>raise( |Failed to get GUI resource: { iv_asset_name }| ).
    ENDIF.

  ENDMETHOD.  " get_asset.

  METHOD get_mime_asset.

    DATA: ls_key    TYPE wwwdatatab,
          lv_size_c TYPE wwwparams-value,
          lv_size   TYPE i,
          lt_w3mime TYPE STANDARD TABLE OF w3mime.

    ls_key-relid = 'MI'.
    ls_key-objid = iv_asset_name.

    " Get exact file size
    CALL FUNCTION 'WWWPARAMS_READ'
      EXPORTING
        relid            = ls_key-relid
        objid            = ls_key-objid
        name             = 'filesize'
      IMPORTING
        value            = lv_size_c
      EXCEPTIONS
        entry_not_exists = 1.

    IF sy-subrc IS NOT INITIAL.
      RETURN.
    ENDIF.

    lv_size = lv_size_c.

    " Get binary data
    CALL FUNCTION 'WWWDATA_IMPORT'
      EXPORTING
        key               = ls_key
      TABLES
        mime              = lt_w3mime
      EXCEPTIONS
        wrong_object_type = 1
        import_error      = 2.

    IF sy-subrc IS NOT INITIAL.
      RETURN.
    ENDIF.

    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
      EXPORTING
        input_length = lv_size
      IMPORTING
        buffer       = rv_data
      TABLES
        binary_tab   = lt_w3mime
      EXCEPTIONS
        failed       = 1 ##FM_SUBRC_OK.

  ENDMETHOD.  " get_mime_asset.

  METHOD get_images.

    FIELD-SYMBOLS <image> LIKE LINE OF rt_images.

    rt_images = get_inline_images( ).

    " Convert to xstring
    LOOP AT rt_images ASSIGNING <image>.
      CALL FUNCTION 'SSFC_BASE64_DECODE'
        EXPORTING
          b64data = <image>-base64
        IMPORTING
          bindata = <image>-content
        EXCEPTIONS
          OTHERS  = 1.
      ASSERT sy-subrc = 0. " Image data error
    ENDLOOP.

  ENDMETHOD.  " get_images.

  DEFINE _inline.
    APPEND &1 TO lt_data.  
  END-OF-DEFINITION. 

  METHOD get_inline_asset.

    DATA: lt_data TYPE ty_string_tt,
          lv_str  TYPE string.

    IF 0 = 1.
 * used via abapmerge  
      _inline 'foo'.  
    ENDIF. 

    CASE iv_asset_name.
      WHEN 'CSS_COMMON'.
        " @@abapmerge include zabapgit_css_common.w3mi.data.css > _inline '$$'.
      WHEN 'JS_COMMON'.
        " @@abapmerge include zabapgit_js_common.w3mi.data.js > _inline '$$'.
      WHEN OTHERS.
        lcx_exception=>raise( |No inline resource: { iv_asset_name }| ).
    ENDCASE.

    CONCATENATE LINES OF lt_data INTO lv_str SEPARATED BY gc_newline.

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = lv_str
      IMPORTING
        buffer = rv_data
      EXCEPTIONS
{'fraction_non_alphanumeric': 0.09258585123164664, 'fraction_numerical': 0.004732435384055333, 'mean_word_length': 1.875785066294487, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7137391', 'n_tokens_mistral': 3023, 'n_tokens_neox': 2731, 'n_words': 637}