forked from abapGit/abapGit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zabapgit.abap
6501 lines (4990 loc) · 196 KB
/
zabapgit.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
REPORT zabapgit.
* See https://github.com/larshp/abapGit/
CONSTANTS: gc_version TYPE string VALUE 'v0.2-alpha'. "#EC NOTEXT
********************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Lars Hvam Petersen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
********************************************************************************
TYPES: t_type TYPE c LENGTH 6,
t_bitbyte TYPE c LENGTH 8,
t_adler32 TYPE x LENGTH 4,
t_sha1 TYPE x LENGTH 20,
t_unixtime TYPE c LENGTH 16.
TYPES: BEGIN OF st_node,
chmod TYPE string,
name TYPE string,
sha1 TYPE t_sha1,
END OF st_node.
TYPES: tt_nodes TYPE STANDARD TABLE OF st_node WITH DEFAULT KEY.
TYPES: BEGIN OF st_object,
sha1 TYPE t_sha1,
type TYPE t_type,
data TYPE xstring,
END OF st_object.
TYPES: tt_objects TYPE STANDARD TABLE OF st_object WITH DEFAULT KEY.
TYPES: BEGIN OF st_file,
path TYPE string,
filename TYPE string,
data TYPE xstring,
END OF st_file.
TYPES: tt_files TYPE STANDARD TABLE OF st_file WITH DEFAULT KEY.
TYPES: BEGIN OF st_commit,
tree TYPE t_sha1,
parent TYPE t_sha1,
author TYPE string,
committer TYPE string,
body TYPE string,
END OF st_commit.
TYPES: BEGIN OF st_repo,
url TYPE string,
branch_name TYPE string,
END OF st_repo.
TYPES: BEGIN OF st_repo_sha1,
url TYPE string,
branch_name TYPE string,
sha1 TYPE string,
END OF st_repo_sha1.
TYPES: tt_repos_sha1 TYPE STANDARD TABLE OF st_repo_sha1 WITH DEFAULT KEY.
TYPES: BEGIN OF st_result,
obj_type TYPE tadir-object,
obj_name TYPE tadir-obj_name,
match TYPE abap_bool,
filename TYPE string,
END OF st_result.
TYPES: tt_results TYPE STANDARD TABLE OF st_result WITH DEFAULT KEY.
TYPES: BEGIN OF st_diff,
local TYPE string,
result TYPE c LENGTH 1,
remote TYPE string,
END OF st_diff.
TYPES: tt_diffs TYPE STANDARD TABLE OF st_diff WITH DEFAULT KEY.
TYPES: BEGIN OF st_comment,
username TYPE string,
email TYPE string,
comment TYPE string,
END OF st_comment.
TYPES: BEGIN OF st_item,
obj_type TYPE tadir-object,
obj_name TYPE tadir-obj_name,
END OF st_item.
CONSTANTS: gc_commit TYPE t_type VALUE 'commit', "#EC NOTEXT
gc_tree TYPE t_type VALUE 'tree', "#EC NOTEXT
gc_ref_d TYPE t_type VALUE 'ref_d', "#EC NOTEXT
gc_blob TYPE t_type VALUE 'blob'. "#EC NOTEXT
CONSTANTS: gc_chmod_file TYPE c LENGTH 6 VALUE '100644',
gc_chmod_dir TYPE c LENGTH 5 VALUE '40000'.
CONSTANTS: gc_newline TYPE abap_char1 VALUE cl_abap_char_utilities=>newline.
DEFINE _raise.
raise exception type lcx_exception
exporting
iv_text = &1. "#EC NOTEXT
END-OF-DEFINITION.
******************
START-OF-SELECTION.
PERFORM run.
*----------------------------------------------------------------------*
* CLASS CX_LOCAL_EXCEPTION DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_exception DEFINITION INHERITING FROM cx_static_check FINAL.
PUBLIC SECTION.
DATA mv_text TYPE string.
METHODS constructor IMPORTING iv_text TYPE string.
ENDCLASS. "CX_LOCAL_EXCEPTION DEFINITION
*----------------------------------------------------------------------*
* CLASS CX_LOCAL_EXCEPTION IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcx_exception IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
mv_text = iv_text.
ENDMETHOD. "CONSTRUCTOR
ENDCLASS. "lcx_exception IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_user DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS: set_username IMPORTING iv_username TYPE string
RAISING lcx_exception.
CLASS-METHODS: get_username RETURNING value(rv_username) TYPE string
RAISING lcx_exception.
CLASS-METHODS: set_email IMPORTING iv_email TYPE string
RAISING lcx_exception.
CLASS-METHODS: get_email RETURNING value(rv_email) TYPE string
RAISING lcx_exception.
PRIVATE SECTION.
CLASS-METHODS: read IMPORTING iv_name TYPE tdobname
RETURNING value(rv_value) TYPE string
RAISING lcx_exception.
CLASS-METHODS: save IMPORTING iv_name TYPE tdobname
iv_value TYPE string
RAISING lcx_exception.
ENDCLASS. "lcl_user DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_user IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_user IMPLEMENTATION.
METHOD read.
DATA: lt_lines TYPE TABLE OF tline,
ls_line LIKE LINE OF lt_lines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'ST'
language = 'E'
name = iv_name
object = 'TEXT'
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 4 AND sy-subrc <> 0.
_raise 'error from READ_TEXT'.
ENDIF.
READ TABLE lt_lines INTO ls_line INDEX 1.
IF sy-subrc = 0.
rv_value = ls_line-tdline.
ENDIF.
ENDMETHOD. "get_details
METHOD save.
DATA: ls_header TYPE thead,
lt_lines TYPE TABLE OF tline,
ls_line LIKE LINE OF lt_lines.
ls_line-tdformat = '*'.
ls_line-tdline = iv_value.
APPEND ls_line TO lt_lines.
ls_header-tdid = 'ST'.
ls_header-tdspras = 'E'.
ls_header-tdname = iv_name.
ls_header-tdobject = 'TEXT'.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = ls_header
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
IF sy-subrc <> 0.
ROLLBACK WORK.
_raise 'error from SAVE_TEXT'.
ENDIF.
COMMIT WORK.
ENDMETHOD. "change
METHOD set_username.
DATA: lv_name TYPE tdobname.
CONCATENATE 'ZABAPGIT_USERNAME_' sy-uname INTO lv_name.
save( iv_name = lv_name
iv_value = iv_username ).
ENDMETHOD. "set_username
METHOD get_username.
DATA: lv_name TYPE tdobname.
CONCATENATE 'ZABAPGIT_USERNAME_' sy-uname INTO lv_name.
rv_username = read( lv_name ).
ENDMETHOD. "get_username
METHOD set_email.
DATA: lv_name TYPE tdobname.
CONCATENATE 'ZABAPGIT_EMAIL_' sy-uname INTO lv_name.
save( iv_name = lv_name
iv_value = iv_email ).
ENDMETHOD. "set_email
METHOD get_email.
DATA: lv_name TYPE tdobname.
CONCATENATE 'ZABAPGIT_EMAIL_' sy-uname INTO lv_name.
rv_email = read( lv_name ).
ENDMETHOD. "get_email
ENDCLASS. "lcl_user IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_xml DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_xml DEFINITION FINAL.
PUBLIC SECTION.
METHODS constructor IMPORTING iv_xml TYPE string OPTIONAL
RAISING lcx_exception.
METHODS element_add IMPORTING ig_element TYPE data
ii_root TYPE REF TO if_ixml_element OPTIONAL
RAISING lcx_exception.
* METHODS element_read
METHODS structure_add IMPORTING ig_structure TYPE data
ii_root TYPE REF TO if_ixml_element OPTIONAL
RAISING lcx_exception.
METHODS structure_read IMPORTING ii_root TYPE REF TO if_ixml_element OPTIONAL
CHANGING cg_structure TYPE data
RAISING lcx_exception.
METHODS table_add IMPORTING it_table TYPE STANDARD TABLE
iv_name TYPE string OPTIONAL
ii_root TYPE REF TO if_ixml_element OPTIONAL
RAISING lcx_exception.
METHODS table_read IMPORTING ii_root TYPE REF TO if_ixml_element OPTIONAL
iv_name TYPE string OPTIONAL
CHANGING ct_table TYPE STANDARD TABLE
RAISING lcx_exception.
METHODS xml_render RETURNING value(rv_string) TYPE string.
METHODS xml_element IMPORTING iv_name TYPE string
RETURNING value(ri_element) TYPE REF TO if_ixml_element.
METHODS xml_add IMPORTING ii_root TYPE REF TO if_ixml_element OPTIONAL
ii_element TYPE REF TO if_ixml_element.
METHODS xml_find IMPORTING ii_root TYPE REF TO if_ixml_element OPTIONAL
iv_name TYPE string
RETURNING value(ri_element) TYPE REF TO if_ixml_element.
PRIVATE SECTION.
DATA: mi_ixml TYPE REF TO if_ixml,
mi_xml_doc TYPE REF TO if_ixml_document,
mi_root TYPE REF TO if_ixml_element.
METHODS special_names CHANGING cv_name TYPE string.
METHODS error IMPORTING ii_parser TYPE REF TO if_ixml_parser
RAISING lcx_exception.
ENDCLASS. "lcl_xml DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_xml IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_xml IMPLEMENTATION.
METHOD xml_find.
DATA: li_root LIKE ii_root.
IF ii_root IS BOUND.
li_root = ii_root.
ELSE.
li_root = mi_root.
ENDIF.
ri_element = li_root->find_from_name( depth = 0 name = iv_name ).
IF NOT ri_element IS BOUND.
RETURN.
ENDIF.
li_root->remove_child( ri_element ).
ENDMETHOD. "xml_find
METHOD xml_element.
ri_element = mi_xml_doc->create_element( iv_name ).
ENDMETHOD. "xml_element
METHOD special_names.
IF cv_name(1) = '*'.
CONCATENATE 'STAR' cv_name+1 INTO cv_name.
ELSEIF cv_name(1) = '2'.
CONCATENATE 'TWO' cv_name+1 INTO cv_name.
ENDIF.
ENDMETHOD. "special_names
METHOD structure_read.
DATA: lv_name TYPE string,
lv_value TYPE string,
li_struct TYPE REF TO if_ixml_element,
lo_descr_ref TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: <lg_any> TYPE any,
<ls_comp> TYPE abap_compdescr.
CLEAR cg_structure.
lo_descr_ref ?= cl_abap_typedescr=>describe_by_data( cg_structure ).
lv_name = lo_descr_ref->get_relative_name( ).
IF lv_name IS INITIAL.
_raise 'no name'.
ENDIF.
li_struct = xml_find( ii_root = ii_root
iv_name = lv_name ).
IF NOT li_struct IS BOUND.
RETURN.
ENDIF.
LOOP AT lo_descr_ref->components ASSIGNING <ls_comp>.
ASSIGN COMPONENT <ls_comp>-name OF STRUCTURE cg_structure TO <lg_any>.
lv_name = <ls_comp>-name.
special_names( CHANGING cv_name = lv_name ).
lv_value = li_struct->find_from_name( depth = 0 name = lv_name )->get_value( ).
<lg_any> = lv_value.
ENDLOOP.
ENDMETHOD. "structure_read
METHOD table_read.
DATA: lv_name TYPE string,
li_root TYPE REF TO if_ixml_element,
lv_kind TYPE abap_typecategory,
lo_table_descr TYPE REF TO cl_abap_tabledescr.
FIELD-SYMBOLS: <lg_line> TYPE any.
CLEAR ct_table[].
lo_table_descr ?= cl_abap_typedescr=>describe_by_data( ct_table ).
lv_name = lo_table_descr->get_relative_name( ).
IF lv_name IS INITIAL.
lv_name = iv_name.
ENDIF.
IF lv_name IS INITIAL.
_raise 'no name'.
ENDIF.
li_root = xml_find( ii_root = ii_root
iv_name = lv_name ).
IF NOT li_root IS BOUND.
RETURN.
ENDIF.
lv_kind = lo_table_descr->get_table_line_type( )->kind.
DO.
APPEND INITIAL LINE TO ct_table ASSIGNING <lg_line>.
CASE lv_kind.
WHEN cl_abap_typedescr=>kind_struct.
structure_read( EXPORTING ii_root = li_root
CHANGING cg_structure = <lg_line> ).
WHEN OTHERS.
_raise 'unknown kind'.
ENDCASE.
IF <lg_line> IS INITIAL.
DELETE ct_table INDEX lines( ct_table ).
ASSERT sy-subrc = 0.
EXIT. " current loop
ENDIF.
ENDDO.
ENDMETHOD. "table_read
METHOD error.
DATA: lv_error TYPE i,
lv_txt1 TYPE string,
lv_txt2 TYPE string,
lv_txt3 TYPE string,
li_error TYPE REF TO if_ixml_parse_error.
IF ii_parser->num_errors( ) <> 0.
DO ii_parser->num_errors( ) TIMES.
lv_error = sy-index - 1.
li_error = ii_parser->get_error( lv_error ).
lv_txt1 = 'Column:' && li_error->get_column( ). "#EC NOTEXT
lv_txt2 = 'Line:' && li_error->get_line( ). "#EC NOTEXT
lv_txt3 = li_error->get_reason( ).
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Error from XLM parser' "#EC NOTEXT
txt1 = lv_txt1
txt2 = lv_txt2
txt3 = lv_txt3.
ENDDO.
ENDIF.
_raise 'Error while parsing XML'.
ENDMETHOD. "error
METHOD constructor.
DATA: li_stream_factory TYPE REF TO if_ixml_stream_factory,
li_istream TYPE REF TO if_ixml_istream,
li_parser TYPE REF TO if_ixml_parser.
mi_ixml = cl_ixml=>create( ).
mi_xml_doc = mi_ixml->create_document( ).
IF iv_xml IS SUPPLIED.
li_stream_factory = mi_ixml->create_stream_factory( ).
li_istream = li_stream_factory->create_istream_string( iv_xml ).
li_parser = mi_ixml->create_parser( stream_factory = li_stream_factory
istream = li_istream
document = mi_xml_doc ).
IF li_parser->parse( ) <> 0.
error( li_parser ).
ENDIF.
li_istream->close( ).
mi_root = mi_xml_doc->find_from_name( depth = 0 name = 'abapGit' ).
ELSE.
mi_root = mi_xml_doc->create_element( 'abapGit' ).
mi_root->set_attribute( name = 'version' value = gc_version ). "#EC NOTEXT
mi_xml_doc->append_child( mi_root ).
ENDIF.
ENDMETHOD. "xml_root
METHOD table_add.
DATA: lv_name TYPE string,
li_table TYPE REF TO if_ixml_element,
lv_kind TYPE abap_typecategory,
lo_table_descr TYPE REF TO cl_abap_tabledescr.
FIELD-SYMBOLS: <lg_line> TYPE any.
lo_table_descr ?= cl_abap_typedescr=>describe_by_data( it_table ).
lv_name = lo_table_descr->get_relative_name( ).
IF lv_name IS INITIAL.
lv_name = iv_name.
ENDIF.
IF lv_name IS INITIAL.
_raise 'no name'.
ENDIF.
li_table = mi_xml_doc->create_element( lv_name ).
lv_kind = lo_table_descr->get_table_line_type( )->kind.
LOOP AT it_table ASSIGNING <lg_line>.
CASE lv_kind.
WHEN cl_abap_typedescr=>kind_struct.
structure_add( ig_structure = <lg_line>
ii_root = li_table ).
WHEN cl_abap_typedescr=>kind_elem.
element_add( ig_element = <lg_line>
ii_root = li_table ).
WHEN OTHERS.
_raise 'unknown kind'.
ENDCASE.
ENDLOOP.
xml_add( ii_root = ii_root
ii_element = li_table ).
ENDMETHOD. "table_add
METHOD xml_add.
IF ii_root IS BOUND.
ii_root->append_child( ii_element ).
ELSE.
mi_root->append_child( ii_element ).
ENDIF.
ENDMETHOD. "xml_add
METHOD element_add.
DATA: lo_descr TYPE REF TO cl_abap_elemdescr,
lv_string TYPE string,
li_element TYPE REF TO if_ixml_element,
li_text TYPE REF TO if_ixml_text,
lv_name TYPE string.
lo_descr ?= cl_abap_typedescr=>describe_by_data( ig_element ).
lv_name = lo_descr->get_relative_name( ).
IF lv_name IS INITIAL.
_raise 'no name'.
ENDIF.
li_element = mi_xml_doc->create_element( lv_name ).
lv_string = ig_element.
li_text = mi_xml_doc->create_text( lv_string ).
li_element->append_child( li_text ).
xml_add( ii_root = ii_root
ii_element = li_element ).
ENDMETHOD. "element_add
METHOD structure_add.
DATA: li_element TYPE REF TO if_ixml_element,
li_structure TYPE REF TO if_ixml_element,
li_text TYPE REF TO if_ixml_text,
lv_string TYPE string,
lv_name TYPE string,
lo_descr TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: <ls_comp> TYPE abap_compdescr,
<lg_any> TYPE any.
lo_descr ?= cl_abap_typedescr=>describe_by_data( ig_structure ).
lv_name = lo_descr->get_relative_name( ).
IF lv_name IS INITIAL.
_raise 'no name'.
ENDIF.
li_structure = mi_xml_doc->create_element( lv_name ).
LOOP AT lo_descr->components ASSIGNING <ls_comp>.
ASSIGN COMPONENT <ls_comp>-name OF STRUCTURE ig_structure TO <lg_any>.
lv_name = <ls_comp>-name.
special_names( CHANGING cv_name = lv_name ).
li_element = mi_xml_doc->create_element( lv_name ).
lv_string = <lg_any>.
li_text = mi_xml_doc->create_text( lv_string ).
li_element->append_child( li_text ).
li_structure->append_child( li_element ).
ENDLOOP.
xml_add( ii_root = ii_root
ii_element = li_structure ).
ENDMETHOD. "structure_to_xml
METHOD xml_render.
DATA: li_ostream TYPE REF TO if_ixml_ostream,
li_renderer TYPE REF TO if_ixml_renderer,
li_streamfactory TYPE REF TO if_ixml_stream_factory.
* todo, the xml file says "encoding=utf-16" but its wrong
li_streamfactory = mi_ixml->create_stream_factory( ).
li_ostream = li_streamfactory->create_ostream_cstring( rv_string ).
li_renderer = mi_ixml->create_renderer( ostream = li_ostream document = mi_xml_doc ).
li_renderer->set_normalizing( ).
li_renderer->render( ).
ENDMETHOD. "xml_render
ENDCLASS. "lcl_xml IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_time DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_time DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS get RETURNING value(rv_time) TYPE t_unixtime
RAISING lcx_exception.
PRIVATE SECTION.
CONSTANTS: c_epoch TYPE datum VALUE '19700101'.
ENDCLASS. "lcl_time DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_time IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_time IMPLEMENTATION.
METHOD get.
DATA: lv_i TYPE i,
lv_tz TYPE tznzone,
lv_utcdiff TYPE tznutcdiff,
lv_utcsign TYPE tznutcsign.
lv_i = sy-datum - c_epoch.
lv_i = lv_i * 86400.
lv_i = lv_i + sy-uzeit.
CALL FUNCTION 'TZON_GET_OS_TIMEZONE'
IMPORTING
ef_timezone = lv_tz.
CALL FUNCTION 'TZON_GET_OFFSET'
EXPORTING
if_timezone = lv_tz
if_local_date = sy-datum
if_local_time = sy-uzeit
IMPORTING
ef_utcdiff = lv_utcdiff
ef_utcsign = lv_utcsign
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
_raise 'Timezone error'.
ENDIF.
CASE lv_utcsign.
WHEN '+'.
lv_i = lv_i - lv_utcdiff.
WHEN '-'.
lv_i = lv_i + lv_utcdiff.
ENDCASE.
rv_time = lv_i.
CONDENSE rv_time.
rv_time+11 = lv_utcsign.
rv_time+12 = lv_utcdiff.
ENDMETHOD. "get
ENDCLASS. "lcl_time IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_repo DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_url DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS: host
IMPORTING iv_repo TYPE string
RETURNING value(rv_host) TYPE string
RAISING lcx_exception.
CLASS-METHODS: name
IMPORTING iv_repo TYPE string
RETURNING value(rv_name) TYPE string
RAISING lcx_exception.
CLASS-METHODS: path_name IMPORTING iv_repo TYPE string
RETURNING value(rv_path_name) TYPE string
RAISING lcx_exception.
PRIVATE SECTION.
CLASS-METHODS: regex IMPORTING iv_repo TYPE string
EXPORTING ev_host TYPE string
ev_path TYPE string
ev_name TYPE string
RAISING lcx_exception.
ENDCLASS. "lcl_repo DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_repo IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_url IMPLEMENTATION.
METHOD host.
regex( EXPORTING iv_repo = iv_repo
IMPORTING ev_host = rv_host ).
ENDMETHOD. "host
METHOD name.
regex( EXPORTING iv_repo = iv_repo
IMPORTING ev_name = rv_name ).
ENDMETHOD. "short_name
METHOD path_name.
DATA: lv_path TYPE string,
lv_name TYPE string.
regex( EXPORTING iv_repo = iv_repo
IMPORTING ev_path = lv_path
ev_name = lv_name ).
CONCATENATE lv_path lv_name INTO rv_path_name.
ENDMETHOD. "path_name
METHOD regex.
FIND REGEX '(.*://[^/]*)(.*/)(.*).git' IN iv_repo
SUBMATCHES ev_host ev_path ev_name.
IF sy-subrc <> 0.
_raise 'Malformed URL'.
ENDIF.
ENDMETHOD. "url
ENDCLASS. "lcl_repo IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_convert DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_convert DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS bitbyte_to_int IMPORTING iv_bits TYPE clike
RETURNING value(rv_int) TYPE i.
CLASS-METHODS x_to_bitbyte IMPORTING iv_x TYPE x
RETURNING value(rv_bitbyte) TYPE t_bitbyte.
CLASS-METHODS string_to_xstring_utf8 IMPORTING iv_string TYPE string
RETURNING value(rv_xstring) TYPE xstring.
CLASS-METHODS xstring_to_string_utf8 IMPORTING iv_data TYPE xstring
RETURNING value(rv_string) TYPE string.
CLASS-METHODS xstring_to_int IMPORTING iv_xstring TYPE xstring
RETURNING value(rv_i) TYPE i
RAISING lcx_exception.
CLASS-METHODS int_to_xstring IMPORTING iv_i TYPE i
iv_length TYPE i
RETURNING value(rv_xstring) TYPE xstring.
ENDCLASS. "lcl_convert DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_convert IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_convert IMPLEMENTATION.
METHOD int_to_xstring.
DATA: lv_x TYPE x LENGTH 4.
ASSERT iv_length = 4. " other cases not implemented
lv_x = iv_i.
rv_xstring = lv_x.
ENDMETHOD. "int_to_xstring
METHOD xstring_to_int.
DATA: lv_xstring TYPE xstring,
lv_x TYPE x.
lv_xstring = iv_xstring.
WHILE xstrlen( lv_xstring ) > 0.
lv_x = lv_xstring(1).
rv_i = rv_i * 256 + lv_x.
lv_xstring = lv_xstring+1.
ENDWHILE.
ENDMETHOD. "xstring_to_int
METHOD xstring_to_string_utf8.
DATA: lv_len TYPE i,
lo_obj TYPE REF TO cl_abap_conv_in_ce.
TRY.
lo_obj = cl_abap_conv_in_ce=>create(
input = iv_data
encoding = 'UTF-8' ).
lv_len = xstrlen( iv_data ).
lo_obj->read( EXPORTING n = lv_len
IMPORTING data = rv_string ).
CATCH cx_parameter_invalid_range
cx_sy_codepage_converter_init
cx_sy_conversion_codepage
cx_parameter_invalid_type. "#EC NO_HANDLER
ENDTRY.
ENDMETHOD. "xstring_to_string_utf8
METHOD string_to_xstring_utf8.
DATA: lo_obj TYPE REF TO cl_abap_conv_out_ce.
TRY.
lo_obj = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
lo_obj->convert( EXPORTING data = iv_string
IMPORTING buffer = rv_xstring ).
CATCH cx_parameter_invalid_range
cx_sy_codepage_converter_init
cx_sy_conversion_codepage
cx_parameter_invalid_type. "#EC NO_HANDLER
ENDTRY.
ENDMETHOD. "string_to_xstring_utf8
METHOD bitbyte_to_int.
DATA: lv_bits TYPE string.
lv_bits = iv_bits.
rv_int = 0.
WHILE strlen( lv_bits ) > 0.
rv_int = rv_int * 2.
IF lv_bits(1) = '1'.
rv_int = rv_int + 1.
ENDIF.
lv_bits = lv_bits+1.
ENDWHILE.
ENDMETHOD. "bitbyte_to_int
METHOD x_to_bitbyte.
DATA: lv_b TYPE n.
CLEAR rv_bitbyte.
DO 8 TIMES.
GET BIT sy-index OF iv_x INTO lv_b.
CONCATENATE rv_bitbyte lv_b INTO rv_bitbyte.
ENDDO.
ENDMETHOD. "x_to_bitbyte
ENDCLASS. "lcl_convert IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_diff DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_diff DEFINITION FINAL.
PUBLIC SECTION.
* assumes data is UTF8 based with newlines
CLASS-METHODS diff IMPORTING iv_local TYPE xstring
iv_remote TYPE xstring
RETURNING value(rt_diffs) TYPE tt_diffs.
ENDCLASS. "lcl_diff DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_diff IMPLEMENTATION