Skip to content

Commit 622a1cc

Browse files
authored
Merge pull request majlis-erc#790 from evolvedbinary/refactor/cleanup-get-submit
Cleanup Get/Submit code
2 parents 47a3875 + f57525d commit 622a1cc

5 files changed

Lines changed: 739 additions & 582 deletions

File tree

src/main/formGenerator/generateXForm.xsl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -560,55 +560,55 @@
560560
<xml-base64 xsi:type="xs:base64Binary"/>
561561
</xf:instance>
562562
<xf:instance id="i-search">
563-
<data>
563+
<data xmlns="">
564564
<search>
565565
<q/>
566566
<facets/>
567567
</search>
568568
</data>
569569
</xf:instance>
570570
<xf:instance id="i-search-id">
571-
<data><q/></data>
571+
<data xmlns=""><q/></data>
572572
</xf:instance>
573573
<xf:instance id="i-search-results">
574-
<data/>
574+
<data xmlns=""/>
575575
</xf:instance>
576576
<xf:instance id="i-selected-search">
577-
<data>
577+
<data xmlns="">
578578
</data>
579579
</xf:instance>
580580
<xf:instance id="i-selected-facet">
581-
<data>
581+
<data xmlns="">
582582
<facetGrp label="" facet=""></facetGrp>
583583
</data>
584584
</xf:instance>
585585
<xf:instance id="i-selected">
586-
<data>
586+
<data xmlns="">
587587
</data>
588588
</xf:instance>
589589
<xf:instance id="i-selectTemplate">
590-
<data>
590+
<data xmlns="">
591591
<xsl:for-each select="$configDoc//template">
592592
<template name="{@name}" src="{@src}"/>
593593
</xsl:for-each>
594594
</data>
595595
</xf:instance>
596596
<xf:instance id="i-subforms">
597-
<data>
597+
<data xmlns="">
598598
<xsl:for-each select="$configDoc//subforms/subform">
599599
<subform formName="{@formName}" selected="false"/>
600600
</xsl:for-each>
601601
</data>
602602
</xf:instance>
603603
<xf:instance id="i-lookups">
604-
<data>
604+
<data xmlns="">
605605
<xsl:for-each select="$configDoc//lookup">
606606
<lookup formName="{@formName}" selected="false"/>
607607
</xsl:for-each>
608608
</data>
609609
</xf:instance>
610610
<xf:instance id="i-submission">
611-
<response status="success">
611+
<response xmlns="" status="success">
612612
<message>Submission result</message>
613613
<url></url>
614614
</response>
@@ -641,7 +641,7 @@
641641
<!-- Pretty print -->
642642
<xf:instance id="i-prettyPrint" src="forms/prettyPrint.xsl"></xf:instance>
643643
<xf:instance id="i-preview">
644-
<data></data>
644+
<data xmlns=""></data>
645645
</xf:instance>
646646
<xf:submission id="s-load-template" method="post" ref="instance('i-selected')" replace="instance" instance="i-rec" serialization="none" mode="synchronous">
647647
<xf:resource value="concat('services/get-rec.xql?template=true&amp;path=',instance('i-selected'))"/>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
xquery version "3.1";
2+
3+
module namespace rh = "http://localhost/manuForma/request-helper";
4+
5+
import module namespace request = "http://exist-db.org/xquery/request";
6+
7+
(:~
8+
: Get a HTTP request parameter.
9+
: Unlike request:get-parameter this will ignore parameters that have an empty string value.
10+
:
11+
: @param $name the name of the HTTP request parameter
12+
:
13+
: @return the value of the parameter if it is valid, or the empty sequence.
14+
:)
15+
declare function rh:request-param($name as xs:string) {
16+
rh:request-param($name, ())
17+
};
18+
19+
(:~
20+
: Get a HTTP request parameter.
21+
: Unlike request:get-parameter this will ignore parameters that have an empty string value, and return the default.
22+
:
23+
: @param $name the name of the HTTP request parameter
24+
: @param $default the default value to return if there is no valid parameter
25+
:
26+
: @return the value of the parameter if it is valid, or the default.
27+
:)
28+
declare function rh:request-param($name as xs:string, $default) {
29+
let $values := request:get-parameter($name, ())[. ne ""]
30+
return
31+
if (exists($values)) then
32+
$values
33+
else
34+
$default
35+
};
36+
37+
(:~
38+
: Get a HTTP request parameter as a boolean value.
39+
: Unlike request:get-parameter this will ignore parameters that have an empty string value.
40+
:
41+
: @param $name the name of the HTTP request parameter
42+
:
43+
: @return the boolean value of the parameter.
44+
:)
45+
declare function rh:request-param-bool($name as xs:string) as xs:boolean {
46+
lower-case(rh:request-param($name, "false")[1]) eq "true"
47+
};
48+
49+
(:~
50+
: Get HTTP request parameters.
51+
: Unlike request:get-parameter this will ignore parameters that have an empty string value.
52+
:
53+
: @param $name-prefix the name prefix of the HTTP request parameters
54+
:
55+
: @return a map or the names and values of the parameters if valid, or the empty sequence.
56+
:)
57+
declare function rh:request-params($name-prefix as xs:string) as map(xs:string, xs:string*)* {
58+
rh:request-params($name-prefix, ())
59+
};
60+
61+
(:~
62+
: Get HTTP request parameters.
63+
: Unlike request:get-parameter this will ignore parameters that have an empty string value, and return the default.
64+
:
65+
: @param $name-prefix the name prefix of the HTTP request parameters
66+
: @param $default the default value to return if there is no valid parameter
67+
:
68+
: @return a map or the names and values of the parameters if valid, or the default.
69+
:)
70+
declare function rh:request-params($name-prefix as xs:string, $default-value) as map(xs:string, xs:string*)* {
71+
for $name in request:get-parameter-names()[starts-with(., $name-prefix)]
72+
let $value := rh:request-param($name, $default-value)
73+
return
74+
if (exists($value)) then
75+
map { "name": $name, "value": $value }
76+
else
77+
()
78+
};

0 commit comments

Comments
 (0)