<commit_before>(: 	This is the main controller for the web application. It is called from the
	XQueryURLRewrite filter configured in web.xml. :)
xquery version "1.0";

declare namespace c="http://exist-db.org/xquery/controller";

import module namespace request="http://exist-db.org/xquery/request";
import module namespace xdb = "http://exist-db.org/xquery/xmldb";

declare function c:admin($path as xs:string, $name as xs:string) {
    if (starts-with($path, "/admin/backups")) then
        let $user := xdb:get-current-user()
        return
            if (not(xdb:is-admin-user($user))) then
                <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        			<redirect url="../admin.xql"/>
        		</dispatch>
        	else
                <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
                    <forward url="/admin/retrieve-backup.xql">
                        <add-parameter name="archive" value="{$name}"/>
                    </forward>
                </dispatch>
    else if (matches($path, "admin/?$")) then
        <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
			<redirect url="admin.xql"/>
		</dispatch>
    else if ($name eq "admin.xql") then
	    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
	        <forward url="/admin/admin.xql"/>
	    </dispatch>
    else
        <ignore xmlns="http://exist.sourceforge.net/NS/exist">
            <cache-control cache="yes"/>
		</ignore>
};

let $uri := request:get-uri()
let $context := request:get-context-path()
let $path := substring-after($uri, $context)
let $name := replace($uri, '^.*/([^/]+)$', '$1')
let $query := request:get-parameter("q", ())
return
	(: redirect webapp root to index.xml :)
    if ($path eq '/') then
		<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
			<redirect url="index.xml"/>
		</dispatch>
	(: /rest and /webdav will be ignored :)
	else if (matches($path, "/(rest|webdav|cocoon|test.xml)")) then
		<ignore xmlns="http://exist.sourceforge.net/NS/exist">
            <cache-control cache="yes"/>
		</ignore>
	(: redirect sandbox root to sandbox.xql :)<commit_msg>[ignore] fixed problem with REST servlet if called as /exist/servlet instead of /exist/rest<commit_after>(: 	This is the main controller for the web application. It is called from the
	XQueryURLRewrite filter configured in web.xml. :)
xquery version "1.0";

declare namespace c="http://exist-db.org/xquery/controller";

import module namespace request="http://exist-db.org/xquery/request";
import module namespace xdb = "http://exist-db.org/xquery/xmldb";

declare function c:admin($path as xs:string, $name as xs:string) {
    if (starts-with($path, "/admin/backups")) then
        let $user := xdb:get-current-user()
        return
            if (not(xdb:is-admin-user($user))) then
                <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        			<redirect url="../admin.xql"/>
        		</dispatch>
        	else
                <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
                    <forward url="/admin/retrieve-backup.xql">
                        <add-parameter name="archive" value="{$name}"/>
                    </forward>
                </dispatch>
    else if (matches($path, "admin/?$")) then
        <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
			<redirect url="admin.xql"/>
		</dispatch>
    else if ($name eq "admin.xql") then
	    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
	        <forward url="/admin/admin.xql"/>
	    </dispatch>
    else
        <ignore xmlns="http://exist.sourceforge.net/NS/exist">
            <cache-control cache="yes"/>
		</ignore>
};

let $uri := request:get-uri()
let $context := request:get-context-path()
let $path := substring-after($uri, $context)
let $name := replace($uri, '^.*/([^/]+)$', '$1')
let $query := request:get-parameter("q", ())
return
	(: redirect webapp root to index.xml :)
    if ($path eq '/') then
		<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
			<redirect url="index.xml"/>
		</dispatch>
	(: /rest and /webdav will be ignored :)
	else if (matches($path, "/(rest|servlet|webdav|cocoon|test.xml)")) then
		<ignore xmlns="http://exist.sourceforge.net/NS/exist">
            <cache-control cache="yes"/>
		</ignore>
	(: redirect sandbox root to sandbox.xql :)
{'fraction_non_alphanumeric': 0.17659279778393353, 'fraction_numerical': 0.0013850415512465374, 'mean_word_length': 2.7909011373578303, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2720490', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1328, 'n_words': 310}