Changeset 3165


Ignore:
Timestamp:
07/18/13 16:19:57 (11 years ago)
Author:
andmor
Message:

Chenged basex query wrapper to be able to issue 'update' queries (without a return value).
The original query passed to the wrapper, must now be enclosed in a '<query>' dummy node.
The namespaces for the query must now be specified in the '<query>' node.
Removed superfluous debug information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cats/SCHEMAcat/trunk/urn.org.basex.rest/rest/query.dpml

    r3117 r3165  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <sequence debug="false" profile="false">
     2<sequence debug="true" profile="false">
    33        <!-- load BaseX DB configuration parameters -->
    44        <request assignment="config">
     
    1515                                        <xsl:param name="vararg"/>
    1616                                        <xsl:param name="debug"/>
    17                                         <xsl:variable name="NL" select="system-property('line.separator')"/>
    18                                         <xsl:template match="*[empty(parent::*)]">
    19                                                 <xsl:variable name="root" select="current()"/>
     17                                        <xsl:template match="query">
    2018                                                <rest:query>
    2119                                                        <rest:text>
    22                                                                 <!-- turn the namespaces in scope of the root element into 'declare namespace' statements -->
    23                                                                 <xsl:for-each
    24                                                                         select="in-scope-prefixes($root)[not(.=('xml','xs','xsi','fn','local'))]">
    25                                                                         <xsl:variable name="prefix" select="current()"/>
    26                                                                         <xsl:choose>
    27                                                                                 <xsl:when test="$prefix=''">
    28                                                                                         <xsl:text>declare default namespace "</xsl:text>
    29                                                                                         <xsl:value-of
    30                                                                                                 select="namespace-uri-for-prefix($prefix,$root)"/>
    31                                                                                         <xsl:text>";</xsl:text>
    32                                                                                         <xsl:value-of select="$NL"/>
    33                                                                                 </xsl:when>
    34                                                                                 <xsl:otherwise>
    35                                                                                         <xsl:text>declare namespace </xsl:text>
    36                                                                                         <xsl:value-of select="$prefix"/>
    37                                                                                         <xsl:text> = "</xsl:text>
    38                                                                                         <xsl:value-of
    39                                                                                                 select="namespace-uri-for-prefix($prefix,$root)"/>
    40                                                                                         <xsl:text>";</xsl:text>
    41                                                                                         <xsl:value-of select="$NL"/>
    42                                                                                 </xsl:otherwise>
    43                                                                         </xsl:choose>
    44                                                                 </xsl:for-each>
     20                                                                        <xsl:variable name="current-node" select="."/>
     21                                                                        <!-- turn the namespaces in scope of the root element into 'declare namespace' statements -->
     22                                                                        <xsl:for-each
     23                                                                                select="in-scope-prefixes($current-node)[not(.=('xml','xs','xsi','fn','local'))]">
     24                                                                                <xsl:variable name="prefix" select="current()"/>
     25                                                                                <xsl:choose>
     26                                                                                        <xsl:when test="$prefix=''">
     27                                                                                                <xsl:text>declare default element namespace "</xsl:text>
     28                                                                                                <xsl:value-of
     29                                                                                                        select="namespace-uri-for-prefix($prefix,$current-node)"/>
     30                                                                                                <xsl:text>";</xsl:text>
     31                                                                                        </xsl:when>
     32                                                                                        <xsl:otherwise>
     33                                                                                                <xsl:text>declare namespace </xsl:text>
     34                                                                                                <xsl:value-of select="$prefix"/>
     35                                                                                                <xsl:text> = "</xsl:text>
     36                                                                                                <xsl:value-of
     37                                                                                                        select="namespace-uri-for-prefix($prefix,$current-node)"/>
     38                                                                                                <xsl:text>";</xsl:text>
     39                                                                                        </xsl:otherwise>
     40                                                                                </xsl:choose>
     41                                                                        </xsl:for-each>
    4542                                                                <!-- turn any additional arguments into variables -->
    4643                                                                <xsl:for-each
    47                                                                         select="$vararg/arguments/*[not(name()=('operator','query'))]">
     44                                                                        select="$vararg/arguments/*[not(name()=('operator','query','sloot-operator'))]">
    4845                                                                        <xsl:variable name="var" select="name()"/>
    4946                                                                        <xsl:text>declare variable $</xsl:text>
    5047                                                                        <xsl:value-of select="$var"/>
    5148                                                                        <xsl:text> external;</xsl:text>
    52                                                                         <xsl:value-of select="$NL"/>
    5349                                                                </xsl:for-each>
    54                                                                 <xsl:apply-templates mode="copy" select="."/>
     50                                                                <xsl:apply-templates mode="copy" select="./node()"/>
    5551                                                        </rest:text>
    5652                                                        <!-- pass on any additonal arguments as variables -->
    5753                                                        <xsl:for-each
    58                                                                 select="$vararg/arguments/*[not(name()=('operator','query'))]">
     54                                                                select="$vararg/arguments/*[not(name()=('operator','query','sloot-operator'))]">
    5955                                                                <xsl:if test="$debug">
    6056                                                                        <xsl:message>DBG: variable name[<xsl:value-of select="name()"
     
    8884                                        <!-- turn a text node into an escaped XML string -->
    8985                                        <xsl:template match="text()" mode="copy">
    90                                                 <xsl:value-of select="."/>
     86                                                <xsl:value-of select="normalize-space(.)"/>
    9187                                        </xsl:template>
    9288                                </xsl:stylesheet>
     
    122118                                                <argument name="operand">this:config</argument>
    123119                                                <argument name="operator">
    124                                                         <literal type="string"
    125                                                                 >/nvp/concat(basex-db-username,':',basex-db-password)</literal>
     120                                                        <literal type="string">/nvp/concat(basex-db-username,':',basex-db-password)</literal>
    126121                                                </argument>
    127122                                        </request>
     
    130125                </argument>
    131126        </request>
    132         <sloot-debug>
    133                 <request>
    134                         <verb>SINK</verb>
    135                         <identifier>res:/debug-basex/org.basex.auth.xml</identifier>
    136                         <argument name="primary">this:AuthHeader</argument>
    137                 </request>
    138         </sloot-debug>
    139127        <!-- Compute BaseX endpoint -->
    140128        <request assignment="db-endpoint">
     
    142130                <argument name="operand">this:config</argument>
    143131                <argument name="operator">
    144                         <literal type="string"
    145                                 >/nvp/concat('http://',basex-rest-host,':',basex-rest-port,'/',basex-rest-path,'/',basex-db-name)</literal>
     132                        <literal type="string">/nvp/concat('http://',basex-rest-host,':',basex-rest-port,'/',basex-rest-path,'/',basex-db-name)</literal>
    146133                </argument>
    147134        </request>
Note: See TracChangeset for help on using the changeset viewer.