dba/common  library module
RA

Summary

Common RESTXQ access points.
Tags

Author: Christian Grün, BaseX Team 2005-21, BSD License

__source : common.xqm

Related documents
ViewDescriptionFormat
xqdocxqDoc xml file from the source modulexml
xqparsexqparse xml file from the source modulexml

Imports

This module is imported by 0 modules. It imports 1 modules.

(None)
imports
this
imports

Variables

None

Functions

4.1 dba:file

Arities: dba:file#1RA

Summary
Returns a file.
Signature
dba:file ( $file as xs:string )  as item()+
Parameters
  • file as xs:string file or unknown path
Return
  • item() +rest binary data
Invoked by 0 functions from 0 modules
    Annotations
    %rest:path('/dba/static/{$file=.+}')
    %output:method('basex')
    %perm:allow('public')
    Source ( 0 lines)

    4.2 dba:redirect

    Arities: dba:redirect#0R

    Summary
    Redirects to the start page.
    Signature
    dba:redirect ( )  as element(rest:response)
    Return
    • element(rest:response)redirection
    Invoked by 0 functions from 0 modules
      Annotations
      %rest:path('/dba')
      Source ( 0 lines)

      4.3 dba:unknown

      Arities: dba:unknown#1RA

      Summary
      Shows a 'page not found' error.
      Signature
      dba:unknown ( $path as xs:string )  as element(html)
      Parameters
      • path as xs:string path to unknown page
      Return
      • element(html)page
      Invoked by 0 functions from 0 modules
        Annotations
        %rest:path('/dba/{$path}')
        %output:method('html')
        Source ( 0 lines)

        Namespaces

        The following namespaces are defined:

        PrefixUri
        dbadba/common
        htmldba/html
        outputhttp://www.w3.org/2010/xslt-xquery-serialization
        permhttp://basex.org/modules/perm
        resthttp://exquery.org/ns/restxq

        6 RestXQ

        Paths defined 3.

        PathMethodFunction
        /dbadba:redirect#0
        /dba/static/{$file=.+}dba:file#1
        /dba/{$path}dba:unknown#1

        Source Code

        (:~
         : Common RESTXQ access points.
         :
         : @author Christian Grün, BaseX Team 2005-21, BSD License
         :)
        module namespace dba = 'dba/common';
        
        import module namespace html = 'dba/html' at 'lib/html.xqm';
        
        (:~
         : Redirects to the start page.
         : @return redirection
         :)
        declare
          %rest:path('/dba')
        function dba:redirect(
        ) as element(rest:response) {
          web:redirect('/dba/logs')
        };
        
        (:~
         : Returns a file.
         : @param  $file  file or unknown path
         : @return rest binary data
         :)
        declare
          %rest:path('/dba/static/{$file=.+}')
          %output:method('basex')
          %perm:allow('public')
        function dba:file(
          $file  as xs:string
        ) as item()+ {
          let $path := file:base-dir() || 'static/' || $file
          return (
            web:response-header(
              map { 'media-type': web:content-type($path) },
              map { 'Cache-Control': 'max-age=3600,public', 'Content-Length': file:size($path) }
            ),
            file:read-binary($path)
          )
        };
        
        (:~
         : Shows a 'page not found' error.
         : @param  $path  path to unknown page
         : @return page
         :)
        declare
          %rest:path('/dba/{$path}')
          %output:method('html')
        function dba:unknown(
          $path  as xs:string
        ) as element(html) {
          html:wrap(
            <tr>
              <td>
                <h2>Page not found:</h2>
                <ul>
                  <li>Page: dba/{ $path }</li>
                  <li>Method: { request:method() }</li>
                </ul>
              </td>
            </tr>
          )
        };