*&---------------------------------------------------------------------*
*&  Include           ZSOFTCOPY_PACK                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& This file is part of ZSOFTCOPY.                                     *
*&                                                                     *
*& ZSOFTCOPY is free software: you can redistribute it and/or modify   *
*& it under the terms of the GNU General Public License as published   *
*& by the Free Software Foundation, either version 3 of the License,   *
*& or any later version.                                               *
*&                                                                     *
*& ZSOFTCOPY is distributed in the hope that it will be useful,        *
*& but WITHOUT ANY WARRANTY; without even the implied warranty of      *
*& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
*& GNU General Public License for more details.                        *
*&                                                                     *
*& You should have received a copy of the GNU General Public License   *
*& along with ZDOWNLOAD. If not, see <http://www.gnu.org/licenses/>.   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&  Author:     Ruediger von Creytz     ruediger.creytz@globalbit.net  *
*&  Copyright:  globalBIT, LLC          http://www.globalbit.net       *
*&                                                                     *
*&---------------------------------------------------------------------*


*-----------------------------------------------------------------------
* pack
*-----------------------------------------------------------------------
FORM pack.
*DEVCLASS
  PERFORM pack_r3tr_devc.

ENDFORM.                    "pack


*-----------------------------------------------------------------------
* pack_r3tr_devc                                Devclass
*-----------------------------------------------------------------------
FORM pack_r3tr_devc.

  DATA:
  lo_package TYPE REF TO if_package,
  l_as4text TYPE as4text,
  ls_attributes TYPE st_attributes,
  ls_ti TYPE st_textinput,
  lt_package_properties TYPE it_textinput,
  lt_transport_attributes TYPE it_textinput,
  l_intf_system TYPE srcsystem,
  l_pack_system TYPE srcsystem,
  lt_ref_interface TYPE tpak_package_interface_list,
  ls_ref_interface TYPE tpak_package_interface_ref,
  lt_interface TYPE it_pack_intf,
  ls_interface TYPE st_pack_intf,
  lt_ref_perm TYPE tpak_permission_to_use_list,
  ls_ref_perm TYPE tpak_permission_to_use_ref_typ,
  lt_perm TYPE it_pack_perm,
  ls_perm TYPE st_pack_perm,
  lt_ref_sub TYPE scompaklis,
  ls_ref_sub TYPE REF TO if_package,
  lt_sub TYPE it_pack_sub,
  ls_sub TYPE st_pack_sub,
  lt_tabstrip TYPE it_tabstrip,
  lt_html TYPE it_string.

  FIELD-SYMBOLS:
  <ls_tabstrip> TYPE st_tabstrip,
  <l_srv_check> TYPE ANY,
  <l_cli_check> TYPE ANY,
  <l_deleted_in_memory> TYPE ANY.

  CALL METHOD cl_package_factory=>load_package
    EXPORTING
      i_package_name = gs_tdevc-devclass
    IMPORTING
      e_package      = lo_package.

*general attributes
  PERFORM get_devclass
    USING
      gs_tdevc-devclass
    CHANGING
      l_as4text.
  ls_attributes-descript = l_as4text.
  ls_attributes-person_responsible = gs_tdevc-as4user.
  PERFORM get_user
    USING
      gs_tdevc-as4user
    CHANGING
      ls_attributes-person_responsible_text.
  ls_attributes-author = gs_tdevc-created_by.
  PERFORM get_user
    USING
      gs_tdevc-created_by
    CHANGING
      ls_attributes-author_text.
  PERFORM get_date
    USING
      gs_tdevc-created_on
    CHANGING
      ls_attributes-date_created.
  ls_attributes-bname = gs_tdevc-changed_by.
  PERFORM get_user
    USING
      gs_tdevc-changed_by
    CHANGING
      ls_attributes-name_text.
  PERFORM get_date
    USING
      gs_tdevc-changed_on
    CHANGING
      ls_attributes-date_last_changed.
  ls_attributes-application_component = gs_tdevc-component.
*package properties
  CLEAR ls_ti.
  ls_ti-name = txt_main_package.
  ls_ti-flag = abap_true.
  IF gs_tdevc-mainpack = 'X'.
    ls_ti-value = abap_true.
  ENDIF.
  APPEND ls_ti TO lt_package_properties.
  CLEAR ls_ti.
  ls_ti-name = txt_surrounding_package.
  ls_ti-input = abap_true.
  ls_ti-value = gs_tdevc-parentcl.
  APPEND ls_ti TO lt_package_properties.
  ls_ti-name = txt_allowed_object_types.
  ls_ti-input = abap_true.
  PERFORM get_dom_value_text
    USING
      'PACKTYPE'
      gs_tdevc-packtype
    CHANGING
      ls_ti-value.
  APPEND ls_ti TO lt_package_properties.
  CLEAR ls_ti.
  ls_ti-name = txt_package_not_extendable.
  ls_ti-flag = abap_true.
  ls_ti-value = gs_tdevc-restricted.
  APPEND ls_ti TO lt_package_properties.
  ASSIGN COMPONENT 'SRV_CHECK' OF STRUCTURE gs_tdevc TO <l_srv_check>.
  IF <l_srv_check> IS ASSIGNED.
    CLEAR ls_ti.
    ls_ti-name = txt_package_check_as_server.
    ls_ti-flag = abap_true.
    ls_ti-value = <l_srv_check>.
    APPEND ls_ti TO lt_package_properties.
    UNASSIGN <l_srv_check>.
  ENDIF.
  ASSIGN COMPONENT 'CLI_CHECK' OF STRUCTURE gs_tdevc TO <l_cli_check>.
  IF <l_cli_check> IS ASSIGNED.
    CLEAR ls_ti.
    ls_ti-name = txt_package_check_as_client.
    ls_ti-flag = abap_true.
    ls_ti-value = <l_cli_check>.
    APPEND ls_ti TO lt_package_properties.
    UNASSIGN <l_cli_check>.
  ENDIF.

*transport attributes
  CLEAR ls_ti.
  ls_ti-name = txt_transport_layer.
  ls_ti-input = abap_true.
  ls_ti-value = gs_tdevc-pdevclass.
  APPEND ls_ti TO lt_transport_attributes.
  CLEAR ls_ti.
  ls_ti-name = txt_software_component.
  ls_ti-input = abap_true.
  ls_ti-value_double_length = abap_true.
  ls_ti-value = gs_tdevc-dlvunit.
  APPEND ls_ti TO lt_transport_attributes.
  CLEAR ls_ti.
  ls_ti-name = txt_changes_are_recorded.
  ls_ti-flag = abap_true.
  ls_ti-value = gs_tdevc-korrflag.
  APPEND ls_ti TO lt_transport_attributes.

*package interfaces
  CALL METHOD lo_package->get_origin_system
    IMPORTING
      e_origin_system = l_pack_system
    EXCEPTIONS
      OTHERS          = 1.

  CALL METHOD lo_package->get_interfaces
    IMPORTING
      e_package_interfaces = lt_ref_interface
    EXCEPTIONS
      OTHERS               = 1.
  LOOP AT lt_ref_interface INTO ls_ref_interface.
    UNASSIGN <l_deleted_in_memory>.
    ASSIGN COMPONENT 'DELETED_IN_MEMORY' OF STRUCTURE
      ls_ref_interface TO <l_deleted_in_memory>.
    IF <l_deleted_in_memory> IS ASSIGNED
    AND <l_deleted_in_memory> = abap_true.
      CONTINUE.
    ENDIF.
    CLEAR ls_interface.
    ls_interface-intf_name = ls_ref_interface->interface_name.
    ls_interface-descript = ls_ref_interface->short_text.

    CALL METHOD ls_ref_interface->get_origin_system
      IMPORTING
        e_origin_system = l_intf_system
      EXCEPTIONS
        OTHERS          = 1.
    IF l_pack_system <> l_intf_system.
      ls_interface-forsys = txt_foreign_source_system.
    ENDIF.
    APPEND ls_interface TO lt_interface.
  ENDLOOP.

*use access
  CALL METHOD lo_package->get_permissions_to_use
    IMPORTING
      e_permissions = lt_ref_perm
    EXCEPTIONS
      OTHERS        = 1.
  LOOP AT lt_ref_perm INTO ls_ref_perm.
    UNASSIGN <l_deleted_in_memory>.
    ASSIGN COMPONENT 'DELETED_IN_MEMORY' OF STRUCTURE ls_ref_perm
      TO <l_deleted_in_memory>.
    IF <l_deleted_in_memory> IS ASSIGNED
    AND <l_deleted_in_memory> = abap_true.
      CONTINUE.
    ENDIF.
    CLEAR ls_perm.
    ls_perm-pack_name = ls_ref_perm->publisher_package_name.
    ls_perm-intf_name = ls_ref_perm->package_interface_name.
    PERFORM get_dom_value_text
      USING
        'ERRSEVRTY'
        ls_ref_perm->error_severity
      CHANGING
        ls_perm-err_sever.
    APPEND ls_perm TO lt_perm.
  ENDLOOP.

*packages included
  CALL METHOD lo_package->get_sub_packages
    IMPORTING
      e_sub_packages = lt_ref_sub
    EXCEPTIONS
      OTHERS         = 1.
  LOOP AT lt_ref_sub INTO ls_ref_sub.
    UNASSIGN <l_deleted_in_memory>.
    ASSIGN COMPONENT 'DELETED_IN_MEMORY' OF STRUCTURE ls_ref_sub
      TO <l_deleted_in_memory>.
    IF <l_deleted_in_memory> IS ASSIGNED
    AND <l_deleted_in_memory> = abap_true.
      CONTINUE.
    ENDIF.
    CLEAR ls_sub.
    ls_sub-devclass = ls_ref_sub->package_name.
    ls_sub-ctext = ls_ref_sub->short_text.
    APPEND ls_sub TO lt_sub.
  ENDLOOP.

*tabstrip
  PERFORM get_tabstrip
    USING 'PACK_DEVC' space
    CHANGING lt_tabstrip.
  LOOP AT lt_tabstrip ASSIGNING <ls_tabstrip>.
    <ls_tabstrip>-empty = abap_false.
    CASE <ls_tabstrip>-id.
      WHEN 'INTERFACE'.
        IF lt_interface IS INITIAL.
          <ls_tabstrip>-empty = abap_true.
        ENDIF.
      WHEN 'PERM'.
        IF lt_perm IS INITIAL.
          <ls_tabstrip>-empty = abap_true.
        ENDIF.
      WHEN 'SUB'.
        IF lt_sub IS INITIAL.
          <ls_tabstrip>-empty = abap_true.
        ENDIF.
    ENDCASE.
  ENDLOOP.

**HTML
  PERFORM html_main_header
    USING
      tpt_pack_devc
      txt_package
      gs_tdevc-devclass
      txt_saved
      space
      space
      space  " 'makeDivSize(''SOURCECODE'');'
      lt_tabstrip
      gt_link
    CHANGING
      lt_html.

* attributes
  PERFORM html_add_attributes_4
    USING
      ls_attributes
      txt_package_properties
      lt_package_properties
      txt_transport_attributes
      lt_transport_attributes
      'ATTRIBUTES'
      abap_true
    CHANGING
      lt_html.
* interface
  IF NOT lt_interface IS INITIAL
  OR g_empty_tab = gc_empty_tab_display.
    PERFORM html_add_table
      USING
        'DEVC_INTF'
        lt_interface
        lt_interface
        'INTERFACE'
        abap_false
      CHANGING
        lt_html.
  ENDIF.
* perm
  IF NOT lt_perm IS INITIAL
  OR g_empty_tab = gc_empty_tab_display.
    PERFORM html_add_table
      USING
        'DEVC_PERM'
        lt_perm
        lt_perm
        'PERM'
        abap_false
      CHANGING
        lt_html.
  ENDIF.
* sub
  IF NOT lt_sub IS INITIAL
  OR g_empty_tab = gc_empty_tab_display.
    PERFORM html_add_table
      USING
        'DEVC_SUB'
        lt_sub
        lt_sub
        'SUB'
        abap_false
      CHANGING
        lt_html.
  ENDIF.
*
  PERFORM html_main_footer
    USING
      lt_html.

  PERFORM download
    USING
      lt_html
      'R3TR'
      'DEVC'
      gs_tdevc-devclass
      gc_extension_htm
      abap_false.

ENDFORM.                                                    "r3tr_devc
