|
|
|||
6.5 CGI binding for .xq filesHere are the instructions to make .xq files directly executable from a Apache web server. Note: The code provided below is still in an experimental stage and is not intended to be used in a production environment. 6.5.1 httpd.confFirst you must adapt the httpd.conf configuration file of the Apache web server, in order to a) turn on cgi scripts (if not already the case), and b) add a "handler" for <code>.xq</code> files. To do so, I made the following changes: $ diff -w httpd.conf httpd.conf.default 858c858 < AddHandler cgi-script .cgi --- > #AddHandler cgi-script .cgi 885,890d884 < # redirect xquery files to our cgi script < AddType text/xml .xq < AddHandler xquery-type .xq < Action xquery-type /cgi-bin/xquery.cgiDon't forget to restart Apache; so it reads httpd.conf 6.5.2 xquery.cgiIn the cgi-bin/ directory, you must also place the script (xquery_cgi) under the name xquery.cgi with executable file permissions: chmod 755 xquery.cgi Beware! You must potentially adapt:
#!/bin/bash
echo 'Content-type: text/xml'
echo
MONETDIR=/path_to_monetdb/
WWWDIR=/var/www/htdocs
XQFILE=$WWWDIR/$REDIRECT_URL
if [ x$QUERY_STRING == x ]
then
$MONETDIR/bin/mclient --set prefix=$MONETDIR --set exec_prefix=$MONETDIR -fxml -lx $XQFILE
else
`echo "sed -e s/%$QUERY_STRING/g $XQFILE" | sed -e "s/&/\/g -e s\/%/g" -e "s/=/%\//g"` > /tmp/$$
$MONETDIR/bin/mclient --set prefix=$MONETDIR --set exec_prefix=$MONETDIR -fxml -lx /tmp/$$
fi
6.5.3 passing parametersThe <code>xquery.cgi</code> script allows parameter passing. Suppose we have the following XQuery file (save it as example.xq in the htdocs>-folder): for $i in 1 to %max%
return element { "mult" } {
$i, " times ", %table%, " is ", $i * %table%
}
The table and max have been parametrized. Parameters take the form: %name% The parameters can be used in the usual URL convention: <a href="http://localhost/example.xq?table=3&max=10"
class='external'>http://localhost/example.xq?table=3&max=10</a>
Beware: parameter substitution in this script is very simple; it won't work with special characters in it (that get escaped by the web server) or even spaces. For optimal web server performance, we may want to do all parameter substitution inside mclient; so that we don't need to fork a bash shell process on each web request. |
||||
| © 1994-2011 CWI | Contact us Legal HG web Bugs TestWeb | |||