Skip to content

Commit ad41043

Browse files
committed
tested all files
- added missing “new-instance.xml” - disabled betterform in edit/edit.xq
1 parent a5a661a commit ad41043

19 files changed

+192
-165
lines changed

src/main/xar-resources/data/beginners-guide-to-xrx-v4/beginners-guide-to-xrx-v4.xml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,24 @@
454454
<sect2>
455455
<title>Re-indexing</title>
456456

457-
<para>After you have created or modified your configuration file, you must re-index any data that you have. This can be done by executing the
458-
following two XQuery lines:</para>
457+
<para>After you have created or modified your collection configuration
458+
file, you must re-index any data that you have. This can be done
459+
by executing the following two XQuery lines (supplying your
460+
eXist administrative user's password in place of
461+
<code>myadminpassword</code>, since reindexing requires
462+
administrative privileges):</para>
459463

460464
<programlisting xlink:href="listings/listing-7.txt"/>
461-
<para>You can run this query directly in <!--eXide-->, or you can also
462-
store the following XQuery script in the app's
463-
<code>admin</code> collection and call it via your browser.
464-
The script will login as the administrator and then run the
465-
<code>xmldb:reindex</code> function (which needs
466-
administrative privileges) on the data collection. It also
467-
returns the time used to reindex the collection. For collections
468-
that are under 1,000 medium sized 10K byte documents, this
469-
script usually runs in a few seconds. Tools are available for
470-
larger collections to schedule indexing during off hours with
471-
the eXist job scheduler.</para>
465+
<para>You can run this query directly in eXide, or you can also store the
466+
following XQuery script in the app's <code>admin</code>
467+
collection and call it via your browser. The script will login
468+
as the administrator and then run the <code>xmldb:reindex</code>
469+
function on the data collection. It also returns the time used
470+
to reindex the collection. For collections that are under 1,000
471+
medium sized 10K byte documents, this script usually runs in a
472+
few seconds. Tools are available for larger collections to
473+
schedule indexing during off hours with the eXist job
474+
scheduler.</para>
472475
<para><code>/db/apps/terms/admin/reindex.xq</code></para>
473476
<programlisting xlink:href="listings/listing-8.txt"/>
474477
<para>The result will be:</para>
@@ -584,9 +587,15 @@
584587
<para>Note that this form does "double duty" as both a form for new items
585588
and a form for updating existing items. The
586589
<code>new=true</code> parameter must always be passed to the
587-
form when creating a new item. A more sophisticated production
590+
form when creating a new item. (A more sophisticated production
588591
systems would check for these parameters and return error codes
589-
if one or the other is not passed to the form.</para>
592+
if one or the other is not passed to the form.) In order to
593+
create the new item, the form fetches a document containing
594+
blank fields to be used as a template for the form.</para>
595+
<para>
596+
<code>/db/apps/terms/edit/new-instance.xml</code>:</para>
597+
598+
<programlisting xlink:href="listings/listing-13.xml"/>
590599
<para>All XForms hold the form data in the <tag>xf:model</tag> element.
591600
This form uses a single <tag>xf:instance</tag> element within
592601
the model to store the data that will saved when the user clicks
@@ -605,7 +614,7 @@
605614
<para>The query that is used is wrapped inside of the <code>action</code>
606615
attribute of the save submission. Here is the portion from
607616
<code>edit.xq</code> with this code: </para>
608-
<programlisting xlink:href="listings/listing-13.txt"/>
617+
<programlisting xlink:href="listings/listing-14.txt"/>
609618
<para>You can see that if the user is creating a new item the data is sent
610619
via an HTTP POST request to the <code>save-new.xq</code> query.
611620
If the user does not have a new item the POST data is sent to
@@ -619,7 +628,7 @@
619628
updated. </para>
620629
<para>The next section of code to notice is that the ID element is only displayed using a read-only <tag>xf:output</tag> element if the form is
621630
in update mode.</para>
622-
<programlisting xlink:href="listings/listing-14.txt"/>
631+
<programlisting xlink:href="listings/listing-15.txt"/>
623632
<para>This shows some of the power of combining XQuery and XForms. In this
624633
case we are using logic on the server to conditionally include
625634
portions of the form based on the context. Contextual indicators
@@ -652,9 +661,9 @@
652661
with elements. </para>
653662
<para>The final part of the form contains the instructions needed to place the XSLTForms processing instruction at the top of the file when it
654663
is rendered.</para>
655-
<programlisting xlink:href="listings/listing-15.txt"/>
656-
<para>You can also add a directive that will put the XSLTForms system into a debug mode by adding the following .</para>
657664
<programlisting xlink:href="listings/listing-16.txt"/>
665+
<para>You can also add a directive that will put the XSLTForms system into a debug mode by adding the following:</para>
666+
<programlisting xlink:href="listings/listing-17.txt"/>
658667
</sect2>
659668

660669
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -666,7 +675,7 @@
666675
next ID to be used in a small XML file with only one element in the root called <emphasis role="bold">next-id</emphasis>. Here is that file: </para>
667676
<para>
668677
<code>/db/apps/terms/edit/next-id.xml</code>: </para>
669-
<programlisting language="xml" xlink:href="listings/listing-17.xml"/>
678+
<programlisting language="xml" xlink:href="listings/listing-18.xml"/>
670679
<para>The <tag>next-id</tag> element is updated using an XQuery "update
671680
function" when new items are saved to the data collection. We
672681
save the file using the number as the filename; in this case,
@@ -679,7 +688,7 @@
679688

680689
<para>
681690
<code>/db/apps/terms/edit/save-new.xq</code>: </para>
682-
<programlisting xlink:href="listings/listing-18.txt"/>
691+
<programlisting xlink:href="listings/listing-19.txt"/>
683692
</sect2>
684693

685694
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -692,7 +701,7 @@
692701
updated and re-indexed upon the store operation. </para>
693702
<para>
694703
<code>/db/apps/terms/edit/update.xq</code>:</para>
695-
<programlisting xlink:href="listings/listing-19.txt"/>
704+
<programlisting xlink:href="listings/listing-20.txt"/>
696705
</sect2>
697706
</sect1>
698707

@@ -718,7 +727,7 @@
718727
appropriately with a red warning indicator.</para>
719728
<para>
720729
<code>/db/apps/terms/edit/delete-confirm.xq</code>: </para>
721-
<programlisting xlink:href="listings/listing-20.txt"/>
730+
<programlisting xlink:href="listings/listing-21.txt"/>
722731
</sect2>
723732
</sect1>
724733

@@ -730,7 +739,7 @@
730739
<para>The delete script also takes a single REST parameter of the ID</para>
731740
<para>
732741
<code>/db/apps/terms/edit/delete.xq</code>: </para>
733-
<programlisting xlink:href="listings/listing-21.txt"/>
742+
<programlisting xlink:href="listings/listing-22.txt"/>
734743
</sect1>
735744

736745
<!-- ================================================================== -->
@@ -743,7 +752,7 @@
743752
below.</para>
744753
<para>
745754
<code>/db/apps/terms/index.html</code>: </para>
746-
<programlisting language="xml" xlink:href="listings/listing-22.xml"/>
755+
<programlisting language="xml" xlink:href="listings/listing-23.xml"/>
747756
<informalfigure>
748757
<mediaobject>
749758
<imageobject>

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-11.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ return
2727
</li>
2828
}
2929
</ol>
30-
<a href="search-form.html">New Search</a>
30+
<a href="search-form.html">New Search</a><br/>
3131
<a href="../index.html">App Home</a>
3232
</body>
3333
</html>

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-12.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let $new := request:get-parameter('new', '')
66
let $id := request:get-parameter('id', '')
77
let $data-collection := '/db/apps/terms/data'
88
let $file :=
9-
if ($new) then
9+
if ($new ne '') then
1010
'new-instance.xml'
1111
else
1212
concat('../data/', $id, '.xml')
@@ -50,7 +50,7 @@ let $form :=
5050
<xf:model>
5151
<xf:instance xmlns="" src="{$file}" id="save-data"/>
5252
<xf:submission id="save" method="post" action="{
53-
if ($new = 'true') then
53+
if ($new eq 'true') then
5454
'save-new.xq'
5555
else
5656
'update.xq'
@@ -95,4 +95,9 @@ let $form :=
9595
</html>
9696
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/apps/xsltforms/xsltforms.xsl"'}
9797
return
98-
($xslt-pi, $form)
98+
(
99+
(: Prevent betterFORM (still enabled by default) from intercepting the form, allowing XSLTForms to handle it :)
100+
request:set-attribute("betterform.filter.ignoreResponseBody", "true"),
101+
$xslt-pi,
102+
$form
103+
)

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-13.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<term>
2+
<id></id>
3+
<term-name></term-name>
4+
<definition></definition>
5+
<publish-status-code></publish-status-code>
6+
</term>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
if ($id) then
2-
<xf:output ref="id" class="id">
3-
<xf:label>ID:</xf:label>
4-
</xf:output>
5-
else
6-
()
1+
action="{
2+
if ($new='true') then
3+
'save-new.xq'
4+
else
5+
'update.xq'
6+
}"
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/apps/xsltforms/xsltforms.xsl"'}
2-
return ($xslt-pi, $form)
1+
if ($id) then
2+
<xf:output ref="id" class="id">
3+
<xf:label>ID:</xf:label>
4+
</xf:output>
5+
else
6+
()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
let $debug := processing-instruction xsltforms-options {'debug="yes"'}
2-
return ($xslt-pi, $debug, $form)
1+
let $xslt-pi := processing-instruction xml-stylesheet {'type="text/xsl" href="/exist/apps/xsltforms/xsltforms.xsl"'}
2+
return ($xslt-pi, $form)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let $debug := processing-instruction xsltforms-options {'debug="yes"'}
2+
return ($xslt-pi, $debug, $form)

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-18.txt

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
xquery version "1.0";
22

33
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
4-
5-
let $title := 'Update Confirmation'
4+
5+
let $app-collection := '/db/apps/terms'
66
let $data-collection := '/db/apps/terms/data'
7-
7+
88
(: get the form data that has been "POSTed" to this XQuery :)
99
let $item := request:get-data()
10+
11+
(: get the next ID from the next-id.xml file :)
12+
let $next-id-file-path := concat($app-collection, '/edit/next-id.xml')
13+
let $next-id := doc($next-id-file-path)/data/next-id/text()
14+
let $file := concat($next-id, '.xml')
1015

1116
(: log into the collection :)
12-
let $login := xmldb:login($data-collection, 'admin', 'myadminpassword')
17+
let $login := xmldb:login($app-collection, 'admin', 'myadminpassword')
1318

14-
(: get the id out of the posted document :)
15-
let $id := $item/term/id/text()
19+
(: create the new file with a still-empty id element :)
20+
let $store := xmldb:store($data-collection, $file, $item)
21+
let $new-document := doc(concat($data-collection, '/', $file))
1622

17-
let $file := concat($id, '.xml')
23+
(: add the correct ID to the new document we just saved :)
24+
let $update-id := update value $new-document/term/id with $next-id
1825

19-
(: save the new file, overwriting the old one :)
20-
let $store := xmldb:store($data-collection, $file, $item)
26+
(: update the next-id.xml file :)
27+
let $new-next-id := update value $next-id with $next-id + 1
28+
29+
(: we need to return the original ID number in our results,
30+
but the previous update expression increased $next-id by 1 :)
31+
let $original-id := $next-id - 1
2132

2233
return
23-
<html>
24-
<head>
25-
<title>{$title}</title>
26-
</head>
27-
<body>
28-
<h1>{$title}</h1>
29-
<p>Item {$id} has been updated.</p>
30-
</body>
31-
</html>
34+
<html>
35+
<head>
36+
<title>Save Conformation</title>
37+
</head>
38+
<body>
39+
<a href="../index.xhtml">Term Home</a>
40+
<p>Term {$original-id} has been saved.</p>
41+
<a href="../views/list-items.xq">List all Terms</a>
42+
</body>
43+
</html>

src/main/xar-resources/data/beginners-guide-to-xrx-v4/listings/listing-20.txt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@ xquery version "1.0";
22

33
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
44

5-
let $id := request:get-parameter('id', '')
6-
let $data-collection := '/db/apps/terms/data/'
7-
let $doc := concat($data-collection, $id, '.xml')
5+
let $title := 'Update Confirmation'
6+
let $data-collection := '/db/apps/terms/data'
7+
8+
(: get the form data that has been "POSTed" to this XQuery :)
9+
let $item := request:get-data()
10+
11+
(: log into the collection :)
12+
let $login := xmldb:login($data-collection, 'admin', 'myadminpassword')
13+
14+
(: get the id out of the posted document :)
15+
let $id := $item/term/id/text()
16+
17+
let $file := concat($id, '.xml')
18+
19+
(: save the new file, overwriting the old one :)
20+
let $store := xmldb:store($data-collection, $file, $item)
821

922
return
1023
<html>
1124
<head>
12-
<title>Delete Confirmation</title>
13-
<style>
14-
<![CDATA[
15-
.warn {
16-
background-color: silver; color: black; font-size: 16pt;
17-
line-height: 24pt; padding: 5pt; border: solid 2px black;
18-
}
19-
]]>
20-
</style>
25+
<title>{$title}</title>
2126
</head>
2227
<body>
23-
<a href="../index.xhtml">Item Home</a> &gt; <a href="../views/list-items.xq">List Items</a>
24-
<h1>Are you sure you want to delete this term?</h1>
25-
<strong>Name:</strong> {doc($doc)/term/term-name/text()}<br/>
26-
<strong>Path:</strong> {$doc}<br/>
27-
<br/>
28-
<a class="warn" href="delete.xq?id={$id}">Yes - Delete This Term</a><br/>
29-
<br/>
30-
<a class="warn" href="../views/view-item.xq?id={$id}">Cancel (Back to View Term)</a>
28+
<h1>{$title}</h1>
29+
<p>Item {$id} has been updated.</p>
3130
</body>
3231
</html>

0 commit comments

Comments
 (0)