This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iedoc2bash.xml
371 lines (311 loc) · 10.2 KB
/
iedoc2bash.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<!--
Copyright 2011 Jan Friesse <jfriesse@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<!--- generate top of file -->
<xsl:text>#!/bin/bash
# Copyright 2011 Jan Friesse <jfriesse@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file has been automatically generated via XSL
usage() {
echo "$0: command [param...]"
echo "where command is one of:"
echo " init"
echo " start"
echo " stop"
echo " help"
</xsl:text>
<xsl:apply-templates select="//function" mode="usage-list" />
<xsl:text>
echo
echo "Use $0 help command to get full description of command."
echo "$0 help top can be used for display help generated from top xml element (description of locators, ...)"
exit 1
}
help() {
case "$1" in
"init")
echo "init [browser_url] [browser] [host] [port]"
echo "Initialize session"
echo " browser_url - url to test (default http://localhost/)"
echo " browser - browser to start (default *firefox)"
echo " host - host with selenium server (default 127.0.0.1)"
echo " port - port with selenium selenium (default 4444)"
echo
echo "export commands are returned and should be used in eval \`$0 init\` way"
;;
"start")
echo "start"
echo "Start new browser session"
echo "export command is returned and should be used as session in eval \`$0 start\` way"
;;
"stop")
echo "stop"
echo "Stop browser session (close browser)"
echo "shell commands are returned to unset SELENIUM_BASH_SESSION"
;;
"top")
</xsl:text>
<xsl:apply-templates select="//top" mode="help" />
<xsl:text> ;;
"help")
echo "help command"
echo "Displays help for command"
;;
</xsl:text>
<xsl:apply-templates select="//function" mode="cmd-help" />
<xsl:text>*)
usage
;;
esac
}
# Initialize session: [browser_url] [browser] [host] [port]
# browser_url - Browser URL (default http://localhost/)
# browser - Browser to start (default *firefox)
# host - Host with selenium server (default 127.0.0.1)
# port - Port with selenium server (default 4444)
# Echoed is export command with variables SELENIUM_BASH_[HOST|PORT|BROWSER|BROWSER_URL]
init() {
browser_url=${1:-http://localhost/}
browser=${2:-*firefox}
host=${3:-127.0.0.1}
port=${4:-4444}
echo "export SELENIUM_BASH_HOST='$host'; export SELENIUM_BASH_PORT='$port';"
echo "export SELENIUM_BASH_BROWSER='$browser'; export SELENIUM_BASH_BROWSER_URL='$browser_url';"
}
# Internal function to display error and exit: [error_msg...]
err() {
echo "$@" >&2
exit 1
}
# Quote url: url
url_quote() {
y="$@";
y=${y//\\/\\\\}
y=${y// /+}
for ((i = 0; i < ${#y}; i++));do
c=${y:$i:1}
[[ "$c" =~ [A-Za-z0-9+] ]] && echo -n "$c" || (echo -n "%`printf '%02x' \'\"$c\" | rev | cut -b -2 | rev`")
done
}
# Get response from server: url
http_get() {
which curl >/dev/null 2>&1 && curl -s "$1" || wget -q "$1" -O -
}
# Run command: command [args...]
# command - command to execute
# args - Argument for commands
do_command() {
if [ "$SELENIUM_BASH_HOST" == "" ] || [ "$SELENIUM_BASH_PORT" == "" ];then
err "SELENIUM_BASH_HOST or SELENIUM_BASH_PORT is not initialized"
fi
url="http://$SELENIUM_BASH_HOST:$SELENIUM_BASH_PORT/selenium-server/driver/?cmd=`url_quote $1`"
shift
i=0
for param in "$@";do
i=$(($i+1))
url="$url&$i=`url_quote \"$param\"`"
done
[ "$SELENIUM_BASH_SESSION" != "" ] && url="$url&sessionId=$SELENIUM_BASH_SESSION"
response=`http_get "$url"`
res="$?"
[ "$res" != "0" ] && err "http_get error: $res"
[ "${response:0:2}" != "OK" ] && err "Server error: $response" || echo "$response"
}
# Get response stored in string: command [args]
get_string() {
cmd="$1"
shift
res=`do_command "$cmd" "$@"`
[ "$?" != 0 ] && exit 1
echo "${res:3}"
}
# Start browser
start() {
if [ "$SELENIUM_BASH_BROWSER_URL" == "" ] || [ "$SELENIUM_BASH_BROWSER" == "" ];then
err "SELENIUM_BASH_BROWSER or SELENIUM_BASH_BROWSER_URL is not initialized"
fi
res=`get_string "getNewBrowserSession" "$SELENIUM_BASH_BROWSER" "$SELENIUM_BASH_BROWSER_URL"`
[ "$?" != 0 ] && exit 1
echo "export SELENIUM_BASH_SESSION='$res';"
}
# Stop browser
stop() {
do_command "testComplete"
echo "unset SELENIUM_BASH_SESSION; export SELENIUM_BASH_SESSION;"
}
</xsl:text>
<!-- Function definitions -->
<xsl:apply-templates select="//function" mode="definition" />
<!-- main -->
<xsl:text># Main
[ "$1" == "" ] && usage
cmd="$1"
shift
case "$cmd" in
"init")
init "$@"
;;
"start")
start
;;
"stop")
stop
;;
"help")
help "$@"
;;
</xsl:text>
<xsl:apply-templates select="//function" mode="main" />
<xsl:text>*)
usage
;;
esac
</xsl:text>
</xsl:template>
<xsl:template match="function" mode="definition">
<!-- Func definition -->
<xsl:text># Generated wrapper for </xsl:text>
<xsl:value-of select="@name" />
<xsl:text> call fn_</xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','_$1'))" />
<xsl:text>() { </xsl:text>
<xsl:text> [ "${#@}" -gt "</xsl:text>
<xsl:value-of select="count(./param)" />
<xsl:text>" ] && err "Too much arguments" </xsl:text>
<xsl:choose>
<xsl:when test="count(./return) = 0">
<xsl:text> do_command</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> get_string</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> "</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>"</xsl:text>
<xsl:text> "$@"</xsl:text>
<xsl:if test="count(./return) = 0">
<xsl:text> >/dev/null</xsl:text>
</xsl:if>
<xsl:text> } </xsl:text>
</xsl:template>
<xsl:template match="function" mode="main">
<xsl:text>"</xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','-$1'))" />
<xsl:text>") fn_</xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','_$1'))" />
<xsl:text> "$@" ;; </xsl:text>
</xsl:template>
<xsl:template match="function" mode="usage-list">
<xsl:text> echo " </xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','-$1'))" />
<xsl:text>" </xsl:text>
</xsl:template>
<xsl:template match="function" mode="cmd-help">
<xsl:text> "</xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','-$1'))" />
<xsl:text>") </xsl:text>
<!-- command name + arguments -->
<xsl:text> echo "</xsl:text>
<xsl:value-of select="lower-case(replace(@name,'([A-Z])','-$1'))" />
<xsl:apply-templates select="./param" mode="cmd-help" />
<!-- comment -->
<xsl:text>" echo '</xsl:text>
<xsl:apply-templates select="./comment" mode="cmd-help" />
<xsl:text>' </xsl:text>
<xsl:text> echo </xsl:text>
<!-- parameters -->
<xsl:apply-templates select="./param" mode="cmd-help2" />
<!-- description -->
<xsl:text> ;; </xsl:text>
</xsl:template>
<xsl:template match="param" mode="cmd-help">
<xsl:text> [</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="comment" mode="cmd-help">
<xsl:variable name="search">'</xsl:variable>
<xsl:variable name="replace">'\\''</xsl:variable>
<xsl:variable name="text"><xsl:apply-templates /></xsl:variable>
<xsl:value-of select="replace(replace(replace($text,$search,$replace),' ',' '),' *',' ')" />
</xsl:template>
<xsl:template match="param" mode="cmd-help2">
<xsl:text> echo ' </xsl:text>
<xsl:value-of select="@name" />
<xsl:text> - </xsl:text>
<xsl:variable name="search">'</xsl:variable>
<xsl:variable name="replace">'\\''</xsl:variable>
<xsl:variable name="text"><xsl:apply-templates /></xsl:variable>
<xsl:value-of select="replace(replace(replace($text,$search,$replace),' ',' '),' *',' ')" />
<xsl:text>' </xsl:text>
</xsl:template>
<xsl:template match="top" mode="help">
<xsl:text> echo '</xsl:text>
<xsl:apply-templates mode="help" />
<xsl:text>' </xsl:text>
</xsl:template>
<xsl:template match="text()" mode="help">
<xsl:variable name="text"><xsl:value-of select='.' /></xsl:variable>
<xsl:variable name="search">'</xsl:variable>
<xsl:variable name="replace">'\\''</xsl:variable>
<xsl:value-of select="replace(replace(replace(replace($text,$search,$replace),' ',' '),' *',' '),'^ *','')" />
</xsl:template>
<xsl:template match="h3" mode="help">
<xsl:text> = </xsl:text>
<xsl:apply-templates mode="help" />
<xsl:text> = </xsl:text>
</xsl:template>
<xsl:template match="p" mode="help">
<xsl:text> </xsl:text>
<xsl:apply-templates mode="help" />
</xsl:template>
<xsl:template match="blockquote" mode="help">
<xsl:text> </xsl:text>
<xsl:apply-templates mode="help" />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="li" mode="help">
<xsl:param name="indent" />
<xsl:text> </xsl:text>
<xsl:value-of select="$indent" />
<xsl:text>* </xsl:text>
<xsl:apply-templates mode="help">
<xsl:with-param name="indent">
<xsl:value-of select="$indent" />
<xsl:text> </xsl:text>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="ul|ol|dl" mode="help">
<xsl:param name="indent" />
<xsl:apply-templates mode="help" >
<xsl:with-param name="indent"><xsl:value-of select="$indent" /></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>