Created
January 30, 2016 22:54
-
-
Save abramsba/a0fc9545153a307e1878 to your computer and use it in GitHub Desktop.
validator.abap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ZCL_SPB_VALIDATOR definition | |
public | |
final | |
create public . | |
public section. | |
methods VALIDATE | |
importing | |
!XML type STRING | |
returning | |
value(RETURNING) type BOOLEAN . | |
protected section. | |
private section. | |
methods _SAVE_TEMP_XML_FILE | |
importing | |
!UUID type STRING | |
!XML type STRING | |
returning | |
value(RETURNING) type BOOLEAN . | |
methods _CHECK_XML_FILE | |
importing | |
!UUID type STRING | |
returning | |
value(RETURNING) type BOOLEAN . | |
methods _DELETE_TEMP_XML_FILE | |
importing | |
!UUID type STRING | |
returning | |
value(RETURNING) type BOOLEAN . | |
methods _UUID_FILENAME | |
importing | |
!UUID type STRING | |
returning | |
value(RETURNING) type STRING . | |
ENDCLASS. | |
CLASS ZCL_SPB_VALIDATOR IMPLEMENTATION. | |
* <SIGNATURE>---------------------------------------------------------------------------------------+ | |
* | Instance Public Method ZCL_SPB_VALIDATOR->VALIDATE | |
* +-------------------------------------------------------------------------------------------------+ | |
* | [--->] XML TYPE STRING | |
* | [<-()] RETURNING TYPE BOOLEAN | |
* +--------------------------------------------------------------------------------------</SIGNATURE> | |
method validate. | |
try. | |
data(tmp_uuid) = `` && cl_system_uuid=>create_uuid_c22_static( ). | |
catch cx_uuid_error. | |
return. | |
endtry. | |
data(saved) = _save_temp_xml_file( uuid = tmp_uuid xml = xml ). | |
if ( saved = abap_true ). | |
if ( _check_xml_file( tmp_uuid ) = abap_true ). | |
returning = abap_true. | |
endif. | |
_delete_temp_xml_file( tmp_uuid ). | |
endif. | |
endmethod. | |
* <SIGNATURE>---------------------------------------------------------------------------------------+ | |
* | Instance Private Method ZCL_SPB_VALIDATOR->_CHECK_XML_FILE | |
* +-------------------------------------------------------------------------------------------------+ | |
* | [--->] UUID TYPE STRING | |
* | [<-()] RETURNING TYPE BOOLEAN | |
* +--------------------------------------------------------------------------------------</SIGNATURE> | |
method _CHECK_XML_FILE. | |
data output type table of btcxpm. | |
data parameter type sxpgcolist-parameters. | |
parameter = '"' && _uuid_filename( uuid ) && '"'. | |
call function 'SXPG_CALL_SYSTEM' | |
exporting | |
commandname = 'Z_SP_VALIDATOR' | |
additional_parameters = parameter | |
tables | |
exec_protocol = output | |
exceptions | |
others = 1. | |
if ( output is initial ). | |
returning = abap_true. | |
endif. | |
endmethod. | |
* <SIGNATURE>---------------------------------------------------------------------------------------+ | |
* | Instance Private Method ZCL_SPB_VALIDATOR->_DELETE_TEMP_XML_FILE | |
* +-------------------------------------------------------------------------------------------------+ | |
* | [--->] UUID TYPE STRING | |
* | [<-()] RETURNING TYPE BOOLEAN | |
* +--------------------------------------------------------------------------------------</SIGNATURE> | |
method _delete_temp_xml_file. | |
data(tmp_filename) = _uuid_filename( uuid ). | |
delete dataset tmp_filename. | |
if ( sy-subrc = 0 ). | |
returning = abap_true. | |
endif. | |
endmethod. | |
* <SIGNATURE>---------------------------------------------------------------------------------------+ | |
* | Instance Private Method ZCL_SPB_VALIDATOR->_SAVE_TEMP_XML_FILE | |
* +-------------------------------------------------------------------------------------------------+ | |
* | [--->] UUID TYPE STRING | |
* | [--->] XML TYPE STRING | |
* | [<-()] RETURNING TYPE BOOLEAN | |
* +--------------------------------------------------------------------------------------</SIGNATURE> | |
method _save_temp_xml_file. | |
data(tmp_filename) = _uuid_filename( uuid ). | |
open dataset tmp_filename for output in text mode encoding utf-8. | |
if ( sy-subrc <> 0 ). | |
return. | |
endif. | |
transfer xml to tmp_filename. | |
if ( sy-subrc <> 0 ). | |
return. | |
endif. | |
close dataset tmp_filename. | |
if ( sy-subrc <> 0 ). | |
return. | |
endif. | |
returning = abap_true. | |
endmethod. | |
* <SIGNATURE>---------------------------------------------------------------------------------------+ | |
* | Instance Private Method ZCL_SPB_VALIDATOR->_UUID_FILENAME | |
* +-------------------------------------------------------------------------------------------------+ | |
* | [--->] UUID TYPE STRING | |
* | [<-()] RETURNING TYPE STRING | |
* +--------------------------------------------------------------------------------------</SIGNATURE> | |
method _UUID_FILENAME. | |
returning = `C:\usr\sap\tmp\` && uuid && `.xml`. | |
endmethod. | |
ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment