|
|
Index Data > Keystone DLS (TKL) (NO LONGER BEING ACTIVELY DEVELOPED) > Keystone Administration > Supporting functions The supporting functions are absolutely central to the function of the user shell, and it important to understand the possibilities that they make available, if you are to build a serious application using Keystone. Since there is currently no good, standardised way to define and involke external functins from XSLT, we have chosen to implement our supporting functions as private URI schemes that can be used via the document() function, but also, for example, in the <xsl:import> and <xsl:include> elements. In the following sections, we describe the individual support functions. All of the functions return their results in the form of an XML document which can treated in the usual way in XSLT. Please not that when these functions are involked from XSLT, the ampersand (&), which is used to spearate parameters, must be escaped as &. Note also that Keystone allows the portal to provide its own extension functions in either PHP or Perl, without requiring changes to the user shell. This is very useful in situations where a task is simply not well-suited for implementation in XSLT alone. Function: Generates relevant HTTP headers for the admin interfaces. Synopsis: This handler is invoked automatically by the Keystone system. Result: This handler is special in the sense that it is invoked automatically by the shell.php in case the admin interface is about to be loaded. If not overwritten, this handler generates the relevant HTTP headers for authentication. Warning: In general, this handler should not be overwritten except when you know exactly what you're doing! See also tkl-header. Function: Query HTTP GET'd/POST'd variables.
Synopsis: Result: XML encoding representation of a list of key => value pairs, for instance,
<args>
<var1>value1</var1>
<var2>value2</var2>
</args>
If an array variable, i.e.
Array
(
[key1] => value1
[key2] => value2
)
is present, it will be encoded this way:
<args>
<list i="key1">value1</list>
<list i="key2">value2</list>
</args>
Function: Looks for the presence of a file in portal area and Keystone core area.
Synopsis: Result: Path is the name of the file relative to the portal root. The handler looks for this file in the portal area. If it exists, the absolute path is returned. Otherwise, the file is looked for in the Keystone core area. If it exists here, the absolute path is returned, otherwise an error flag is raised. Example:
<tkl-default>
<abs_path>/var/www/bibliotheca/my_dir/my_file</abs_path>
</tkl-default>
on success. On error, the returned XML looks like this:
<tkl-default>
<error>Error message</error>
</tkl-default>
Function: Opens a Keystone file and filters language dependent elements.
Synopsis: Result: This handler returns an XML document tree ready to process in XSLT. It is important not to confuse the "tkl-file" handler with the generic XSLT handler "file". The differences can be summarized this way:
The tkl-file handler is well-suited for importing general XML into your stylesheet, Keystone files as well as XSLT stylesheets, or any other type of XML. The tkl-file handler works excellent in combination with the XSLT import and include instructions, i.e.
<xsl:import href="tkl-file://my_stylesheet.xsl"/>
<xsl:include href="tkl-file://subdir/some_other_stylesheet.xsl"/>
which are the preferred XSL stylesheet inclusion idioms. Function: Checks if a specified file exists.
Synopsis: Result: Returns the following XML structure:
<tkl-file-exists>
<exists>1</exists>
</tkl-file-exists>
if the file exists, and of course otherwise,
<tkl-file-exists>
<exists>0</exists>
</tkl-file-exists>
Function: Finds files which match a given pattern or mask.
Synopsis: Result: A list oif <file> elements, one for each matching file, containing the elements of each file given by fieldmask. Example: tkl-find:/?path=*/index.tkl&select=title
<?xml version="1.0" encoding="ISO-8859-1"?>
<tkl-find>
<file path="./news/index.tkl">
<title>Nu med links!</title>
</file>
<file path="./oldcheese/index.tkl">
<title>Gammel ost på nye flasker</title>
</file>
.....
</tkl-find>
The tkl-find function can be used in two different ways. IN the simple version, it searches for files which match path-parameters (comparable to a simple listing of files matching a filename (glob) pattern in a Unix shell. It returns a number of file elements, containing the elements selected by the fieldmask parameter. The fieldmask parameter has the form element|element|... - in other words, an arbitrary number of element names separated by vertical bars. The function can also be used like the find-command of Unix, to recursively traverse one or more subtrees.This example from the base test portal finds all index.tkl files in subdirectories of links/* two levels down. tkl-find:/?path=links/*&mask=index.tkl&select=title&level=2 Returns:
<?xml version="1.0" encoding="ISO-8859-1"?>
<tkl-find>
<dir path="./links/27/" level="1" att="2">
<file path="./links/27/index.tkl">
<title xml:lang="en">General Subjects</title>
</file>
<dir path="./links/27/01/" level="2" att="2">
<file path="./links/27/01/index.tkl">
<title xml:lang="en">Cross-disciplinary subjects</title>
</file>
</dir>
<dir path="./links/27/03/" level="2" att="2">
<file path="./links/27/03/index.tkl">
<title xml:lang="en">Library collections</title>
</file>
</dir>
</dir>
................
</tkl-find>
(please note that the structure above represents a hierarchy, where directory elements can contain both files and onther directories). If the path expression only matches files, there is no needs to provide a mask. If the path expression matches directories, the function will search these subdirectories, looking for files matching the mask parameter, until level levels (steps) The <dir> and <file> elements both have a path-attribute, which provides a relative path to the file or directory (with respect to the location of the current document).Usually, this means that these paths can be used without modification in, say, a HTML <A> element, as a relative URL. However, please note that if the original path expression is absolute (ie. starts with a '/'), it is processed relative to the root of the portal , and the path-attribute in the <dir> and <file> elements can be used directly as a server-absolute URL. For example:
tkl-find://?path=/news/news*.tkl&select=date|title
<tkl-find>
<file path="/tkl/news/news1.tkl">
<date>2002-07-08</date>
<title xml:lang="en">The test has begun</title>
</file>
<file path="/tkl/news/news429.tkl">
<date>2002-07-10</date>
<title xml:lang="en">The news entries have been cleaned out</title>
</file>
</tkl-find>
Please note that tkl-find, like the other functions, pre-process their results so that any elements marked with xml:lang attributes not matching the current language are filtered out. Under normal circumstances, the programmer should not have to worry about resource languages in his stylesheets.
Function: Checks for user read/write/create authorization. This handler only makes
sense in an administration interface, i.e. where
Synopsis: Result: In case, the user is authorized to perform the given action, the following XML structure is returned:
<tkl-grant>
<granted>1</granted>
</tkl-grant>
Otherwise, false is returned, i.e.
<tkl-grant>
<granted>0</granted>
</tkl-grant>
The parameters
All paths are relative to the Keystone portal root. Function: Send HTTP headers to the user interface. Synopsis: This handler is called automatically by the Keystone system. Don't attempt to call it from your XSL stylesheets. Result: This Keystone handler is intentionally born empty. When developing a Keystone portal, the programmer is encouraged to overwrite the tkl-header by something meaningful. Typically, one wants to exploit the fact that this handler is called before any output has been generated by the XSLT processor. Thus, for instance HTTP headers can be created here. See also tkl-admin-header. Function: Find the closest occurence of help.tkl.
Synopsis: Result: This support function is in a state of development and in the future it may be out-phased in favour of a more generalized implementation. But for the time being, it looks in the current working directory for the presence of a help.tkl file. If there is no such file there, it goes one directory level back and looks there. It keeps doing this process, until it finds a help.tkl file or reaches the Keystone portal root. If a help.tkl file was found, the following XML document is returned:
<tkl-help>
<file>../../help.tkl</file>
</tkl-help>
where the content of the
Otherwise, the Function: Support function for sending e-mails.
Synopsis: Result: The following mail is sent with the native system's mail transmission agent:
To: recipient@domain.org
Subject: Subject text
Message body.
If the mail was sent successfully, the following XML is returned:
<tkl-mail>
<status>OK</status>
</tkl-mail>
Otherwise, an error flag is raised:
<tkl-mail>
<error>error message</error>
</tkl-mail>
Function: Returns a path of "breadcrumbs" to the root of the portal.
Synopsis: Example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<tkl-path>
<step path='./../../../'>
<title xml:lang="en">Bibliotheca</title>
</step>
<step path='./../'>
<title xml:lang="en">Social Sciences</title>
</step>
<step path='./'>
<title xml:lang="en">Law</title>
</step>
</tkl-path>
Tkl-path returns an XML representation of the path from a given document to the root of the portal. In the base portal Bibliotheca, in the file interface.xsl, in the template insert-path, is an example of the usage of this function. In the base portal, the function is used to create a clickable path on each side, as a navigational aid. The function operate by examining all directories from the current directory up to the root. For all directories which contain an index.tkl file, it returns a <step> element with a path-attribute providing a relative path. The path is generally suitable for use as a relative URL in an HTML <A> tag. Function: Searches a Z39.50 database
Synopsis: Example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<search>
<start>1</start>
<number>6</number>
<server url="unix:/home/indexdata/html/tkl/db/socket" status="1">
<hits>6</hits>
<end>6</end>
<record offset="1">
<subject xmlns:idzebra="http://www.indexdata.dk/zebra/">
<title xml:lang="en">Computer science</title>
<idzebra:size>153</idzebra:size>
<idzebra:localnumber>332</idzebra:localnumber>
<idzebra:filename>links/30/05/index.tkl</idzebra:filename>
</subject>
</record>
...............
<record offset="6">
.......
</record>
</server>
</search>
Tkl-search executes a search against the given Z39.50 server. The address of the server generally follows the Z39.50 URL format, even though the example aboce is not standard, but an INdex Data specific extension which allows the use of Unix filesystem sockets (Unix fomain sockets) instead of internet host addresses/port numbers. In the local search function of the base portal Bibliotheca, Unix domain sockets are used to avoid having to allocate a new TCP/IP port to every portal running on the same machine. The parameters start, number, and syntax work as you would expect, and queries are given in the PQF format (described at http://www.indexdata.dk/yaz/doc/tools.php#AEN2265) or ISO CCL (XX add documentation for the configuration of CCL field mapping setup). The results come back as shown above. In particular, the users start and number-parameters are repeated in the XML structure. In the <server> element (which may become repeatable if multi-target searching is introduced) is the number of hits, along with the highest record number returned. After this follows a number of tecord elements, each of which contains one retrieval record from the server. In portals like the base portal Bibliotheca, the tkl-search function is used to search the portal's index, which are hosted by a Zebra server. Note that Zebra for each record returns the path of the record in the element <idzebra:filename>. Function: Name a custom handler to be executed after XSLT processing and output has completed.
Synopsis: Result: Returns an empty XML document. Has the side effect of executing the named custom handler AFTER the current stylesheet has completed. The most obvious use for this is to execute a PHP or Perl script after the main page HTML has been output. This script in turn may perform a time-consuming process, i.e. a search, and provide a dynamic update of the user's screen by emitting a series of Javascript commands which alter the document HTML contents. Function: Provides access to procedure calls on remote systems via the SOAP protocol.
Synopsis: Example:
<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope" >
<env:Header>
<t:transaction
xmlns:t="http://thirdparty.example.org/transaction"
env:encodingStyle="http://example.com/encoding"
env:mustUnderstand="true" >
5
</t:transaction>
</env:Header>
<env:Body>
<m:reserveAndChargeResponse
env:encodingStyle="http://www.w3.org/2001/12/soap-encoding"
xmlns:rpc="http://www.w3.org/2001/12/soap-rpc"
xmlns:m="http://travelcompany.example.org/">
<rpc:result>m:status</rpc:result>
<m:status>confirmed</m:status>
<m:reference>FT35ZBQ</m:reference>
<m:viewAt>
http://travelcompany.example.org/reservations?code=FT35ZBQ
</m:viewAt>
</m:reserveAndChargeResponse>
</env:Body>
</env:Envelope>
Tkl-soap provides access to any SOAP-based, so-called web-service (or remote API) anywhere on the Internet. The parameters to the the function consist of a reference to a service definition file (WSDL), a function name, and a list of parameters. The parameters can be structured in a variety of ways, to enable the use of different types of remote function. The WSDL file can be identified using a relative or portal-absolute path, or as an HTTP URL. Different SOAP functions pose different requirements to the structure of their parameters. In the example here, concat() is used to construct an argument list soleley in order to increase readability. You can imagine that "$query" in the example is a parameter which has been supplied by the user (see above about accessing user-supplied parameters in XSLT stylesheets). INSERT EXAMPLE FROM bibliotheca/soap/google/google.xsl Parameters for the SOAP functions can also be named explicitly, for example: tkl-soap:MyTestService.wsdl?tkl:fun=myFunction&alpha=1&beta=2 Some functions require structured data, for instance, the arguments primitive=test&alpha.a=bob&alpha.b=bub yields the structure: primitive=>test, alpha=>{a=>bob, b=>bub} Substructures can be anonymous, as in .a=bob&.b=bub which yields {a=bob, b=>bub} As a concrete example, Amazon.com can be searched like this:
<xsl:variable name="result" select="document(concat(
'tkl-soap:AmazonWebServices.wsdl?',
'tkl:fun=KeywordSearchRequest',
'&.keyword=', $squery,
'&.page=2',
'&.mode=books',
'&.tag=webservices-20',
'&.type=lite',
'&.devtag=', token,
'&.format=xml',
'&.version=1.0'
))"/>
If debugging has been enabled (adding the parameter debug=1 to the URL line), both the SOAP request and response packages will be displayed so it is easy to determine if you have constructed the right parameters for a given web service. Function: Connect to a MySQL database server and execute SQL instructions.
Synopsis I:
Synopsis II: Result: This Keystone handler sends an SQL query to the database specified and encode the returned records as XML. Before any SQL instruction can be carried out, a database connection must be established. This is performed by calling
tkl-sql:?type=connect&host=mysqlhost.mydomain.org&db=sqlbase
If you need to login as a specific user with password, simply add a
Assuming one have an open MySQL connection, any number of manipulations can be made during one HTTP session. You execute SQL instructions the following way:
tkl-sql:?type=exec&sql=SELECT this FROM that WHERE xxxx
When
<sql hits="xx" affected="yy">
<record>
<field1>value1</field1>
<field2>value2</field2>
...
...
</record>
<record>
<field1>value1</field1>
<field2>value2</field2>
...
...
</record>
...
...
</sql>
The attribute The XML encoding is crucial when non-XML data from an external database is converted into well-formed XML. Therefore, one needs to decide how to handle two aspects of this situation:
Function: Return the current time.
Synopsis:
Result: Returns the time as a raw string. The optional setting Function: Filenaming support function for the admin interface.
Synopsis:
Result: This support function is designed mostly for the admin interface. It returns
information about how to name new files respecting the local schemes specified in
directory.tkl. The The returned XML document has this form:
<tkl-unique>
<unique>link-12345678.tkl</unique>
<exists>0</exists>
<file_spec>0</file_spec>
</tkl-unique>
When Warning: Don't overwrite this function unless you know exactly what you are doing! Function: Get information about user currently logged into the admin interface.
Synopsis: Result: Returns an XML document with information about the user currently logged into the admin interface. The structure of the XML is the following:
<tkl-user>
<login>user_login</login>
<password>ff402ace53f370435</password>
<name>Human Readable Name Of This User;/name>
<email>user_login@domain.org</email>
<usertype>administrator</usertype>
<area>/</area>
<area>/news</area>
<pass_type>md5</pass_type>
</tkl-user>
The
Finally, we have the repeatable Since this is an admin interface handler, please don't attempt to overwrite it, unless you know what you are doing! |
|||
|
|
||||
| Copyright Index Data ApS 2008 | ||||