Permalink
Fetching contributors…
Cannot retrieve contributors at this time
455 lines (400 sloc) 21.7 KB
<?xml version="1.0" encoding="iso-8859-1"?>
<CLAS CLSNAME="ZSAPLINK_SMARTFORM" VERSION="0" LANGU="E" DESCRIPT="SAPlink - Programs" UUID="7CB76E9F279C244BADF6EC7E1B9CD6EA" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" AUTHOR="BCUSER" CREATEDON="20061007" CHANGEDON="00000000" CHGDANYON="00000000" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" R3RELEASE="700" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " REFCLSNAME="ZSAPLINK">
<publicSection>class ZSAPLINK_SMARTFORM definition
public
inheriting from ZSAPLINK
final
create public .
*&quot;* public components of class ZSAPLINK_SMARTFORM
*&quot;* do not include other source files here!!!
public section.
methods CHECKEXISTS
redefinition .
methods CREATEIXMLDOCFROMOBJECT
redefinition .
methods CREATEOBJECTFROMIXMLDOC
redefinition .</publicSection>
<protectedSection>*&quot;* protected components of class ZSAPLINK_PROGRAM
*&quot;* do not include other source files here!!!
protected section.
methods DELETEOBJECT
redefinition .
methods GETOBJECTTYPE
redefinition .</protectedSection>
<privateSection>*&quot;* private components of class ZSAPLINK_SMARTFORM
*&quot;* do not include other source files here!!!
private section.</privateSection>
<localImplementation>*&quot;* local class implementation for public class
*&quot;* use this source file for the implementation part of
*&quot;* local helper classes</localImplementation>
<localTypes>*&quot;* use this source file for any type declarations (class
*&quot;* definitions, interfaces or data types) you need for method
*&quot;* implementation or private method&apos;s signature</localTypes>
<localMacros>*&quot;* use this source file for any macro definitions you need
*&quot;* in the implementation part of the class</localMacros>
<method CLSNAME="ZSAPLINK" CMPNAME="CHECKEXISTS" VERSION="0" LANGU="E" DESCRIPT="Check if object exists" EXPOSURE="2" STATE="1" EDITORDER="9 " DISPID="0 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" MTDABSTRCT="X" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink 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 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink 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 SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD checkexists .
SELECT SINGLE formname FROM stxfadm INTO objname WHERE formname = objname.
IF sy-subrc = 0.
exists = &apos;X&apos;.
ENDIF.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="CREATEIXMLDOCFROMOBJECT" VERSION="0" LANGU="E" DESCRIPT="Creates an IF_IXML_DOCUMENT from the OBJNAME Attribute" EXPOSURE="2" STATE="1" EDITORDER="5 " DISPID="0 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" MTDABSTRCT="X" MTDNEWEXC="X" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<exception CLSNAME="ZSAPLINK" CMPNAME="CREATEIXMLDOCFROMOBJECT" SCONAME="ZCX_SAPLINK" VERSION="0" LANGU="E" DESCRIPT="SAPlink exception class" MTDTYPE="0" EDITORDER="1 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000"/>
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink 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 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink 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 SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD createixmldocfromobject .
DATA rootnode TYPE REF TO if_ixml_element.
DATA sourcenode TYPE REF TO if_ixml_element.
DATA rc TYPE sysubrc.
DATA sourcestring TYPE string.
DATA _objtype TYPE string.
DATA: l_filename TYPE string,
l_file_filter TYPE string,
l_user_action TYPE i.
DATA: wa_node type ssfgnode,
l_element TYPE REF TO if_ixml_element.
DATA: l_language_str TYPE string,
l_language(2) TYPE c.
DATA: l_lines TYPE i,
l_splitted_name_tab TYPE TABLE OF string.
DATA: l_stylename TYPE tdssname,
l_stylevari TYPE tdvariant,
l_save_style TYPE tdssname.
TYPES: t_raw(250) TYPE x.
CONSTANTS: c_xml_ns_uri_sf(255) TYPE c
VALUE &apos;urn:sap-com:SmartForms:2000:internal-structure&apos;,&quot;#EC NOTEXT
c_xml_ns_uri_ifr(255) TYPE c
VALUE &apos;urn:sap-com:sdixml-ifr:2000&apos;. &quot;#EC NOTEXT
DATA: g_ixml TYPE REF TO if_ixml,
xml_macro_rc TYPE i,
xml_document TYPE REF TO if_ixml_document,
xml_ns_prefix_sf TYPE string,
xml_ns_uri_sf TYPE string,
xml_ns_uri_ifr TYPE string,
xml_document_size TYPE i,
xml_xtable TYPE TABLE OF t_raw,
xml_xtable2 TYPE TABLE OF string,
sform_name TYPE tdsfname.
DATA ref_ssf TYPE REF TO cl_ssf_fb_smart_form.
sform_name = objname.
IF g_ixml IS INITIAL.
g_ixml = cl_ixml=&gt;create( ).
ENDIF.
xml_document = g_ixml-&gt;create_document( ).
xml_ns_prefix_sf = &apos;sf&apos;.
xml_ns_uri_sf = c_xml_ns_uri_sf.
xml_ns_uri_ifr = c_xml_ns_uri_ifr.
CLEAR: xml_document_size, xml_xtable[], xml_xtable2[].
CREATE OBJECT ref_ssf.
TRY.
CALL METHOD ref_ssf-&gt;load
EXPORTING
im_formname = sform_name.
ref_ssf-&gt;xml_init( ).
CALL METHOD ref_ssf-&gt;xml_download
EXPORTING
parent = xml_document
CHANGING
document = xml_document.
* namespace
l_element = xml_document-&gt;get_root_element( ).
l_element-&gt;set_attribute( name = xml_ns_prefix_sf
namespace = &apos;xmlns&apos;
value = xml_ns_uri_sf ).
l_element-&gt;set_attribute( name = &apos;xmlns&apos;
value = xml_ns_uri_ifr ).
* language
WRITE sy-langu TO l_language.
l_language_str = l_language.
xml_macro_rc = l_element-&gt;set_attribute(
name = &apos;language&apos;
namespace = xml_ns_prefix_sf
value = l_language_str ).
* convert DOM to xml
CALL FUNCTION &apos;SDIXML_DOM_TO_XML&apos;
EXPORTING
document = xml_document
IMPORTING
size = xml_document_size
TABLES
xml_as_table = xml_xtable
EXCEPTIONS
OTHERS = 1.
CHECK sy-subrc EQ 0.
_objtype = getobjecttype( ).
rootnode = xmldoc-&gt;create_element( _objtype ).
DATA: wa_stxfadm TYPE stxfadm.
SELECT SINGLE * FROM stxfadm INTO wa_stxfadm WHERE formname = objname.
setattributesfromstructure( node = rootnode structure = wa_stxfadm
).
sourcenode = xmldoc-&gt;create_element( &apos;smartform&apos; ).
xml_xtable2 = xml_xtable[].
sourcestring = buildsourcestring( sourcetable = xml_xtable2[] ).
rc = sourcenode-&gt;if_ixml_node~set_value( sourcestring ).
rc = rootnode-&gt;append_child( sourcenode ).
rc = xmldoc-&gt;append_child( rootnode ).
ixmldocument = xmldoc.
FREE: xml_document, xml_xtable[], xml_document_size.
CATCH cx_ssf_fb .
CLEAR ixmldocument.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;not_found.
ENDTRY.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="CREATEOBJECTFROMIXMLDOC" VERSION="0" LANGU="E" DESCRIPT="Creates Object on System from IXMLDocument passed in" EXPOSURE="2" STATE="1" EDITORDER="4 " DISPID="0 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" MTDABSTRCT="X" MTDNEWEXC="X" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<exception CLSNAME="ZSAPLINK" CMPNAME="CREATEOBJECTFROMIXMLDOC" SCONAME="ZCX_SAPLINK" VERSION="0" LANGU="E" DESCRIPT="SAPlink exception class" MTDTYPE="0" EDITORDER="1 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000"/>
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink 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 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink 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 SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD createobjectfromixmldoc .
TYPES: t_raw(250) TYPE x.
DATA rootnode TYPE REF TO if_ixml_element.
DATA progattribs TYPE trdir.
DATA sourcenode TYPE REF TO if_ixml_element.
DATA l_xml_node TYPE REF TO if_ixml_element.
DATA source TYPE string.
DATA sourcetable TYPE table_of_strings.
DATA _objtype TYPE string.
DATA checkexists TYPE flag.
DATA: wa_stxfadm TYPE stxfadm,
formname TYPE tdsfname,
master_language TYPE sylangu,
lv_devclass TYPE devclass,
korrnum TYPE trkorr,
modif_language TYPE sylangu.
DATA: g_ixml TYPE REF TO if_ixml,
xml_macro_rc TYPE i,
xml_document TYPE REF TO if_ixml_document,
l_element TYPE REF TO if_ixml_element,
xml_ns_prefix_sf TYPE string,
xml_ns_uri_sf TYPE string,
xml_ns_uri_ifr TYPE string,
xml_document_size TYPE i,
xml_xtable TYPE TABLE OF t_raw,
l_ns_uri TYPE string,
l_name TYPE string,
l_language TYPE string,
p_dequeue TYPE tdbool,
l_cancel TYPE tdsfflag,
sf_exception TYPE REF TO cx_ssf_fb.
DATA: ref_ssf TYPE REF TO cl_ssf_fb_smart_form,
l_upload_smartform TYPE REF TO cl_ssf_fb_smart_form.
_objtype = getobjecttype( ).
xmldoc = ixmldocument.
rootnode = xmldoc-&gt;find_from_name( _objtype ).
CALL METHOD getstructurefromattributes
EXPORTING
node = rootnode
CHANGING
structure = wa_stxfadm.
objname = wa_stxfadm-formname.
checkexists = checkexists( ).
IF checkexists IS NOT INITIAL.
IF overwrite IS INITIAL.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING textid = zcx_saplink=&gt;existing.
ELSE.
* delete object for new install
deleteobject( ).
ENDIF.
ENDIF.
sourcenode = rootnode-&gt;find_from_name( &apos;smartform&apos; ).
source = sourcenode-&gt;get_value( ).
sourcetable = buildtablefromstring( source ).
xml_xtable = sourcetable.
xml_document_size = STRLEN( source ).
CREATE OBJECT ref_ssf.
formname = objname.
* Check access permission and enqueue smart form
master_language = sy-langu.
TRY.
CALL METHOD ref_ssf-&gt;enqueue
EXPORTING
suppress_corr_check = space
language_upd_exit = &apos; &apos;
master_language = master_language
mode = &apos;INSERT&apos;
formname = formname
IMPORTING
devclass = lv_devclass
new_master_language = master_language
korrnum = korrnum
modification_language = modif_language.
CATCH cx_ssf_fb INTO sf_exception.
CASE sf_exception-&gt;textid.
WHEN cx_ssf_fb=&gt;enqueued_by_user OR cx_ssf_fb=&gt;enqueue_system_failure.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING msg = &apos;Enqueued by user&apos;.
WHEN cx_ssf_fb=&gt;no_modify_permission OR cx_ssf_fb=&gt;no_show_permission.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING msg = &apos;Permission Error&apos;.
WHEN cx_ssf_fb=&gt;permission_failure.
EXIT.
WHEN cx_ssf_fb=&gt;request_language_denied.
RAISE EXCEPTION TYPE zcx_saplink
EXPORTING msg = &apos;Language request denied&apos;.
WHEN OTHERS.
EXIT.
ENDCASE.
ENDTRY.
CALL FUNCTION &apos;SDIXML_XML_TO_DOM&apos;
EXPORTING
xml = xml_xtable[]
size = xml_document_size
IMPORTING
document = xml_document
EXCEPTIONS
OTHERS = 1.
l_xml_node = xml_document-&gt;get_root_element( ).
l_ns_uri = l_xml_node-&gt;get_namespace_uri( ).
l_name = l_xml_node-&gt;get_name( ).
l_element ?= l_xml_node-&gt;query_interface( ixml_iid_element ).
l_language = l_element-&gt;get_attribute( name = &apos;language&apos;
namespace = xml_ns_prefix_sf ).
CREATE OBJECT l_upload_smartform.
CALL METHOD l_upload_smartform-&gt;xml_upload
EXPORTING
dom = l_xml_node
formname = formname
language = master_language
CHANGING
sform = ref_ssf.
ref_ssf = l_upload_smartform.
PERFORM save_form IN PROGRAM saplstxb
USING
&apos; &apos; &apos;X&apos;
CHANGING
ref_ssf
l_cancel.
FREE: xml_document.
* dequeue form
ref_ssf-&gt;dequeue( formname = formname ).
* successful install
name = objname.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="DELETEOBJECT" VERSION="0" LANGU="E" DESCRIPT="Delete object" EXPOSURE="1" STATE="1" EDITORDER="1 " DISPID="0 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" MTDABSTRCT="X" MTDNEWEXC="X" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<exception CLSNAME="ZSAPLINK" CMPNAME="DELETEOBJECT" SCONAME="ZCX_SAPLINK" VERSION="0" LANGU="E" DESCRIPT="SAPlink exception class" MTDTYPE="0" EDITORDER="1 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000"/>
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink 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 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink 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 SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
METHOD deleteobject .
CALL FUNCTION &apos;FB_DELETE_FORM&apos;
EXPORTING
I_FORMNAME = OBJNAME
* I_FORMTYPE = &apos; &apos;
* I_WITH_DIALOG = &apos;X&apos;
* I_WITH_CONFIRM_DIALOG = &apos;X&apos;
* IMPORTING
* O_FORMNAME =
EXCEPTIONS
NO_NAME = 1
NO_FORM = 2
FORM_LOCKED = 3
NO_ACCESS_PERMISSION = 4
ILLEGAL_LANGUAGE = 5
ILLEGAL_FORMTYPE = 6
OTHERS = 7
.
IF sy-subrc &lt;&gt; 0.
ENDIF.
ENDMETHOD. &quot;createobjectfromixmldoc</source>
</method>
<method CLSNAME="ZSAPLINK" CMPNAME="GETOBJECTTYPE" VERSION="0" LANGU="E" DESCRIPT="Get object type of plugin" EXPOSURE="1" STATE="1" EDITORDER="8 " DISPID="0 " AUTHOR="BCUSER" CREATEDON="20061006" CHANGEDON="00000000" MTDTYPE="0" MTDDECLTYP="0" MTDABSTRCT="X" R3RELEASE="700" BCMTDCAT="00" BCMTDSYN="0">
<parameter VERSION="0" CMPTYPE="0" MTDTYPE="0" EDITORDER="0 " DISPID="0 " CREATEDON="00000000" CHANGEDON="00000000" PARDECLTYP="0" PARPASSTYP="0" TYPTYPE="0"/>
<source>*/---------------------------------------------------------------------\
*| This file is part of SAPlink. |
*| |
*| SAPlink 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 2 of the License, |
*| or (at your option) any later version. |
*| |
*| SAPlink 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 SAPlink; if not, write to the |
*| Free Software Foundation, Inc., |
*| 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
*\---------------------------------------------------------------------/
method GETOBJECTTYPE .
objectType = &apos;SSFO&apos;. &quot;SAP Smartforms
endmethod.</source>
</method>
</CLAS>