|
 |
 |
XactScript (Lexml version 2) language specification
(c)2004 XactSystems, Inc.
All XactScript control tags begin with an underscore (_) character. All other tags are specific to the renderer implementation, with the simplest renderer being the HTML renderer which simply passes through other tags as native HTML tags. Other renderers may process tags to produce PDF or PostScript or other types of output.
XactScript Control Tags
<_xactscript>: Function: This is the "root tag" of all XactScript documents. All XactScript documents must begin with <_xactscript ...> and end with </_xactscript>. It also contains optional attributes to control the characteristics of the document.
Attributes:
- name: This is an optional name for the document. This along with the author and version attributes are simply for documentation purposes as the moment although they may be used in the future for document indexing or revision control or other purposes.
- author: This is an optional author name for the document.
- version: This is an optional version for the document.
- options: This attribute contains option expressions seperated by commas and can be used to toggle certain behaviors with regard to how the page is rendered, cached, delivered, etc. Some feature options are specific to a given renderer and will not function if the document is rendered using other renderers.
<_load>: Function: This tag is used to load instances of objects or, if the given connection type supports it, "static references" enabling static methods in objects to be called. Constructor arguments can be specified using the <_arg> tag described below.
Attributes:
- name: This is the name of the variable to load the object into. Name can be given with or without the proper $ character, but the "$variable" form is preferred to just "variable."
- class: This is the name of the object class to create a new instance of. This name is totally dependant upon connection type. For example, using the "jvm" connection type (local Java virtual machine) the class argument would be a Java class name.
- connection: The connection specifies how the object is to be reached. The default value is "jvm" meaning that we are loading a class from the local Java virtual machine. Other types that may be supported in the future might be "corba," "rmi," and "xmlrpc."
- static: If this is set to "yes" then a static reference will be loaded. A static reference allows static methods in object classes to be called without actually creating an instance of the object. Not all connection types may support static references, and an error will be generated if you attempt to load a static reference for a connection type that doesn't support this feature.
Example: <_load name="$customer" class="some.tree.location.CustomerManager" connection="jvm">
<_arg name="cust_id" value="$customer.id:-1"/>
<_arg name="cust_name" value="$customer.name:-1"/>
<_arg name="cust_note">
This customer was automatically created at <_print name="$time"/>.
</_arg>
</_load> <_arg>: Function: This tag specifies an argument to a method called through a <_load>, <_call>, or <_if> tag. It can be used either with a "value" attribute or with the value being whatever is contained within the tags.
Attributes:
- name: Name of argument
- value: Optional value; if this attribute is not present than whatever is contained within tags will be parsed and counted as the argument. Any other tag including other control tags may be used inside arguments to generate arguments from other data. If the value of this attribute is a variable, whatever is contained within the variable will be passed as the argument. Note that variables will only be exapanded if this attribute is used. Variables will not be expanded from the tag body.
<_onerror>: Function: This tag can be used inside any tag that calls a method (like _arg) to specify something to do if an error occurs. If an error matching the error mask occurs, whatever is contained within the _onerror tag will be parsed, executed, and output.
Attributes:
- error: The name of the error to match, * and ? wildcards permitted.
Example: error="*SQL*" would match any error whose name contains the string "SQL." Matches are case insensitive.
Note that when onerror executes, it creates a map called $error with these values: $error.name - Name of error $error.detail - A detail such as the name of a missing argument $error.message - A full error message $error.type - Severity of error
Examples:
<!-- substring from 2 to 4; ie. "John" returns "hn" -->
<_call name="$string" method="substring" assign="$newstring">
<_arg name="1" value="2"/>
<_arg name="2" value="4"/>
<_onerror error="*OutOfBounds*">
The string has to be at least 4 characters!
<_print name="$error.name"/>
<_print name="$error.detail"/>
</_onerror>
</_call>
<_call name="$customer" method="getCustomerId" assign="$customer.id">
<_onerror error="*SQL*">
<_set name="$session.errormsg" value="$error.message"/>
A database error occurred. <a href="senderror.xact">Click here</a> to report this problem to the site administrator.
<_end/>
</_onerror>
</_call> <_call>: Function: The <_call> tag is the primary tag used to call methods in objects. Results can be echoed in string form to the output or assigned to a variable. Arguments can be passed into the method using _arg tags. (See section on arguments, default argument names, and user-friendly argument name specification below.)
Attributes:
- name: This is the variable name containing the object whose method is being called. This is the same variable that you specified when you used the <_load> tag to load the object.
- asarg: The results of calls can be used as arguments to other calls using this argument. If a <_call> tag is placed inside a <_call> or method-calling <_if> statement with this attribute, the result of the call is passed to the previous call as an argument.
- method: This is the name of the method within the object being called.
- quiet: The quiet attribute affects methods that have a specified argument to automatically recieve the output stream. This can be configured in the configuration of user-friendly argument names (see section below on argument names). If this attribute is 'yes' then a null output rather than the real output will be passed for this argument if it is present. Otherwise this attribute has no effect.
- echo: If this attribute is 'yes' then the return value of the method being called will be echoed in string form if possible. If this is not possible, nothing will be echoed. (Whether or not this is possible may depend on object type and/or the connection type through which this object is being reached.)
- assign: This attribute designates the name of a variable to assign the return value of this method to. If this attribute is not present, the return value will be assigned to the default variable "$result".
<_if>: Function: The <_if> tag allows comparisons to be done and blocks of code to be executed or not executed depending upon the result. An <_if> may only contain an expression to compare existing variables and values or may contain an implied call to a method whose return value can be checked within the expression.
Attributes:
- expr: Comparison expression (see section on if expressions below).
- cs: Toggles case sensitivity for string comparisons; default is 'no'.
*In addition to these, all the attributes of <_call> may be present except asarg.f these are present, an implied call will be executed before the expression is checked and the variable "$result" (or another name if specified in the assign attribute) will be available in the expression containing the return value of the called method. The tags <_arg>, <_onerror>, and <_call> (with asarg) may be used within an <_if> tag with an implied call to provide arguments and error handling for the called method.
Note that an <_if> tag with only an expression should contain nothing, while one with an implied call can contain only arguments and error handling tags. The tags <_else>, <_endif>, and <_elseif> are used to terminate a conditional block of code. These are seperate tags. (Look at the code examples below.)
If Expression Syntax:
If expressions are given a special syntax in our markup language due to XML's handling of special characters commonly used in if expressions like &, |, ^, etc. XML interprets these as special escape characters, so they are awkward to use as operators in an expression. Instead, a syntax was created in which two and three letter abbreviations are used as operators and all arguments in an if expression are seperated by spaces. If the value being compared contains a space, the space may be escaped by using a blackslash (\) before the space.
Allowed comparison operators: eq - Equals (==) ne - Not equal to (!=) lt - Less than (<) le - Less than or equal to (<=) gt - Greater than (>) ge - Greater than or equal to (>=) mod - Modulus (value1 % value2 == 0) (always false for non-numeric values) matches - Wildcard match (* and ? allowed) is - Comparison against 'meta-values' (empty, number, null, unset, true, false)
Allowed logicals: and, or, not, xor
The meaning of the 'meta-values' are: is null - self-explanatory is unset - synonym for is null is empty - null, empty string, all spaces, etc. is number - if value is numeric is true - string begins with 1, y, Y, t, or T is false - same as 'is not true'
The matches operator can be used to do wildcard matches as shown
above. The 'not' keyword can be used with any operator. (e.g.
'is not' or 'not matches')
Allowed logical operators: and, or, not, xor
Expresssion Examples: "($variable eq 1) or ($variable eq 2)"
"$somevalue ne 0"
"$sentence eq Hello\ my\ name\ is\ John"
"($somevalue is not number) and ($somevalue is not empty)"
"(($somevalue gt 0) and ($anothervalue gt 0)) or ($i eq 1)"
If Tag Examples: <_if expr="($customer.id eq 0) or ($customer.name is empty)"/>
Customer information was not entered correctly. Please
press the Back arrow on your browser and re-enter.
<_endif/>
<_if expr="$form.password ne $customer_record.password" cs="yes"/>
Your password is incorrect.
<_endif/>
<_if name="$order" method="gettotal" assign="$ord_total" expr="$result eq 0"/>
Your order total is 0.
<_else/>
Your order total is <_print name="$ord_total"/>
<_endif/> <_elseif>: Function: The <_elseif> tag is equivalent to an <_else> tag followed by another <_if> block. Attributes are identical to <_if>. <_else>: Function: The <_else> tag inverts the state of the previous <_if>. Tag should be empty and closed immediately. (e.g. "<_else/>" in XML)
Attributes: none <_endif>: Function: The <_endif> tag ends an if/else block. Tag should be empty and closed immediately.
Attributes: none <_set>: Function: This tag sets the value of a variable to either the text contained in the value attribute if present or the contents of the <_set> tag if not.
Attributes:
- name: Name of variable (with $ sign) to assign value to. (See variables section below for more information on variable behavior.)
- value: If this attribute is present, the string contained within it will be assigned to the variable. If this attribute is not present, whatever is contained within the <_set> opening and closing tags will be assigned to the variable. This may include other control tags, text, and native tags.
<_unset>: Function: This tag removes a variable from the variable set.
Attributes:
- name: Name of variable to remove.
Note that you can clear the contents of an entire Map variable by unsetting "$variable.*". This will not remove the Map variable $variable but will remove all it's subfields. <_print>: Function: This tag prints the string value of the object contained within a variable. (e.g. for Java objects this is the value of the toString() method) For some object types and/or connection types this may do nothing.
Attributes:
- name: Name of variable to print.
- format: Format can be one of the following:
normal: Performs no additional formatting
urlencode / urldecode: used for ecaping characters in URLs. (This & That? This+%26+That%3F)
xmlescape / xmlunescape: used for ecaping XML characters. (This & That? This & That?)
lowercase / uppercase: changes case of all characters within the string. (Hello there. HELLO THERE.)
jsescape: used to back-slash escape quotes, ticks, and carriage returns / line feeds. Also converts quotes to 2 ticks. (He's not really "there". He\'s not really \'\'there\'\'.)
round*: causes the value to be rounded to the nearest integer. (432.5436 432)
money*: causes the value to be printed with exactly two decimal places. (432.5436 432.54, 3 3.00)
hex: prints the hexidecimal value of a number. (545354542542 7ef9a9edce)
propernouns: capitalizes the first letter of every word in a string, except for words less than 3 characters in length. (Hello it is nice to meet you. Hello it is Nice to Meet You)
plural: makes a noun plural. (friend friends, knife knives, party parties)
hrfilesize*: prints a human readable version of a file size number in bytes. (324232 316 K, 423523643 403.0 MB)
removereturns: removes all carriage returns and line feeds.
*Note: The round, money, and hrfilesize formats only function if the value is a number or a string that describes a valid number. Any non-numeric values will result in 0 or 0.00 if used with round or money.
Example:
<_print name="$total" format="money"/> <_stepthrough>: Function: This tag can be used to iterate through any object that can potentially be interpreted as a list of something. This can include arrays, List objects, Collection objects, Map objects (the Map will be iterated over as a List of Map objects with fields 'key' and 'value' representing each entry in the Map), and strings (every character in the string will be iterated over). Each element will be assigned to the variable specified and the code inside the tag will be executed for each element.
Attributes:
- through: Variable (must be an array or List) to iterate over.
- with: Variable to use as iteration variable. Each element of the array or List will be assigned to this variable for each iteration. This variable can then be used inside the iterator to access the current element.
- counter: A numberic counter starting at 1 will be assigned to this variable if this attribute is present.
- mastercounter: This counter will be independent of recursion using the <_stepinto> tag.
- startat: Index in the array or list to start at. Default is zero.
- count: Maximum number of elements to iterate through. Default is zero which means no limit (iterate through all remaining items in array or List).
Examples: <p>List of all customers in system:</p>
<_stepthrough through="$customers" with="$c" counter="$cnt" startat="0">
<p>
Customer name: <_print name="$c.name"/><br/>
Customer description: <_print name="$c.description"/><br/>
Customer ID: <_print name="$c.id"/><br/>
</p>
</_stepthrough>
<!-- print everything in the submitted form -->
<_stepthrough through="$form" with="$f">
<_print name="$f.key"/> = <_print name="$f.value"/>
</_stepthrough>
<!-- print everything in the session -->
<_stepthrough through="$session" with="$s">
<_print name="$s.key"/> = <_print name="$s.value"/>
</_stepthrough>
<_stepinto>: Function: The <_stepinto> tag can be used inside an <_stepthrough> tag to recurse into another list or array. In other words, if you're inside an <_stepthrough> tag and you recurse into something, the current stepthrough block that you are inside is executed over the new variable. This can be used to display trees and other recursive data structures. This tag does nothing if the variable given is null or doesn't contain anything that can be stepped through.
Attributes:
- into: This is the name of the variable to recurse into.
- depthcounter: This is the name of a variable to keep track of the current depth. (optional)
Example:
<_stepthrough through="$items" with="$i" counter="$cnt">
<_repeat counter="$n" count="$depth:0"> </_repeat>
Item: <_print name="$i.name"/>
<_stepinto into="$i.subitems" depthcounter="$depth"/>
</_stepthrough> <_repeat>: Function: The <_repeat> tag allows a block of code to be executed a fixed number of times.
Attributes:
- count: Number of times to repeat.
- counter: Variable to use as counter (starts at 1).
<_break>: Function: Breaks out of any <_stepthrough> or <_repeat> loop. This can be used in conjunction with an <_if> tag to break out of a loop when a certain condition arises. This is an empty tag.
Attributes: none <_jumpto>: Function: Sets the location when used from within a <_stepthrough> tag. Note that this does not affect the count of elements to iterate through. For example, if you start at element zero with count set to ten and then at element four use <_jumpto> to jump to element 15, the result will be that elements 15, 16, 17, 18, and 19 will be executed (the remaining five).
Attributes:
- to: New index to set location to. If this is out of bounds, the index will be set to the nearest boundary (e.g. a negative number would set the index to zero and a number greater than the maximum number of items in the List or array would set the index to the number of items and stop iteration).
<_sub>: Function: The <_sub> tag declares it's contents to be callable as a subroutine. This is useful for declaring areas of the page to be executed on error or other special status and for organizing complex documents like programs to make them easier to understand and maintain.
Attributes:
- name: Name by which this subroutine can be called with a <_gosub> tag.
- transparent: If this is "yes" (the default) then the contents of this <_sub> tag will not be executed inline as the parser passes over it. If this is "no" the tag will act like a marker still but it's contents will be executed regardless at least once as the parser passes over it.
<_gosub>: Function: This tag allows areas marked off by <_sub> tags to be called.- name: Name of sub to call. A fatal error will occur if there is no sub declared by that name. Keep in mind that parsing is linear, so a sub declared below a <_gosub> will not be available to it.
<_include>: Function: This tag is for including parsed or raw local files. Unparsed local files are simply sent to the output stream as they are, while parsed local files are executed as if they were inline code. Variable space is inherited in both directions for parsed included files, so parsed included files can both read the variable space of the present document and modify it or add new variables that persist when the included document ends.
Attributes:
- file: Relative or absolute pathname of file to include.
- parsed: If this is "yes" (the default) then the file will be parsed as an XactScript document.
- override: This overrides whatever maps exist in the included page with other maps specified.
For example, if you wish to include an XactScript page, but use a separate $form and $session map
already defined, you could use <_include file="somepage.xact" parsed="yes" override="$form:$newform,$session:$newsession"/>
<_template>: Function: This tag allows segments of the page to be templated rather than the entire page. This is extremely useful if certain segments of a page must be refreshed with each load but others consist of data that is not changed often. In some cases this can lead to extreme performance improvements. In general, this should not be overused in situations in which no significant gain is to be expected (e.g. trying to template areas of the page that don't require anything time consuming like a database call or file access). Nesting of this tag is allowed but somewhat meaningless unless you wanted to have an area with a longer template frequency inside an area with a shorter template frequency.
Attributes:
- name: Anything you like; this name is simply used to identify this template internally. This name must be unique in the document in which it appears.
- frequency: This is the frequency for template refresh, in seconds.
- dependencies: This is a comma seperated list of variable names from whose contents a fingerprint will be computed. Multiple templates will be stored, each representing a different value of this fingerprint. This should be used if the templated code varies only slightly over a few conditions. Avoid using a condition that changes often, since this would defeat the purpose of the template tag altogether.
<_math>: Function: The <_math> tag allows simple mathematical expressions to be performed. These can contain the operators +, -, *, /, %, and ^ along with parentheses. Variable names can be used, and will be turned into their numeric values or 0 if this is impossible. Requires the "expr" and either the "assign" or "echo" attributes.
Attributes:
- expr: A valid math expression.
- assign: Variable name to assign result to. If blank, result will not be assigned to any variable.
- result: This controls the format of the result variable. Possible values are round, integer, money, decimal, roundup, or rounddown. The default is decimal.
- echo: If this is "yes", the result will be printed. Default is "no".
- echoformat: This controls the printed format of the result. Possible values are round, integer, money, decimal, roundup, or rounddown. The default is decimal.
Example:
Your new total is: $<_math expr="$order_total + $new_item_price" echo="yes" echoformat="money"/>
Variable Syntax
XactScript allows powerful and easy manipulation of variables within documents. Simple variables as well as "Maps" (variables containing multiple internal fields) can be manipulated simply and easily. The variable syntax is:
$variablename[.mapfieldname][:default]
If "mapfieldname" is present, then this variable name refers to a field inside a Map variable. If the variable name is not defined or is not a Map variable, it will be automatically redefined as a Map variable. If the default value is present, this value will be substituted in the event that the variable (or Map field) is not defined.
Examples:
$user.first_name:UnknownReturn first_name field in Map stored in variable $user and return "Unknown" if $user or the first_name field inside it are not defined. $user.first_name:$user.name:UnknownReturn first_name field in Map stored in variable $user but evaluate $user.name:Unknown if undefined. $counterSimply return value of simple (non-Map) variable $counter or null if not defined. $counter:0Return $counter or 0 if not defined. Predefined/System Variables
Various renderers in the XactScript engine may define certain variables as predefined and available to all documents. Here is a list of currently supported predefined variables for all current renderer options.
For all renderers:
|
$system.osversion - | Operating system type and version string |
|
$system.jvmversion - | Java virtual machine version |
|
$system.time - | Time in human-readable form |
|
$system.timeutc - | Time in UTC64 (ms) |
|
$system.machinename - | Name of this machine or 'unknown' if it wasn't set |
|
$system.usercount - | Number of concurrent users currently on |
|
$system.userlimit - | Maximum number of licensed users |
|
$system.xactscriptversion - | XactScript engine version |
|
$chars.tab - | A Tab Character (\t) |
|
$chars.return - | A Return Character (\n) |
|
$chars.linefeed - | A Line Feed Character (\r) |
For HTML and XHTML renderers:
|
$requestmethod - | GET, PUT, POST, etc. |
|
$requestsecure - | Is this connection secure; true or false |
|
$requestreferer - | URL of referring page |
|
$remoteaddr - | IP address of remote user |
|
$remoteuser - | Remote user (only set if http auth is being used) |
|
$remoteagent - | User's browser ID string |
|
$thisurl - | URL of the current page |
|
$thishost - | Server Host Name |
|
$servername - | Server Name |
|
$serverport - | Server Port |
|
$thispage - | File Path of this page on server |
|
$thispagedir - | Directory Path where page resides on server |
|
$thispagename - | This Page's File Name |
|
$thispage_canonical - | Canonical File Path of this page on server |
|
$thispagedir_canonical - | Canonical Directory Path where page resides on server |
|
$invoker - | Class name of invoker for this document |
|
$outputtype - | Output MIME type |
|
$webtools - | Instance of com.xactsys.xactscript.utils.WebTools |
|
$form - | Form variables Map (read only) |
|
$forminfo.resubmit - | Double-tap protection - checks whether a submitted form has already been submitted (true/false) (read only) |
|
$forminfo.age - | Age in seconds since the submitted form was originally generated (read only) |
|
$forminfo.sameorigin - | checks whether the original submitted form was from the same IP address and User Agent (true/false) (read only) |
|
$on_error_push_url - | URL to push to when an error ocurrs on a page |
|
 |
|
 |