Annotation of win32/dist/other/en/_test.html, revision 1.1
1.1 ! misha 1: #<!--
! 2: ###################################################################################
! 3: @main[]
! 4: <h1>Parser 3.x test page</h1>
! 5: <p>If you see this page, you have sucessfully installed Parser and trying to test it.</p>
! 6: <p>To see full paths to configuration files and DOCUMENT_ROOT comment out postprocess[] method.</p>
! 7: <p>If something is marked as red, then something is configured the wrong way or automatic detection is impossible
! 8: (related to library files and codepages search with relative paths).</p>
! 9: <hr />
! 10:
! 11: ^try{
! 12: $status_rusage_begin[$status:rusage]
! 13: $status_memory_begin[$status:memory]
! 14: }{
! 15: $exception.handled(1)
! 16: }
! 17:
! 18: <h2>Global variables defined in config auto.p</h2>
! 19:
! 20: <h3>^$CHARSETS:</h3>
! 21: ^if($CHARSETS && $CHARSETS is "hash"){
! 22: <table cellpadding="5" cellspacing="0" border="1">
! 23: ^CHARSETS.foreach[sKey;sValue]{
! 24: <tr>
! 25: <td>$sKey</td>
! 26: <td>$sValue (^check_system_file[$sValue])</td>
! 27: </tr>
! 28: }
! 29: </table>
! 30: }{
! 31: ^error[Table with charset not defined.]
! 32: <br />Probably parser can't find configuration auto.p which located near parser3 executable
! 33: <br />Чтобы убедиться в том, что он обрабатывается, добавьте инструкцию
! 34: ^^throw[^;check auto.p execution] в его метод @^;auto[] и перезагрузите страницу.
! 35: Появление ошибки после её перезагрузки будет свидетельствовать о том, что он обрабатыватся.
! 36: }
! 37:
! 38: <h3>^$SQL:</h3>
! 39: ^if($SQL && $SQL.drivers && $SQL.drivers is "table"){
! 40: ^try{
! 41: <table cellpadding="5" cellspacing="0" border="1">
! 42: <tr>
! 43: <th>protocol</th>
! 44: <th>parser driver</th>
! 45: <th>sql client library</th>
! 46: </tr>
! 47: ^SQL.drivers.menu{
! 48: <tr>
! 49: <td>$SQL.drivers.protocol</td>
! 50: <td>^if(def $SQL.drivers.driver){$SQL.drivers.driver (^check_system_file[$SQL.drivers.driver])^if(!^check_p3_sql_lib_name[$SQL.drivers.driver;parser3]){<br />^error[уверены, что указан верный файл?]}}{<br />}</td>
! 51: <td>^if(def $SQL.drivers.client){$SQL.drivers.client (^check_system_file[$SQL.drivers.client])}{<br />}</td>
! 52: </tr>
! 53: }
! 54: </table>
! 55: }{
! 56: $exception.handled(1)
! 57: ^error[^$SQL.drivers. Wrond data structure.]
! 58: <br />Probably TABs characters was replaced by spaces characters while manual editing configuration auto.p
! 59: <br />Table content:
! 60: ^printTable[$SQL.drivers]
! 61: }
! 62: }{
! 63: ^error[^$SQL.drivers not defined.]
! 64: <br />Probably parser can't find configuration auto.p
! 65: }
! 66:
! 67: <p>
! 68: ^info[DOCUMENT_ROOT]: ^if(^trim[$env:DOCUMENT_ROOT;/] eq $script_dir){equal with test script directory}{^error[^if(!def $env:DOCUMENT_ROOT){undefined}{«^;wrong»^; or test script located not in the DOCUMENT ROOT}]}^if(def $env:DOCUMENT_ROOT){ ($env:DOCUMENT_ROOT)}<br />
! 69: ^info[Путь к скрипту]: $script_dir<br />
! 70: ^info[^$response:charset]: ^if(def $response:charset){$response:charset}{^error[Undefined. Are you use UTF8?]}<br />
! 71: ^info[^$request:charset]: ^if(def $request:charset){$request:charset}{^error[Undefined. Are you use UTF8?]}<br />
! 72: ^info[^$request:uri]: $request:uri<br />
! 73: ^info[^$request:query]: $request:query^if(def $request:query){ (for get values use ^$form class)}<br />
! 74: ^info[^$SQL.connect-string]: ^if(def ${SQL.connect-string}){defined}{^info[undefined]}<br />
! 75: ^info[^$MAIL.SMTP]: ^if(def $MAIL.SMTP){defined}{undefined}<br />
! 76: ^info[^$CLASS_PATH]:
! 77: ^if($CLASS_PATH is "table"){
! 78: <br />
! 79: ^try{
! 80: <table cellpadding="5" cellspacing="0" border="1">
! 81: ^CLASS_PATH.menu{
! 82: <tr>
! 83: <td>$CLASS_PATH.path</td>
! 84: <td>^check_dir[$CLASS_PATH.path]</td>
! 85: </tr>
! 86: }
! 87: </table>
! 88: }{
! 89: $exception.handled(1)
! 90: ^error[^$CLASS_PATH. Wrong structure.]
! 91: <br />^$CLASS_PATH. must contain string or named table with column 'path'.<br />
! 92: }
! 93: }{
! 94: ^if(def $CLASS_PATH){$CLASS_PATH &mdash^; ^check_dir[$CLASS_PATH]}{^info[undefined]}<br />
! 95: }
! 96: </p>
! 97:
! 98:
! 99:
! 100: <h2>Parser demo</h2>
! 101:
! 102: <h3>Manipulations with cookie (class <a href="http://www.parser.ru/en/docs/lang/cookieclass.htm">^$cookie</a>)</h3>
! 103: <p>
! 104: Read ^$cookie:test: ^if(def $cookie:test){$cookie:test}{undefined}<br />
! 105: Write to cookie value ABC ^$cookie:test[ABC]$cookie:test[ABC] (press Reload)<br />
! 106: </p>
! 107:
! 108:
! 109:
! 110: <h3>Math operations (class <a href="http://www.parser.ru/en/docs/lang/mathclass.htm">^$math</a>)</h3>
! 111: <p>
! 112: $math_string[StRiNg]
! 113: $math_salt[^$apr1^$]
! 114:
! 115: $iNum1(^math:random(9)+1)
! 116: $iNum2(^math:random(9)+1)
! 117: ^^eval($iNum1+$iNum2): ^eval($iNum1+$iNum2)<br />
! 118: ^^math:random(1000): ^math:random(1000)<br />
! 119: ^^math:log(1000): ^try_exec{^math:log(1000)}<br />
! 120: ^^math:log10(1000): ^try_exec{^math:log10(1000)}<br />
! 121: ^^math:uuid[]: ^try_exec{^math:uuid[]}<br />
! 122: ^^math:uid64[]: ^try_exec{^math:uid64[]}<br />
! 123: ^^math:md5[$math_string]: ^try_exec{^math:md5[$math_string]}<br />
! 124: ^^math:crypt[$math_string;$math_salt]: ^try_exec{^math:crypt[$math_string;$math_salt]}<br />
! 125: ^^math:crc32[$math_string]: ^try_exec{^math:crc32[$math_string]}<br />
! 126: </p>
! 127:
! 128:
! 129: <h3>Strings manipulations (class <a href="http://www.parser.ru/en/docs/lang/stringclass.htm">^$string</a>)</h3>
! 130: <p>
! 131: $upper[ББ]
! 132: $lower[бб]
! 133: $mixed[Бб]
! 134: Definition ^$str[АбвГде] $str[АбвГде]<br />
! 135: String length ^^str.length[]: ^str.length[]<br />
! 136: Uppercase string ^^str.upper[]: ^str.upper[]^if(^mixed.upper[] ne $upper){ [^error[incorrect transformin to uppercase]]}<br />
! 137: Lowercase string ^^str.lower[]: ^str.lower[]^if(^mixed.lower[] ne $lower){ [^error[incorrect transformin to lowercase]]}<br />
! 138: First 2 chars ^^str.left(2): ^str.left(2)<br />
! 139: Last 3 chars ^^str.right(3): ^str.right(3)<br />
! 140: Substring ^^str.mid(1^;3): ^str.mid(1;3)<br />
! 141: Position of 'б' char ^^str.pos[б]: ^str.pos[б]<br />
! 142: Position of 'б' char starting from position 2 ^^str.pos[б](2): ^try_exec{^str.pos[б](2)}<br />
! 143: Position of 'X' char ^^str.pos[X]: ^str.pos[X]<br />
! 144: Replacement substring 'вГ' to XX using match ^^str.match[вГ][]{XX}: ^str.match[вГ][]{XX}<br />
! 145: $repl[^table::create{a b
! 146: в Y
! 147: Г Z}]
! 148: Replacement chars 'в' to 'Y', 'Г' to 'Z' using ^^str.replace[^$repl]: ^str.replace[$repl]<br />
! 149: ^^str.trim[both;е]: ^try_exec{^str.trim[both;е]}<br />
! 150: ^^str.trim[start;е]: ^try_exec{^str.trim[start;е]}<br />
! 151: ^^str.trim[end;е]: ^try_exec{^str.trim[end;е]}<br />
! 152: ^^str.trim[left;е]: ^try_exec{^str.trim[left;е]}<br />
! 153: ^^str.trim[right;е]: ^try_exec{^str.trim[right;е]}<br />
! 154: ^^str.base64[]: ^try_exec{$sBase64[^str.base64[]]$sBase64}<br />
! 155: ^if(def $sBase64){
! 156: # ^^string:base64[$sBase64]: ^try_exec{^string:base64[$sBase64]}
! 157: }
! 158: ^^str.js-escape[]: ^try_exec{$sEscaped[^str.js-escape[]]$sEscaped}<br />
! 159: ^if(def $sEscaped){
! 160: ^^str:js-unescape[$sEscaped]: ^try_exec{^string:js-unescape[$sEscaped]}<br />
! 161: }
! 162: </p>
! 163:
! 164:
! 165: <h3>Working with class <a href="http://www.parser.ru/en/docs/lang/inetclass.htm">^$inet</a></h3>
! 166: ^^inet:aton[10.0.0.2]: ^try_exec{^inet:aton[10.0.0.2]}<br />
! 167: ^^inet:aton[192.168.1.5]: ^try_exec{^inet:aton[192.168.1.5]}<br />
! 168: ^^inet:ntoa(167772162): ^try_exec{^inet:ntoa(167772162)}<br />
! 169: ^^inet:ntoa(3232235781): ^try_exec{^inet:ntoa(3232235781)}<br />
! 170:
! 171:
! 172:
! 173:
! 174: <h3><a name="forms">Form values manipulations</a> (class <a href="http://www.parser.ru/en/docs/lang/formclass.htm">^$form</a>)</h3>
! 175: <p>
! 176: ^$form:a: ^if(def $form:a){$form:a}{undefined}<br />
! 177: Safe conversion ^$form:a to integer: ^^form:a.int(1): ^form:a.int(1)<br />
! 178: ^if($form:tables.b){
! 179: ^form:tables.b.menu{
! 180: ^form:tables.b.line[] value ^$form:b: $form:tables.b.field
! 181: }[<br />]
! 182: }{
! 183: ^$form:b undefined
! 184: }
! 185: <br />
! 186: ^$form:qtail: ^if(def $form:qtail){$form:qtail}{undefined}<br />
! 187: ^if(!def $form:a){
! 188: <a href="?a=321&b=^taint[uri][А]&b=^taint[uri][Б]&b=^taint[uri][ВГД]?ABC#forms">click here to check reading form values</a>
! 189: }
! 190: </p>
! 191:
! 192: <h3>Manipulations with hash (class <a href="http://www.parser.ru/en/docs/lang/hashclass.htm">^$hash</a>)</h3>
! 193: <p>
! 194: <pre>
! 195: ^$hash1[
! 196:  ^; ^;^$.a[1]
! 197:  ^; ^;^$.b[2]
! 198:  ^; ^;^$.c[3]
! 199: ]
! 200: ^^hash1.foreach[key;value]{
! 201:  ^; ^;^$key=^$value
! 202: }[<^;br />^;]
! 203: </pre>
! 204: $hash1[
! 205: $.a[1]
! 206: $.b[2]
! 207: $.c[3]
! 208: ]
! 209: ^hash1.foreach[key;value]{
! 210: $key=$value
! 211: }[<br />]
! 212:
! 213: <br /><br />
! 214: Checking item with key 'a' (^^hash1.contains[a]):
! 215: ^try_exec{^if(^hash1.contains[a]){item with key 'a' exist}{^error[item with key 'a' doesn't exixt]}}
! 216: </p>
! 217:
! 218:
! 219: <h3>Manipulations with table (class <a href="http://www.parser.ru/en/docs/lang/tableclass.htm">^$table</a>)</h3>
! 220: <pre>^$tbl1[^^table::create{name col1 col2
! 221: Vasya 3 5
! 222: Dima 4 14}]</pre>
! 223: $tbl1[^table::create{name col1 col2
! 224: Vasya 3 5
! 225: Dima 4 14}]
! 226: ^$tbl1 rows quantity: ^tbl1.count[]<br />
! 227: $col[^tbl1.columns[]]
! 228: ^$tbl1 columns quantity: ^col.count[]<br />
! 229: Print columns:<br />
! 230: ^printTable[$col]
! 231:
! 232: <p>
! 233: Print content ^$tbl1:<br />
! 234: ^printTable[$tbl1]
! 235: </p>
! 236:
! 237: <pre>^$tbl2[^^table::create{name col1 col2
! 238: Vova 3 44}]</pre>
! 239: $tbl2[^table::create{name col1 col2
! 240: Vova 3 44}]
! 241: ^$tbl2 rows quantity: ^tbl2.count[]<br />
! 242:
! 243:
! 244: <p>
! 245: join ^$tbl1 to ^$tbl2 [^^tbl2.join[^$tbl1]]<br />
! 246: ^tbl2.join[$tbl1]
! 247: ^$tbl2 rows quantity ^^tbl2.count[]: ^tbl2.count[]<br />
! 248: Print table:<br />
! 249: ^printTable[$tbl2]
! 250: </p>
! 251:
! 252: <p>select table rows where col1 values are equal 3: ^^tbl2.select(^$tbl2.col1 == 3)<br />
! 253: ^printTable[^tbl2.select($tbl2.col1 == 3)]
! 254: </p>
! 255:
! 256:
! 257: <p>Making hash with tables (where hash keys are col1 values): ^$hData[^^tbl2.hash[col1][^$.distinct[tables]]]<br />
! 258: ^try{
! 259: $hData[^tbl2.hash[col1][$.distinct[tables]]]
! 260: <p>Print hash data:
! 261: <table cellpadding="2" cellspacing="0" border="1" width="35%">
! 262: <tr align="center">
! 263: <th>Key</th>
! 264: <th>Value</th>
! 265: </tr>
! 266: ^hData.foreach[sKey;tValue]{
! 267: <tr>
! 268: <td>$sKey</td>
! 269: <td>^printTable[$tValue;100%]</td>
! 270: </tr>
! 271: }
! 272: </table>
! 273: </p>
! 274: }{
! 275: $exception.handled(1)
! 276: ^error[Detected parser before 3.0.8. This method not exist.]
! 277: }
! 278: </p>
! 279:
! 280: <p>Making hash with strings (where hash keys are col2 values and values are name values): ^$hData[^^tbl2.hash[col2^;name][^$.type[string]]]<br />
! 281: ^try{
! 282: $hData[^tbl2.hash[col2;name][$.type[string]]]
! 283: <p>Print hash data:
! 284: <table cellpadding="2" cellspacing="0" border="1">
! 285: <tr align="center">
! 286: <th>Key</th>
! 287: <th>Value</th>
! 288: </tr>
! 289: ^hData.foreach[sKey;sValue]{
! 290: <tr>
! 291: <td>$sKey</td>
! 292: <td>$sValue</td>
! 293: </tr>
! 294: }
! 295: </table>
! 296: </p>
! 297: }{
! 298: $exception.handled(1)
! 299: ^error[Detected parser before 3.2.2. This method not exist.]
! 300: }
! 301: </p>
! 302:
! 303: <h3>Date manipulations (class <a href="http://www.parser.ru/en/docs/lang/dateclass.htm">^$date</a>)</h3>
! 304: <p>
! 305: ^$now[^^date::now[]]<br />
! 306: $now[^date::now[]]
! 307: ^$now.day/^$now.month/^$now.year ^${now.hour}:^${now.minute}:^$now.second: $now.day/$now.month/$now.year ${now.hour}:${now.minute}:$now.second<br />
! 308: ^$now.week: ^try_exec{$now.week}<br />
! 309: ^$now.weekyear: ^try_exec{$now.weekyear}<br />
! 310: Print now in sql format ^^now.sql-string[]: ^now.sql-string[]<br />
! 311: Print now in UNIX timestamp format ^^now.unix-timestamp[]: ^try_exec{^now.unix-timestamp[]}<br />
! 312: Print now in GMT format ^^now.gmt-string[]: ^try_exec{^now.gmt-string[]}<br />
! 313: Number of last day in current month ^^now.last-day[]: ^try_exec{^now.last-day[]}<br />
! 314: ^now.roll[day](-5)
! 315: Roll date to 5 days ahead ^^now.roll[day](-5): ^printDate[$now]<br />
! 316: ^now.roll[day](30)
! 317: Roll date to 30 days behind ^^now.roll[day](30): ^printDate[$now]<br />
! 318: </p>
! 319:
! 320:
! 321:
! 322:
! 323: <h3>Manipulations with files (class <a href="http://www.parser.ru/en/docs/lang/fileclass.htm">^$file</a>)</h3>
! 324: <p>
! 325: $save_table_name[_test.cfg]
! 326: $fname[$save_table_name]
! 327: Write table ^$tbl1 to file $save_table_name (^^tbl1.save[$fname]):
! 328: $no_file(0)
! 329: ^try{
! 330: ^tbl1.save[$fname]
! 331: ^info[File created successfully]
! 332: }{
! 333: ^if($exception.type eq "file.access"){
! 334: $exception.handled(1)
! 335: $no_file(1)
! 336: ^error[access denied]
! 337: }
! 338: }
! 339: <br />
! 340: ^^file:dirname[/$save_table_name]: ^try_exec{^file:dirname[/$save_table_name]}<br />
! 341: ^^file:basename[/$save_table_name]: ^try_exec{^file:basename[/$save_table_name]}<br />
! 342: ^^file:justname[/$save_table_name]: ^try_exec{^file:justname[/$save_table_name]}<br />
! 343: ^^file:justext[/$save_table_name]: ^try_exec{^file:justext[/$save_table_name]}<br />
! 344:
! 345: </p>
! 346: ^if(!$no_file){
! 347: <p>Get saved file information ^$fstat[^^file::stat[$fname]]:<br />
! 348: $fstat[^file::stat[$fname]]
! 349: File size [^$fstat.size]: $fstat.size<br />
! 350: cdate: $fstat.cdate.day/$fstat.cdate.month/$fstat.cdate.year<br />
! 351: adate: ^printDate[$fstat.adate]<br />
! 352: mdate: ^printDate[$fstat.mdate]<br />
! 353: </p>
! 354:
! 355: <p>
! 356: Loading data into ^$tbl3 from file DOCUMENT_ROOT/$save_table_name and out table content (^$tbl3[^^table::load[$fname]]):<br />
! 357: ^if(-f $fname){
! 358: $tbl3[^table::load[$fname]]
! 359: ^printTable[$tbl3]
! 360: }
! 361: </p>
! 362:
! 363: <p>File copy (^^file:copy[$fname^;_copy.cfg]):
! 364: ^try_exec{
! 365: ^file:copy[$fname;_copy.cfg]^info[ok]
! 366: ^try{
! 367: ^file:delete[_copy.cfg]
! 368: }{
! 369: $exception.handled(1)
! 370: }
! 371: }
! 372: </p>
! 373:
! 374: <p>File delete (^^file:delete[$fname]):
! 375: ^try{
! 376: ^file:delete[$fname]
! 377: ^info[ok]
! 378: }{
! 379: $exception.handled(1)
! 380: ^error[error during file deletion]
! 381: }
! 382: </p>
! 383: }
! 384:
! 385:
! 386: <h3>Working with class <a href="http://www.parser.ru/en/docs/lang/hashfileclass.htm">^$hashfile</a></h3>
! 387: $hashfile_name[_test]
! 388: <p>Create object: ^$hf [^$hf[^^hashfile::open[$hashfile_name]]]:
! 389: ^try{
! 390: $hf[^hashfile::open[$hashfile_name]]
! 391: ^info[object was created sucessfully]<br />
! 392:
! 393: $expires(3)
! 394: $hash1[^hf.hash[]]
! 395: Number of records: ^hash1._count[]<br />
! 396:
! 397: ^try{
! 398: $key[^math:uuid[]]
! 399: }{
! 400: $exception.handled(1)
! 401: $key[^math:random(999999999)]
! 402: }
! 403: Adding record ($key) for $expires days:
! 404: $value[^math:random(999999999)]
! 405: <pre>
! 406: ^$hf.[$key][
! 407:  ^;  ^;^$.value[$value]
! 408:  ^;  ^;^$.expires($expires)
! 409: ]
! 410: </pre>
! 411: $hf.[$key][
! 412: $.value[$value]
! 413: $.expires($expires)
! 414: ]
! 415:
! 416: Cleanup hashfile from expired records (^^hf.cleanup[]):
! 417: ^try_exec{^hf.cleanup[]^info[ok]}<br /><br />
! 418:
! 419: $limit(5)
! 420: Print hashfile content (max $limit records):<br />
! 421: $cnt(0)
! 422: ^hf.foreach[k;v]{^if($cnt < $limit){
! 423: $k=^v.format[%d]<br />
! 424: ^cnt.inc(1)
! 425: }}
! 426: <br />
! 427:
! 428: Close hashfile files and release locks (^^hf.release[]):
! 429: ^try_exec{^hf.release[]^info[ok]}<br />
! 430: }{
! 431: $exception.handled(1)
! 432: ^if($exception.type eq "file.access"){
! 433: ^error[access denied]
! 434: }{
! 435: ^error[can't create object]
! 436: }
! 437: }
! 438: </p>
! 439:
! 440:
! 441: <h3>Manipulations with enviroment variables (class <a href="http://www.parser.ru/en/docs/lang/envclass.htm">^$env</a>)</h3>
! 442: $env_table[^table::create{name description
! 443: SERVER_NAME DNS Server name
! 444: QUERY_STRING For get values use ^$form class
! 445: HTTP_REFERER
! 446: HTTP_USER_AGENT Browser USER_AGENT string
! 447: HTTP_X_FORWARDED_FOR Filled if visitor come through proxy server
! 448: REMOTE_HOST
! 449: REMOTE_ADDR Visitors' IP address
! 450: PARSER_VERSION Parser3 version (if not defined - parser3 before 3.1.5)
! 451: }]
! 452:
! 453: $is_env_defined(0)
! 454: <table cellpadding="2" cellspacing="0" border="1">
! 455: <tr>
! 456: <th>Variable</th>
! 457: <th>Value</th>
! 458: <th><a href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html">Comment</a></th>
! 459: </tr>
! 460: ^env_table.menu{
! 461: <tr>
! 462: <td>$env_table.name</td>
! 463: <td>^if(def $env:[$env_table.name]){$env:[$env_table.name]^is_env_defined.inc(1)}{<br />}</td>
! 464: <td>^if(def $env_table.description){$env_table.description}{<br />}</td>
! 465: </tr>
! 466: }
! 467: </table>
! 468: ^if(!$is_env_defined){
! 469: <p>^error[No one enviroment variable defined.]</p>
! 470: }
! 471:
! 472:
! 473:
! 474:
! 475: <h3>Working with SQL</h3>
! 476: <p>
! 477: ^if(def ${SQL.connect-string}){
! 478: $sqlquery[SELECT 2+2^if(^SQL.connect-string.left(6) eq "oracle"){ from dual}]
! 479: ^^int:sql{$sqlquery}:
! 480: ^try{
! 481: ^connect[$SQL.connect-string]{
! 482: $sqlTest(^int:sql{$sqlquery}[$default{0}])
! 483: }
! 484: $sqlTest^if($sqlTest != 4){ [^error[Ups. You SQL server calculate 2+2 very strange...]]}<br />
! 485: ^rem{
! 486: # закомментарено, т.к. не доделал...
! 487: $lower_string[абв]
! 488: $upper_string[АБВ]
! 489: <p>SQL преобразование строк к верхнему регистру:
! 490: ^connect[$SQL.connect-string]{
! 491: ^try{
! 492: $test_string[^string:sql{SELECT UPPER('$lower_string')}[$.default{}]]
! 493: ^if($upper_string eq $test_string){
! 494: кодировки настроены правильно
! 495: }{
! 496: кодировки настроены не корректно. Исходная строка: '$lower_string'. Результат: '$test_string'. Должно быть: '$upper_string'.
! 497: }
! 498: }{
! 499: <b>синтаксис запроса не подходит для вашего SQL сервера.</b>
! 500: $exception.handled(1)
! 501: }
! 502: }
! 503: </p>
! 504: }
! 505: }{
! 506: ^if($exception.type eq "sql.connect"){
! 507: ^error[Can't connect to SQL server.] Probably wrong username/password combination or incorrect connection string.
! 508: $exception.handled(1)
! 509: }{
! 510: ^if($exception.type eq "sql.execute"){
! 511: ^error[Query execution error.], but connection to SQL server establish successfully. So strange, because SQL query is very simple
! 512: $exception.handled(1)
! 513: }{
! 514: ^error[Problems with SQL operations.] Probably SQL drivers not found.
! 515: <br />Error message:
! 516: <blockquote>
! 517: ^taint[html][$exception.comment]
! 518: ^if(def $exception.source){<br /><b>^taint[html][$exception.source]</b>}
! 519: </blockquote>
! 520: $exception.handled(1)
! 521: }
! 522: }
! 523: }
! 524: }{
! 525: ^error[^$SQL.connect-string not defined]. Testing impossible.
! 526: }
! 527: </p>
! 528:
! 529:
! 530: <h3>Manipulations with XML</h3>
! 531: <p>
! 532: Create xdoc:<br />
! 533: ^try{
! 534: $xml_txt[<?xml version="1.0" encoding="$request:charset" ?>
! 535: <document>
! 536: <t attr="Hello" n="123"/>
! 537: <t attr="Bye" n="234" n2="xxx"/>
! 538: <text>Text</text>
! 539: </document>]
! 540: <pre>
! 541: ^taint[html][^$document[^^xdoc::create{$xml_txt}]]
! 542: </pre>
! 543: $document[^xdoc::create{$xml_txt}]
! 544: Object xdoc created successfully.<br />
! 545:
! 546: Get ^taint[html][<t />] elements ^$elements[^^document.select[//t]] :<br />
! 547: $elements[^document.select[//t]]
! 548: ^taint[html][<t />] elements quantity: ^elements._count[]<br />
! 549: Print elements using foreach:<br >
! 550: ^elements.foreach[key;node]{
! 551: name: '$node.nodeName', type: '$node.nodeType', attributes quantity: '^node.attributes._count[]', attributes: ^node.attributes.foreach[akey;aval]{$akey='$aval.value'}[, ]
! 552: }[<br />]
! 553: }{
! 554: ^if($exception.type eq "parser.runtime"){
! 555: ^error[You need install parser with XML...] Probably XML libs not installed properly...
! 556: $exception.handled(1)
! 557: }
! 558: ^if($exception.type eq "xml"){
! 559: $no_file(1)
! 560: $exception.handled(1)
! 561: ^error[Problems with XML operations...] Probable because of charset problems...
! 562: <br />Сообщение об ошибке:
! 563: <blockquote>
! 564: ^taint[html][$exception.comment]
! 565: ^if(def $exception.source){<br /><b>^taint[html][$exception.source]</b>}
! 566: </blockquote>
! 567: }
! 568: }
! 569: </p>
! 570:
! 571:
! 572: <h3>Working with classes <a href="http://www.parser.ru/en/docs/lang/statusclass.htm">Status</a> and <a href="http://www.parser.ru/en/docs/lang/memoryclass.htm">Memory</a></h3>
! 573: $fields[^table::create{section name measure description
! 574: rusage utime secs process time
! 575: rusage stime secs time for reading files
! 576: rusage maxrss blocks memory, used by process
! 577: memory used KB user
! 578: memory free KB free (fragmentated)
! 579: memory ever_allocated_since_compact KB allocated since last garbage collection
! 580: memory ever_allocated_since_start KB allocated since start
! 581: }]
! 582:
! 583: <p>
! 584: ^try{
! 585: <table cellpadding="2" cellspacing="0" border="1">
! 586: <tr>
! 587: <th rowspan="2">Field</th>
! 588: <th rowspan="2">Description</th>
! 589: <th colspan="3">Value</th>
! 590: </tr>
! 591: <tr>
! 592: <th>on start</th>
! 593: <th>now</th>
! 594: <th>after ^^memory:compact[]</th>
! 595: </tr>
! 596: $status_rusage_now[$status:rusage]
! 597: $status_memory_now[$status:memory]
! 598: ^try{
! 599: $tbl1[]
! 600: $tbl2[]
! 601: $tbl3[]
! 602: $hash1[]
! 603: $document[]
! 604: $elements[]
! 605: $tables_hash[]
! 606: $hf[]
! 607: $k[]
! 608: $v[]
! 609:
! 610: ^memory:compact[]
! 611: ^memory:compact[]
! 612: $is_compact_work(1)
! 613: $status_rusage_compact[$status:rusage]
! 614: $status_memory_compact[$status:memory]
! 615: }{
! 616: $exception.handled(1)
! 617: }
! 618: ^fields.menu{
! 619: <tr>
! 620: <td>^$status:${fields.section}.$fields.name^if(def $fields.measure){ ($fields.measure)}</td>
! 621: <td>$fields.description</td>
! 622: <td>^if($fields.section eq "rusage"){$status_rusage_begin.[$fields.name]}{$status_memory_begin.[$fields.name]}</td>
! 623: <td>^if($fields.section eq "rusage"){$status_rusage_now.[$fields.name]}{$status_memory_now.[$fields.name]}</td>
! 624: ^if(!$is_compact_work && ^fields.line[] == 1){
! 625: <td rowspan="^fields.count[]">^error[Method doesn't exist in used parser3 version.]</td>
! 626: }{
! 627: <td>^if($fields.section eq "rusage"){$status_rusage_compact.[$fields.name]}{$status_memory_compact.[$fields.name]}</td>
! 628: }
! 629: </tr>
! 630: }
! 631: </table>
! 632: }{
! 633: $exception.handled(1)
! 634: ^error[In this parser3 version methods ^$status:rusage or ^$status:memory doesn't works.]
! 635: }
! 636: </p>
! 637: #end @main[]
! 638:
! 639:
! 640:
! 641: ###########################################################################
! 642: @auto[filespec]
! 643: ^if(def $filespec){
! 644: $script_dir[^trim[^filespec.match[/(?:\w+\.html?)?^$][i]{/};/]]
! 645: }
! 646: $document_root[^if(def $env:DOCUMENT_ROOT){$env:DOCUMENT_ROOT}{$script_dir}]
! 647: #end @auto[]
! 648:
! 649:
! 650:
! 651:
! 652: ###########################################################################
! 653: # trim leading and trailing chars $char (spaces by default)
! 654: @trim[str;char][chr;tbl]
! 655: ^if(def $str){
! 656: $chr[^if(def $char){$char}{\s}]
! 657: $str[^str.match[^^$chr*][]{}]
! 658: $tbl[^str.match[^^(.*[^^$chr])$chr*^$]]
! 659: $result[$tbl.1]
! 660: }{
! 661: $result[]
! 662: }
! 663: #end @trim[]
! 664:
! 665:
! 666:
! 667: ###########################################################################
! 668: @check_dir[dir]
! 669: ^if(def $dir && -d $dir){directory exist}{^error[directory doesn't exist]}
! 670: #end @check_dir[]
! 671:
! 672:
! 673:
! 674: ###########################################################################
! 675: # get relative path to file
! 676: @get_relative_path[from;to][ff;tt;f;t;p;up;ne;pos;i;down]
! 677: $ff[^trim[^from.match[\\][g]{/};/]]
! 678: $tt[^trim[^to.match[\\][g]{/};/]]
! 679: $f[^ff.lsplit[/]]
! 680: $t[^tt.lsplit[/]]
! 681:
! 682: $p[]
! 683: $up[/]
! 684: $ne(0)
! 685: $pos(0)
! 686: ^for[i](1;^f.count[]){
! 687: ^if(!$ne && $f.piece eq $t.piece){
! 688: $p[${p}$f.piece/]
! 689: $pos($i)
! 690: }{
! 691: $ne($i)
! 692: $up[${up}../]
! 693: }
! 694: ^f.offset(1)
! 695: ^t.offset(1)
! 696: }
! 697: $down[]
! 698: ^for[i]($pos;^t.count[]-1){
! 699: ^t.offset[set]($i)
! 700: $down[${down}$t.piece^if($i != ^t.count[]-1){/}]
! 701: }
! 702: $result[${up}$down]
! 703: #end @get_relative_path[]
! 704:
! 705:
! 706:
! 707: ###########################################################################
! 708: # override unhandled_exception for show parser error (if occur) in this test
! 709: @unhandled_exception[exception;stack]
! 710: $response:status(500)
! 711: <html>
! 712: <head><title>Unhandled Exception</title></head>
! 713: <body>
! 714: <H1>Unhandled Exception</H1>
! 715: <pre>^taint[html][$exception.comment]</pre>
! 716: ^if(def $exception.source){
! 717: <b>$exception.source</b><br>
! 718: <pre>^taint[html][$exception.file^($exception.lineno^)]</pre>
! 719: }
! 720: ^if(def $exception.type){exception.type=$exception.type}
! 721: ^if($stack){
! 722: <hr />
! 723: ^stack.menu{<tt>$stack.name</tt> $stack.file^($stack.lineno^)<br>}
! 724: }
! 725: #for [x] MSIE friendly
! 726: <span style="font-size:1px">^for[i](0;512/7){ ^;}</span>
! 727: </body>
! 728: #end @unhandled_exception[]
! 729:
! 730:
! 731:
! 732: ###########################################################################
! 733: @printDate[dtDate]
! 734: $result[^if($dtDate is "date"){$dtDate.day/$dtDate.month/$dtDate.year}]
! 735: #end @printDate[dt]
! 736:
! 737:
! 738:
! 739: ###########################################################################
! 740: @printTable[tTable;sTableWidth][tCols;sColumnWidth]
! 741: ^if($tTable is "table" && $tTable){
! 742: <table cellpadding="3" cellspacing="0" border="1"^if(def $sTableWidth){ width="$sTableWidth"}>
! 743: $tCols[^tTable.columns[]]
! 744: $sColumnWidth[^eval(100/(^tCols.count[]+1))[%d]]
! 745: <tr>
! 746: <th width="^eval(100-$sColumnWidth*^tCols.count[])%">string</th>
! 747: ^tCols.menu{<th width="$sColumnWidth%">$tCols.column</th>}
! 748: </tr>
! 749: ^tTable.menu{
! 750: <tr>
! 751: <td>^tTable.line[]</td>
! 752: ^tCols.menu{<td>$tTable.[$tCols.column]</td>}
! 753: </tr>
! 754: }
! 755: </table>
! 756: }
! 757: #end @printTable[]
! 758:
! 759:
! 760:
! 761: ###########################################################################
! 762: @update_pattern[text]
! 763: ^if(def $text){
! 764: $result[^text.match[(\\|\.)][g]{\$match.1}]
! 765: }{
! 766: $result[]
! 767: }
! 768: #end @update_pattern[]
! 769:
! 770:
! 771:
! 772: ###########################################################################
! 773: @error[text]
! 774: $result[<b style="color:red">$text</b>]
! 775: #end @error[]
! 776:
! 777:
! 778:
! 779: ###########################################################################
! 780: @info[text]
! 781: $result[<b>$text</b>]
! 782: #end @info[]
! 783:
! 784:
! 785:
! 786: ###########################################################################
! 787: # use postprocess for cut paths and don't show them to everyones
! 788: @postprocess[sBody]
! 789: $result[$sBody]
! 790: ^if(def $sqldriversdir){$result[^result.match[^update_pattern[$sqldriversdir]][gi]{^$sqldriversdir}]}
! 791: ^if(def $charsetsdir){$result[^result.match[^update_pattern[$charsetsdir]][gi]{^$charsetsdir}]}
! 792: ^if(def $document_root){$result[^result.match[^update_pattern[$document_root]][gi]{comment postprocess method for view}]}
! 793: ^if(def $script_dir){$result[^result.match[^update_pattern[$script_dir]][gi]{comment postprocess method for view}]}
! 794: #end @postprocess[]
! 795:
! 796:
! 797:
! 798: ###########################################################################
! 799: # check file
! 800: @check_system_file[path][relative_path;file_stat;path_drive;root_drive]
! 801: ^if(def $path){
! 802: $path_drive[^get_drive_letter[$path]]
! 803: ^if(^path.left(1) ne "/" && !^path.match[^^[a-z]:\\][i]){
! 804: $result[relative path. ^info[checkout is impossible]]
! 805: }{
! 806: ^if(def $path_drive && $path_drive ne ^get_drive_letter[$document_root]){
! 807: $result[^info[on different drive, checkout is impossible]]
! 808: }{
! 809: ^rem{ *** path started with X:\\ - win paths, case insensitive *** }
! 810: $path[^path.match[^^[a-z]:\\(.+)][i]{^match.1.lower[]}]
! 811:
! 812: $relative_path[^get_relative_path[$document_root;$path]]
! 813: ^if(-f $relative_path){
! 814: ^try{
! 815: $file_stat[^file::stat[$relative_path]]
! 816: $result[^if(!$file_stat.size){^error[$file_stat.size Bytes]}{$file_stat.size Bytes}]
! 817: }{
! 818: $exception.handled(1)
! 819: $result[found but ^error[access denied]]
! 820: }
! 821: }{
! 822: $result[^error[not found]]
! 823: }
! 824: }
! 825: }
! 826: }{
! 827: $result[]
! 828: }
! 829: #end @check_system_file[]
! 830:
! 831:
! 832:
! 833: ###########################################################################
! 834: @get_drive_letter[sPath]
! 835: $result[]
! 836: ^sPath.match[^^([a-z]):(?:\\|/).+][i]{$result[^match.1.lower[]]}
! 837: #end @get_drive_letter[]
! 838:
! 839:
! 840:
! 841: ###########################################################################
! 842: # check parser3 sql lib name (many people write path to sql client lib but not parser3 lib)
! 843: @check_p3_sql_lib_name[sFile;sPattern][tPart]
! 844: $result(1)
! 845: ^if(def $sFile){
! 846: $tPart[^sFile.rsplit[/]]
! 847: ^if(!^tPart.piece.match[$sPattern]){$result(0)}
! 848: }
! 849: #end @check_p3_sql_lib_name[]
! 850:
! 851:
! 852:
! 853: ###########################################################################
! 854: @try_exec[jCode;sErrorInfo]
! 855: ^try{
! 856: $result[$jCode]
! 857: }{
! 858: $exception.handled(1)
! 859: $result[^error[^if(def $sErrorInfo){$sErrorInfo}{Used Parser 3 version don't have this feature.}]]
! 860: }
! 861: #end @try_exec[]
! 862: #--> To make this test work, Parser should be made a processor of documents with this extention, what now is not observed. #
E-mail: