Skip to content

Commit e7e23d2

Browse files
committed
Incorporate reviewers’ suggestions
1 parent fba8c14 commit e7e23d2

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

src/main/xar-resources/data/urlrewrite/urlrewrite.xml

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<para>Good web applications provide meaningful and consistent URLs to the user. eXist-db's
2020
<emphasis>URL Rewriting</emphasis> facility is eXist's oldest internal mechanism for
2121
providing short, human-readable URLs to XQuery web applications, conveniently masking the
22-
often complex heirarchy of XQuery modules, HTML files, data, and other resources. (A newer
22+
often complex hierarchy of XQuery modules, HTML files, data, and other resources. (A newer
2323
facility for achieving these goals is eXist-db's implementation of <link
2424
xlink:href="http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html"
2525
>RESTXQ</link>. A third method is to place a <link xlink:href="production_web_proxying"
@@ -41,10 +41,11 @@
4141
<emphasis>root pattern</emphasis>, which is <code>/apps</code> by default, eXist-db will
4242
look within the associated <emphasis>controller root path</emphasis>, which is the
4343
<code>/db/apps</code> database collection by default, for <emphasis>controller
44-
scripts</emphasis>: special XQuery files named <code>controller.xq</code>. These
45-
controller scripts apply to the collections where they are stored and their descendant
46-
collections. They form a <emphasis>collection hierarchy</emphasis>—a URL space within
47-
which URL rewriting can be flexibly applied.</para>
44+
scripts</emphasis>: special XQuery files named <code>controller.xq</code> (or in older
45+
applications <code>controller.xql</code>). A controller script applies to the collection
46+
it is stored in and its descendants. They form a <emphasis>collection
47+
hierarchy</emphasis>—a URL space within which URL rewriting can be flexibly
48+
applied.</para>
4849
</listitem>
4950
<listitem>
5051
<para>The <code>controller.xq</code> script examines the URL using the provided <xref
@@ -54,10 +55,12 @@
5455
<listitem>
5556
<para>The <code>XQueryURLRewrite</code> servlet interprets the directive as a series of
5657
instructions on what to do next. These instructions may be as simple as forwarding the
57-
request to a resource on the server (or elsewhere), or it may be as complex as a pipeline
58-
using the <emphasis>Model-View-Controller</emphasis> pattern (see <xref
59-
linkend="mvc-pipelines"/>) and other servlets such as eXist-db's <xref
60-
linkend="xq-servlet"/> or <xref linkend="xslt-servlet"/>.</para>
58+
request to a resource on the server (or elsewhere), or as complex as a pipeline using the
59+
<emphasis>Model-View-Controller</emphasis> pattern (see <xref linkend="mvc-pipelines"/>)
60+
and other servlets such as eXist-db's <xref linkend="xq-servlet"/> or <xref
61+
linkend="xslt-servlet"/>. The controller script isn't limited to returning these types
62+
of instructions; like any XQuery main module, they can return any data you may wish. But
63+
URL Rewriting instructions are the special capability of controller scripts.</para>
6164
</listitem>
6265
</orderedlist>
6366
<sect2 xml:id="eg1">
@@ -86,10 +89,10 @@
8689
script</emphasis>, an XQuery main module named <literal>controller.xq</literal>. This
8790
script is invoked for all URL paths targeting the collection in which it resides. It has
8891
access to a number of <xref linkend="variables"/> pre-bound with details about the request,
89-
including <literal>$exist:resource</literal>, which conveniently contains the name of the
92+
including <code>$exist:resource</code>, which conveniently contains the name of the
9093
requested resource (without any leading path components). It also includes
91-
<literal>$exist:controller</literal>, which contains the path to the database collection
92-
where the <literal>controller.xq</literal> is located.</para>
94+
<code>$exist:controller</code>, which contains the path to the database collection where
95+
the <literal>controller.xq</literal> is located.</para>
9396
<para>This information allows a controller script to forward all requests for
9497
<literal>/exist/apps/doc/{resource}</literal> to an XQuery,
9598
<literal>transform.xq</literal>, which converts the XML document located via the
@@ -138,8 +141,10 @@
138141
<sect1 xml:id="controller-xml">
139142
<title>Controller XML Format</title>
140143
<para>As we have seen, the <code>controller.xq</code> script is expected to return a single XML
141-
element: either a <tag>dispatch</tag> element or an <tag>ignore</tag> element.</para>
142-
<para>Note that all of the elements discussed in this article must be in the
144+
element: a <tag>dispatch</tag> or <tag>ignore</tag> element. The script can actually return
145+
any data, as you wish, but the <tag>dispatch</tag> or <tag>ignore</tag> elements have special
146+
properties in the context of a <code>controller.xq</code> script.</para>
147+
<para>Note that all of the elements described in this section must be in the
143148
<code>http://exist.sourceforge.net/NS/exist</code> namespace.</para>
144149
<sect2 xml:id="dispatch">
145150
<title>The <tag>dispatch</tag> Action</title>
@@ -365,7 +370,7 @@ Content-Length: 0</programlisting>
365370
<row>
366371
<entry>
367372
<para>
368-
<literal>$exist:root</literal>
373+
<code>$exist:root</code>
369374
</para>
370375
</entry>
371376
<entry>
@@ -377,7 +382,7 @@ Content-Length: 0</programlisting>
377382
<row>
378383
<entry>
379384
<para>
380-
<literal>$exist:prefix</literal>
385+
<code>$exist:prefix</code>
381386
</para>
382387
</entry>
383388
<entry>
@@ -389,7 +394,7 @@ Content-Length: 0</programlisting>
389394
<row>
390395
<entry>
391396
<para>
392-
<literal>$exist:controller</literal>
397+
<code>$exist:controller</code>
393398
</para>
394399
</entry>
395400
<entry>
@@ -401,7 +406,7 @@ Content-Length: 0</programlisting>
401406
<row>
402407
<entry>
403408
<para>
404-
<literal>$exist:path</literal>
409+
<code>$exist:path</code>
405410
</para>
406411
</entry>
407412
<entry>
@@ -413,7 +418,7 @@ Content-Length: 0</programlisting>
413418
<row>
414419
<entry>
415420
<para>
416-
<literal>$exist:resource</literal>
421+
<code>$exist:resource</code>
417422
</para>
418423
</entry>
419424
<entry>
@@ -444,7 +449,7 @@ declare variable $exist:resource external;
444449
<variablelist>
445450
<varlistentry>
446451
<term>
447-
<code>exist:root</code>
452+
<code>$exist:root</code>
448453
</term>
449454
<listitem>
450455
<para>Is bound to the root of the current controller hierarchy. This may either point to
@@ -455,51 +460,49 @@ declare variable $exist:resource external;
455460
the <literal>/stylesheets</literal> directory in the root of the webapp or, if the app
456461
is running from within the database, the corresponding <literal>/stylesheets</literal>
457462
collection. You want your app to be able to run from either location. The solution is to
458-
incorporate the value of the <literal>exist:root</literal> variable into your
459-
logic:</para>
463+
incorporate the value of the <code>$exist:root</code> variable into your logic:</para>
460464
<programlisting language="xml" xlink:href="listings/listing-5.xml"/>
461465
</listitem>
462466
</varlistentry>
463467
<varlistentry>
464468
<term>
465-
<code>exist:prefix</code>
469+
<code>$exist:prefix</code>
466470
</term>
467471
<listitem>
468472
<para>If the current controller hierarchy is mapped to a certain path prefix, then the
469-
<literal>$exist:prefix</literal> variable will be bound to that prefix.</para>
473+
<code>$exist:prefix</code> variable will be bound to that prefix.</para>
470474
<para>For example: the default configuration maps the path <literal>/apps</literal> to a
471-
collection in the database (see below). In this case, the
472-
<literal>$exist:prefix</literal> variable would be bound to the value
473-
<literal>/apps</literal>.</para>
475+
collection in the database (see below). In this case, the <code>$exist:prefix</code>
476+
variable would be bound to the value <literal>/apps</literal>.</para>
474477
</listitem>
475478
</varlistentry>
476479
<varlistentry>
477480
<term>
478-
<code>exist:controller</code>
481+
<code>$exist:controller</code>
479482
</term>
480483
<listitem>
481484
<para>Is bound to the part of the URL leading to the current
482485
<literal>controller.xq</literal>.</para>
483486
<para>For example, if the request path is <literal>/sandbox/test.xq</literal> and the
484487
controller is in the <literal>xquery</literal> collection, the
485-
<literal>$exist:controller</literal> variable will be bound to the value
488+
<code>$exist:controller</code> variable will be bound to the value
486489
<literal>/sandbox</literal>.</para>
487490
</listitem>
488491
</varlistentry>
489492
<varlistentry>
490493
<term>
491-
<code>exist:path</code>
494+
<code>$exist:path</code>
492495
</term>
493496
<listitem>
494497
<para>Is bound to the last part of the request URL, i.e., after the section leading to the
495498
collection containing the controller.xq.</para>
496499
<para>For instance, if the resource <literal>example.xml</literal> resides within the same
497-
collection as the controller query, the <literal>$exist:path</literal> variable would be
498-
bound to the value <literal>/example.xml</literal>.</para>
500+
collection as the controller query, the <code>$exist:path</code> variable would be bound
501+
to the value <literal>/example.xml</literal>.</para>
499502
</listitem>
500503
</varlistentry>
501504
<varlistentry>
502-
<term><code>exist:resource</code></term>
505+
<term><code>$exist:resource</code></term>
503506
<listitem>
504507
<para>Is bound to the part of the URL after the last <literal>/</literal>; this is usually
505508
pointing to a resource.</para>
@@ -542,14 +545,16 @@ declare variable $exist:resource external;
542545
<title>Locating Controller Scripts and Configuring Base Mappings</title>
543546

544547
<para>By convention, the controller script must be named <literal>controller.xq</literal> (or in
545-
older applications <code>controller.xql</code>). If you wish to allow anonymous users to
546-
access resources using the URL Rewriting framework then you need to ensure that the
547-
<literal>controller.xq</literal> script is world-executable, e.g.,
548-
<code>sm:chmod(xs:anyURI("/path/to/controller.xq")), "o+x")</code>.</para>
548+
older applications <code>controller.xql</code>; if both <literal>controller.xq</literal> and
549+
<code>controller.xql</code> are placed in the same collection, the former takes precedence,
550+
and the latter is ignored).</para>
551+
<para>If you wish to allow anonymous users to access resources using the URL Rewriting framework
552+
then you need to ensure that the <literal>controller.xq</literal> script is world-executable,
553+
e.g., <code>sm:chmod(xs:anyURI("/path/to/controller.xq")), "o+x")</code>.</para>
549554
<para>By default, the URL Rewriting framework will try to guess the path to the controller
550555
script by looking at the request path, starting with the deepest, most specific collection,
551-
and then looking into each parent collection until the controller script is found or the root
552-
of the database has been reached.</para>
556+
and then examining each parent collection until a controller script is found or the root of
557+
the database has been reached.</para>
553558
<para>This can be configured and overridden via the <literal>controller-config.xml</literal>
554559
configuration file in <literal>$EXIST_HOME/etc/webapp/WEB-INF</literal>, which defines the
555560
base mappings used.</para>
@@ -576,7 +581,7 @@ declare variable $exist:resource external;
576581
entire web application, and no additional handling of the servlet paths is necessary in the
577582
controller script.</para>
578583
<para>For example, if we had registered a servlet mapping for <literal>/rest</literal> in
579-
<literal>web.xml</literal>, we would jave needed to make sure that this path is ignored in
584+
<literal>web.xml</literal>, we would have needed to make sure that this path is ignored in
580585
our main <literal>controller.xq</literal> scripts. However, since the mapping is done via
581586
<literal>controller-config.xml</literal>, XQueryURLRewrite handles the path, which then
582587
doesn't need to be accounted for in our controller.</para>

0 commit comments

Comments
 (0)