Skip to content

Commit

Permalink
fix: adopt community convention for XQuery modules
Browse files Browse the repository at this point in the history
… for all but those modules generated by tei-publisher-lib, which hardcodes the “xql” file extension
  • Loading branch information
joewiz committed Jun 28, 2024
1 parent 4bafaf2 commit ddb1adc
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 41 deletions.
30 changes: 15 additions & 15 deletions controller.xql → controller.xq
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ declare function local:serve-not-found-page() as element() {
local:render-page("error-page-404.xml")
};

declare variable $local:view-module-url := $exist:controller || "/modules/view.xql";
declare variable $local:view-module-url := $exist:controller || "/modules/view.xq";
declare function local:render-page($page-template as xs:string, $parameters as map(*)) as element() {
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/pages/{$page-template}"/>
Expand Down Expand Up @@ -102,16 +102,16 @@ else if (ends-with($exist:path, "validate-results-of-twitter-jobs.xq")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/tests/xquery/validate-results-of-twitter-jobs.xq"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
<forward url="{$exist:controller}/modules/view.xq"/>
</view>
<error-handler>
<forward url="{$exist:controller}/pages/error-page.xml" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
<forward url="{$exist:controller}/modules/view.xq"/>
</error-handler>
</dispatch>

(: ignore direct requests to main modules :)
else if (ends-with($exist:resource, ".xql")) then
else if (ends-with($exist:resource, ".xq")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<ignore/>
</dispatch>
Expand All @@ -123,7 +123,7 @@ else if (starts-with($exist:path, "/sitemap")) then

(: reject ANY request with more than 4 path parts -> /a/b/c/d/e :)
else if (count($path-parts) gt 4) then (
util:log("info", ("hsg-shell controller.xql received >4 path parts: ", string-join($path-parts, ":"))),
util:log("info", ("hsg-shell controller.xq received >4 path parts: ", string-join($path-parts, ":"))),
local:serve-not-found-page()
)

Expand Down Expand Up @@ -237,7 +237,7 @@ else switch($path-parts[1])
default return
(: return 404 for requests with unreasonable numbers of path path-parts :)
if (count($path-parts) gt 3) then (
util:log("info", ("hsg-shell controller.xql received >2 path-parts: ", string-join($path-parts, "/"))),
util:log("info", ("hsg-shell controller.xq received >2 path-parts: ", string-join($path-parts, "/"))),
local:serve-not-found-page()
)
else if (starts-with($path-parts[2], "frus")) then
Expand Down Expand Up @@ -581,16 +581,16 @@ else switch($path-parts[1])

case "frus-latest.xml" return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/open.xql">
<add-parameter name="xql-feed" value="latest"/>
<add-parameter name="xql-application-url" value="{local:get-url()}"/>
<forward url="{$exist:controller}/modules/open.xq">
<add-parameter name="xq-feed" value="latest"/>
<add-parameter name="xq-application-url" value="{local:get-url()}"/>
</forward>
</dispatch>
case "frus-metadata.xml" return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/open.xql">
<add-parameter name="xql-feed" value="metadata"/>
<add-parameter name="xql-application-url" value="{local:get-url()}"/>
<forward url="{$exist:controller}/modules/open.xq">
<add-parameter name="xq-feed" value="metadata"/>
<add-parameter name="xq-application-url" value="{local:get-url()}"/>
</forward>
</dispatch>
default return
Expand Down Expand Up @@ -666,8 +666,8 @@ else switch($path-parts[1])
case 'api' return
if ($path-parts[2] eq 'v1') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/opds-catalog.xql">
<add-parameter name="xql-application-url" value="{local:get-url()}"/>
<forward url="{$exist:controller}/modules/opds-catalog.xq">
<add-parameter name="xq-application-url" value="{local:get-url()}"/>
</forward>
<!--TODO Add an error handler appropriate for this API - with error codes, redirects. We currently let bad requests through without raising errors. -->
</dispatch>
Expand All @@ -680,7 +680,7 @@ else switch($path-parts[1])
case 'volume-ids'
case 'volume-images' return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/{$path-parts[2]}.xql"/>
<forward url="{$exist:controller}/modules/{$path-parts[2]}.xq"/>
<!--TODO Maybe add an error handler, but not the default one. -->
</dispatch>
default return
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/frus-toc-html.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ declare function toc:paginate($child-document-count as xs:int, $start as xs:int)
};

(:
TODO: Add processing this function to post-install.xql with the according permissions,
TODO: Add processing this function to post-install.xq with the according permissions,
check for target collection and create a new, empty one, if necessary
:)
declare function toc:generate-frus-tocs() {
Expand Down
8 changes: 4 additions & 4 deletions modules/lib/epub.xql → modules/lib/epub.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ xquery version "3.1";
module namespace epub = "http://exist-db.org/xquery/epub";

import module namespace config="http://history.state.gov/ns/site/hsg/config" at "../config.xqm";
import module namespace pm-config="http://www.tei-c.org/tei-simple/pm-config" at "../pm-config.xql";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xql";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "lib/util.xql";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation" at "../navigation.xql";
import module namespace pm-config="http://www.tei-c.org/tei-simple/pm-config" at "../pm-config.xqm";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xqm";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "lib/util.xqm";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation" at "../navigation.xqm";

declare namespace tei="http://www.tei-c.org/ns/1.0";

Expand Down
4 changes: 2 additions & 2 deletions modules/lib/get-epub.xql → modules/lib/get-epub.xq
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
xquery version "3.1";

import module namespace config="http://history.state.gov/ns/site/hsg/config" at "../config.xqm";
import module namespace epub="http://exist-db.org/xquery/epub" at "epub.xql";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xql";
import module namespace epub="http://exist-db.org/xquery/epub" at "epub.xqm";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xqm";

declare namespace tei="http://www.tei-c.org/ns/1.0";

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions modules/lib/transform.xql → modules/lib/transform.xq
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace tei="http://www.tei-c.org/ns/1.0";

import module namespace config="http://history.state.gov/ns/site/hsg/config" at "../config.xqm";
import module namespace pm-config="http://www.tei-c.org/tei-simple/pm-config" at "../pm-config.xql";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xql";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "util.xql";
import module namespace pm-config="http://www.tei-c.org/tei-simple/pm-config" at "../pm-config.xqm";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xqm";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "util.xqm";

declare option output:method "html";
declare option output:html-version "5.0";
Expand Down
2 changes: 1 addition & 1 deletion modules/lib/util.xql → modules/lib/util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module namespace tpu="http://www.tei-c.org/tei-publisher/util";


import module namespace config="http://history.state.gov/ns/site/hsg/config" at "../config.xqm";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation" at "../navigation.xql";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation" at "../navigation.xqm";

declare function tpu:parse-pi($doc as document-node(), $view as xs:string?) {
tpu:parse-pi($doc, $view, request:get-parameter("odd", ()))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/opds-catalog.xql → modules/opds-catalog.xq
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import module namespace tags="http://history.state.gov/ns/site/hsg/tags-html" at
declare option output:method "xml";

declare variable $opds:opds-path := 'api/v1/catalog';
declare variable $opds:server-url := substring-before(request:get-parameter('xql-application-url', ''), $opds:opds-path);
declare variable $opds:server-url := substring-before(request:get-parameter('xq-application-url', ''), $opds:opds-path);
declare variable $opds:opds-base-url := $opds:server-url || $opds:opds-path;
declare variable $opds:feed-author-name {'Office of the Historian'};
declare variable $opds:opds-search-url {concat($opds:server-url, 'opensearch.xml')};
Expand Down
4 changes: 2 additions & 2 deletions modules/open.xql → modules/open.xq
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import module namespace app="http://history.state.gov/ns/site/hsg/templates" at

declare option output:method "xml";

declare variable $application-url := request:get-parameter('xql-application-url', '');
declare variable $application-url := request:get-parameter('xq-application-url', '');


declare function open:frus-latest() {
Expand Down Expand Up @@ -227,7 +227,7 @@ declare function open:frus-metadata() {
</volumes>
};

switch(request:get-parameter('xql-feed', ''))
switch(request:get-parameter('xq-feed', ''))
case 'latest' return open:frus-latest()
case 'metadata' return open:frus-metadata()
default return <error/>
2 changes: 1 addition & 1 deletion modules/pages.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function pages:load($node as node(), $model as map(*), $publication-id as xs:str
()
let $created :=
if (exists($publication-id) and exists($document-id)) then
(: No need to truncate creation date; it'll be serialized in view.xql :)
(: No need to truncate creation date; it'll be serialized in view.xq :)
pages:created($publication-id, $document-id, $section-id)
else
()
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions modules/sitemap-config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ function site:cwpfus-with-param-select($select as attribute(select), $state as m
};

declare function site:get-url() {
(: imported from old controller.xql :)
(: imported from old controller.xq :)
concat(
request:get-scheme(),
'://',
Expand All @@ -843,7 +843,7 @@ declare function site:get-url() {
};

declare function site:get-uri() {
(: imported from old controller.xql :)
(: imported from old controller.xq :)
let $uri := (request:get-header("nginx-request-uri"), request:get-uri())[1]
return
if (contains($uri, "?")) then
Expand Down
4 changes: 2 additions & 2 deletions modules/view.xql → modules/view.xq
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(:~
: This is the main XQuery which will (by default) be called by controller.xql
: This is the main XQuery which will (by default) be called by controller.xq
: to process any URI ending with ".html". It receives the HTML from
: the controller and passes it to the templating system.
:)
xquery version "3.0";

import module namespace templates="http://exist-db.org/xquery/html-templating" ;
import module namespace templates="http://exist-db.org/xquery/html-templating";

(:
: The following modules provide functions which will be called by the
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions post-install.xql → post-install.xq
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ declare function local:generate-code($collection as xs:string) {
)
};

sm:chmod(xs:anyURI($target || "/modules/view.xql"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/frus-ajax.xql"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/fo.xql"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/lib/regenerate.xql"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/view.xq"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/frus-ajax.xq"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/fo.xq"), "rwsr-xr-x"),
sm:chmod(xs:anyURI($target || "/modules/lib/regenerate.xq"), "rwsr-xr-x"),
(:sm:chmod(xs:anyURI($target || "/tests/xquery/validate-results-of-twitter-jobs.xq"), "rwsr-xr-x"),:)
util:eval(xs:anyURI($target || "/modules/lib/regenerate.xql")),
util:eval(xs:anyURI($target || "/modules/lib/regenerate.xq")),

local:generate-code($target)
File renamed without changes.
4 changes: 2 additions & 2 deletions repo.xml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<copyright>true</copyright>
<type>application</type>
<target>hsg-shell</target>
<prepare>pre-install.xql</prepare>
<finish>post-install.xql</finish>
<prepare>pre-install.xq</prepare>
<finish>post-install.xq</finish>
<permissions xmlns:repo="http://exist-db.org/xquery/repo" password="" user="hsg" group="hsg"
mode="rw-rw-r--"/>
</meta>

0 comments on commit ddb1adc

Please sign in to comment.