Database Reference
In-Depth Information
• Notice that the result of the script is always an XML fragment in an eXist-specific
namespace. This fragment determines what eXist will do next—for instance,
redirect the browser to another page, or silently (and invisibly to the user) for‐
ward to some other URL. The examples here are quite simple, but you can do
some amazingly complex things, like pipelining results through XLST stylesheets.
• The top of the script declares a number of external variables. eXist uses these to
pass important information about the call to the script.
• There is a function that extracts the extension part from a filename (e.g.,
xq
from
home.xq
), by using a regular expression. This is, of course, not unique to URL
rewriting, but you'll often see regular expressions in a
controller.xql
inspecting
parts of the URL.
• The main part of the script examines the request by inspecting the external vari‐
ables. The first
if
clause determines if the URL contains a resource name. If not,
it
redirects
the browser to the home page. This causes a browser redirect (visible
because the URL visible in your browser changes). So again, an HTTP request
travels through our URL rewriting controller, but now with
/home
appended.
• The second
if
clause checks whether the resource part of the URL has an exten‐
sion (like
.xq
or
.png
). If not, it assumes that it is an XQuery script and
forwards
the request, invisibly to the browser, to an XQuery script in the database. So, for
example, the second time around, after
/home
has been appended to the URI,
home
is interpreted as
home.xq
, and therefore
home.xq
is called.
• The last
else
is a catchall that passes on the full URL to the appropriate handler,
necessary for displaying images and more.
You'll also want to look at the security settings of the application files. You can view
these by, for instance, using eXist's Java Admin Client:
• Other users have execute permissions for
controller.xql
. This will always be the
case for a URL rewriting controller, because it is the general entry point to your
application. Otherwise, this is the error message you'll see:
Subject 'guest' does not have '--------x' access to resource
'/db/apps/exist-book/building-applications/mini-application/controller.xql'
• For our application,
other
users have execute permissions for other XQuery files
too, so anybody can use them.
• Other users also have execute permissions for the
images
subcollection. If you
were to revoke this permission, the browser would not be able to load the eXist
logo.
Search WWH ::
Custom Search