Wiki source code of 3. Variables
Version 12.1 by Assala Chmiti on 2022/04/14 15:23
Hide last authors
author | version | line-number | content |
---|---|---|---|
2.16 | 1 | {{toc/}} | |
2 | |||
2.2 | 3 | = Introduction = | |
4 | |||
2.16 | 5 | Variable is a container that holds a value and can be called in the iXPath Scenario. The importance of | |
2.2 | 6 | ||
2.16 | 7 | variables is to make flexibility in using some values without referring to their origins. | |
8 | |||
2.3 | 9 | There are 2 types of variables: | |
2.2 | 10 | ||
2.3 | 11 | * System variables | |
12 | * Local variables | ||
2.2 | 13 | ||
2.3 | 14 | To call a variable, we should put it inside ${}. Eg: for a variable named ‘iXVar’, it can be called as ${iXVar}. | |
2.2 | 15 | ||
3.2 | 16 | == System variables == | |
2.2 | 17 | ||
2.3 | 18 | System variables define some default values in the system, and they can be called by users several times. | |
2.2 | 19 | ||
2.3 | 20 | Here is the list of system variables : | |
21 | |||
22 | 1. At the declaration of the scenario: | ||
23 | 1*. iXSession: it returns the ID of the current session. | ||
24 | 1*. iXSessionPath: gets the Path of the session folder. | ||
25 | 1*. env: name of the environment. | ||
26 | 1*. inputFile: this variable collect all input files in one list. | ||
27 | 1. For a **mail listener : ** | ||
28 | 1*. iXFrom: refers to the sender of the mail. | ||
29 | 1*. iXSubject: refers to the mail subject. | ||
30 | 1. For an **AS2 listener **: | ||
31 | 1*. iXFrom: return the value of the AS2 sender. | ||
2.6 | 32 | 1. All connectors declare a system variable of type BpmnFile, the connector variable uses a bunch of functions to handle the list of BpmnFiles that will be detailed in the table below : | |
2.3 | 33 | 1*. ((( | |
2.11 | 34 | (% style="width:884px" %) | |
35 | |(% style="width:150px" %)**Function**|(% style="width:365px" %)**Description**|(% style="width:367px" %)**Use** | ||
7.1 | 36 | |(% style="width:150px" %)Get( x ) |(% style="width:365px" %)Get a file with index number "x" from the BpmnFile list, the indexes begin from 0 as the first element, and so on.|(% style="width:367px" %)((( | |
2.9 | 37 | if we have an XmlToXml connector named "XmlToXml1" we can get __the second__ BpmnFile as : | |
2.3 | 38 | ||
2.4 | 39 | ${XmlToXml1.get(1)} | |
2.6 | 40 | ||
2.8 | 41 | NB: we will make examples on the same connector "XmlToXml1". | |
2.4 | 42 | ))) | |
2.11 | 43 | |(% style="width:150px" %)getTrkValues()|(% style="width:365px" %)Return the Tracking values from a BpmnFile.|(% style="width:367px" %)Eg : ${XmlToXml1.get(0).getTrkValues()} returns the tracking values of the first BpmnFile. | |
44 | |(% style="width:150px" %)path()|(% style="width:365px" %)Return the absolute path of the BpmnFile.|(% style="width:367px" %)Eg : ${XmlToXml.get(3).path()} returns the path of the __fourth__ BpmnFile | ||
45 | |(% style="width:150px" %)fileName()|(% style="width:365px" %)Return the name of the BpmnFile. |(% style="width:367px" %)Eg : ${XmlToXml1.get(2).fileName()} retrieves the name of the third BpmnFile. | ||
46 | |(% style="width:150px" %)extension()|(% style="width:365px" %)Returns the extension of the BpmnFile.|(% style="width:367px" %)((( | ||
2.9 | 47 | Eg : if we want to get the extension of the first BpmnFile, we will proceed as below : | |
2.4 | 48 | ||
2.9 | 49 | ${XmlToXml1.get(0).extension()} | |
50 | ))) | ||
2.11 | 51 | |(% style="width:150px" %)fullName()|(% style="width:365px" %)Returns the file name + its extension |(% style="width:367px" %)Eg : ${XmlToXml1.get(0).fullName()} returns the full name of the BpmnFile. | |
52 | |(% style="width:150px" %)size()|(% style="width:365px" %)Returns the size of the BpmnFile in megabit.|(% style="width:367px" %)((( | ||
2.10 | 53 | Eg : ${XmlToXml1.get(0).size()} returns the size of the first BpmnFile. | |
54 | ))) | ||
2.11 | 55 | |(% style="width:150px" %)type()|(% style="width:365px" %)Returns the type of the BpmnFile|(% style="width:367px" %)((( | |
2.10 | 56 | Eg : To get the type of the second BpmnFile , | |
2.9 | 57 | ||
2.10 | 58 | ${XmlToXml1.get(1).type()} | |
59 | ))) | ||
2.3 | 60 | ))) | |
61 | |||
3.2 | 62 | == Local variables == | |
2.3 | 63 | ||
2.14 | 64 | Local variable is a type of variable that can be newly created and used for a certain need. | |
2.3 | 65 | ||
2.14 | 66 | So as to create a local variable "newVar" with a value equals to "var number 1", we should write this piece of XSL code : | |
2.3 | 67 | ||
2.14 | 68 | {{code language="XML"}} | |
69 | <xsl:value-of select=" ixf:SetVar('newVar', 'var Number 1')"></xsl:value-of> | ||
2.12 | 70 | ||
2.14 | 71 | {{/code}} | |
2.12 | 72 | ||
3.2 | 73 | The call of this new variable in the scenario is similar to previous system variables: **${newVar}.** | |
2.14 | 74 | ||
3.2 | 75 | To get 'newVar' inside an XSL file : | |
2.14 | 76 | ||
77 | {{code language="XML"}} | ||
3.2 | 78 | <xsl:value-of select="ixf:getVar('newVar')"></xsl:value-of> | |
2.14 | 79 | {{/code}} | |
80 | |||
6.1 | 81 | = Examples = | |
2.14 | 82 | ||
6.1 | 83 | We set a simple example of a scenario to illustrate how to use variables. | |
2.14 | 84 | ||
6.1 | 85 | We want to receive a file by a FileListener and send it by mail that contains a message body. | |
2.14 | 86 | ||
6.1 | 87 | here is the scenario: | |
2.14 | 88 | ||
6.1 | 89 | [[image:2021-04-27_21h31_55.png||height="140" width="446"]] | |
2.14 | 90 | ||
6.1 | 91 | The configuration of the "SendMail" is : | |
92 | |||
93 | [[image:2021-04-27_21h32_07.png||height="373" width="281"]] | ||
94 | |||
95 | As shown in the mail body, we called 3 variables which are : | ||
96 | |||
7.3 | 97 | * Env: the current environment | |
6.1 | 98 | * iXSession : ID session | |
7.3 | 99 | * path : the path of BpmnFile in FileListener1. | |
6.1 | 100 | ||
7.2 | 101 | = String Class = | |
6.1 | 102 | ||
7.4 | 103 | in java language, The String class represents character strings. It contains a lot of functions to handle String object. | |
7.2 | 104 | ||
7.4 | 105 | you can discover all these functions on the following URL : | |
7.2 | 106 | ||
7.6 | 107 | __[[https:~~/~~/docs.oracle.com/javase/8/docs/api/java/lang/String.html#method.summary>>https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#method.summary]] __ | |
7.2 | 108 | ||
7.5 | 109 | Eg: to check if a variable "myVar" is empty or not, we refer to the isEmpty() method as ${myVar.isEmpty()}, if so then it returns true, if not it will return false. | |
7.4 | 110 | ||
111 | |||
2.3 | 112 |