minor changes to edit DEC functionality

minor changes to edit DEC functionality

xquery version "1.0";

(: ~
 : Module Name:             new property webpage and XQuery
 :
 : Module Version           2.0
 :
 : Date                     31st July 2007
 :
 : Copyright                The cagrid consortium
 :
 : Module overview          Creates and property and displays list
 :
 :)

(:~
 :    @author Steve Harris
 :    @version 0.1
 :
 :    @author Steve Harris
 :    @version 2.0
 :     now allows searching for concept terms
~ :)

  import module namespace
  lib-forms="http://www.cagrid.org/xquery/library/forms"
  at "../edit/m-lib-forms.xquery";

  import module namespace
  lib-util="http://www.cagrid.org/xquery/library/util"
  at "../library/m-lib-util.xquery";

  import module namespace
  lib-rendering="http://www.cagrid.org/xquery/library/rendering"
  at "../web/m-lib-rendering.xquery";

  import module namespace
  lib-make-admin-item="http://www.cagrid.org/xquery/library/make-admin-item"
  at "../edit/m-lib-make-admin-item.xquery";

declare namespace openMDR = "http://www.cagrid.org/schema/openMDR";
declare namespace ISO11179= "http://www.cagrid.org/schema/ISO11179";
declare namespace session="http://exist-db.org/xquery/session";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace exist = "http://exist.sourceforge.net/NS/exist";
declare namespace util="http://exist-db.org/xquery/util";

declare function local:DataElementConcept(
   $id as xs:string,
   $reg-auth as xs:string,
   $administrative-note as xs:string,
   $administrative-status as xs:string,
   $administered-by as xs:string,
   $submitted-by as xs:string,
   $registered-by as xs:string,
   $context-ids as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $preferred as xs:string?
   ) as xs:string
   {
   let $version := '0.1'

   let $object_class_id := request:get-parameter('object_class_id','')
   let $property_id := request:get-parameter('property_id','')
   let $conceptual_domain_id := request:get-parameter('conceptual_domain_id','')
   let $object_class_uri := request:get-parameter('object_class_uri','')
   let $property_uri := request:get-parameter('property_uri','')

   let $data-identifier-oc := substring-after(lib-forms:substring-before-last($id,'-'),'-')
   let $data-identifier-pr := substring-after(lib-forms:substring-before-last($id,'-'),'-')

   let $full-identifier-oc := concat($reg-auth, '-', $data-identifier-oc, '-', $version)
   let $full-identifier-pr := concat($reg-auth, '-', $data-identifier-pr, '-', $version)

   let $data-identifier := lib-forms:generate-id()
   let $new-identifier := concat($reg-auth, '-', $data-identifier, '-', $version)

   let $content := (
           lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
            lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
            lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
                    (:
                    element openMDR:data_element_concept_conceptual_domain {$conceptual_domain_id},
                    element openMDR:data_element_concept_object_class
                    {
                        if ($object_class_id) then ($object_class_id) else ($full-identifier-oc)
                    },
                    element openMDR:data_element_concept_property
                    {
                        if ($property_id) then ($property_id) else ($full-identifier-pr)
                    }
                    :)

                    element openMDR:data_element_concept_conceptual_domain {$conceptual_domain_id},
                    element openMDR:data_element_concept_object_class {$object_class_id},
                    element openMDR:data_element_concept_property {$property_id}
                    )

let $object-class :=
   (
   element openMDR:Object_Class {
        lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier-oc,$version),
        lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
        lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
        lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
        element openMDR:reference_uri {$object_class_uri}
        }
   )

let $property :=
   (
    element openMDR:DataElementConcept {
        lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier-pr,$version),
        lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
        lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
        lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
        element openMDR:reference_uri {$property_uri}
        }
   )

   (: compose the document :)
   let $document :=
      element openMDR:Data_Element_Concept {
            lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier,$version),
            $content
           }

   return
   if ((
      if ($object_class_id > '')
      then 'stored'
      else lib-forms:store-document($object-class))='stored'
      )
   then (
      if ((
         if ($property_id > '')
         then 'stored'
         else lib-forms:store-document($property))='stored')
      then (
          if(lib-forms:store-document($document)='stored')
          then 'stored'
          else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store data element concept"))) )
          )
      else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store property"))) )
   )
   else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store object class"))) )

};

declare function local:input-page(
   $message as xs:string?,
   $id as xs:string,
   $reg-auth as xs:string,
   $administrative-note as xs:string,
   $administrative-status as xs:string,
   $administered-by as xs:string,
   $submitted-by as xs:string,
   $registered-by as xs:string,
   $context-ids as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $preferred as xs:string?,
   $action as xs:string?
   )

   {
   let $skip-name := substring-after($action,'delete naming entry')
   let $skip-name-index := if ($skip-name>'') then xs:int($skip-name) else 0

   return

                This form will allow you to Edit a DataElementConcept in the metadata repository

          <form name="edit_DataElementConcept" action="editDataElementConcept.xquery" method="post" class="cagridForm" enctype="multipart/form-data">

             {lib-forms:hidden-element('id',$id)}
             {lib-forms:hidden-element('updating','updating')}

             {lib-forms:edit-admin-item($reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $preferred,
                     $action)}

                  Object Class URI

                     {lib-forms:find-concept-id('object_class_uri','get object class concept',request:get-parameter('object_class_uri',''))}

                   or select existing
                  {lib-forms:make-select-admin-item('object_class','object_class_id', request:get-parameter('object_class_id',''))}

                  Property URI

                     {lib-forms:find-concept-id('property_uri','get property concept',request:get-parameter('property_uri',''))}

                   or select existing
                     {lib-forms:make-select-admin-item('property','property_id', request:get-parameter('property_id',''))}

                  Conceptual Domain

                     {lib-forms:make-select-admin-item('conceptual_domain','conceptual_domain_id', request:get-parameter('conceptual_domain_id',''))}

	<input type="submit" name="update" value="Store"/>	<input type="submit" name="update" value="Clear"/>

          </form>

{$message}

   };

declare function local:success-page()
{
   let $calling-page := request:get-parameter("calling-page","")
   return

Property modified

Return to maintenance menu

Create another DataElementConcept

};

declare option exist:serialize "media-type=text/html method=xhtml doctype-public=-//W3C//DTD XHTML 1.0 Transitional//EN doctype-system=http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd";

   session:create(),
   let $id := request:get-parameter('id','')
   let $updating := request:get-parameter('updating','')
   let $title as xs:string := "Editing DataElementConcept"
   let $element := lib-util:mdrElement("DataElementConcept",$id)
   let $action := request:get-parameter('update','')

   let $reg-auth := request:get-parameter('registration-authority','')
   let $administrative-note := request:get-parameter('administrative-note','')
   let $administrative-status := request:get-parameter('administrative-status','')
   let $administered-by := request:get-parameter('administered-by','')
   let $submitted-by := request:get-parameter('submitted-by','')
   let $registered-by := request:get-parameter('registered-by','')
   let $context-ids := request:get-parameter('context-ids',())
   let $country-identifiers := request:get-parameter('country-identifiers',())
   let $language-identifiers := request:get-parameter('language-identifiers',())
   let $names := request:get-parameter('names',())
   let $definitions := request:get-parameter('definitions',())
   let $sources := request:get-parameter('sources',())
   let $preferred := request:get-parameter('preferred','')

   let $ireg-auth := string($element/@item_registration_authority_identifier)
   let $iadministrative-note := string($element//openMDR:administrative_note)
   let $iadministrative-status := string($element//openMDR:administrative_status)
   let $iadministered-by := string($element//openMDR:administered_by)
   let $isubmitted-by := string($element//openMDR:submitted_by)
   let $iregistered-by := string($element//openMDR:registered_by)
   let $icontext-ids := $element//openMDR:context_identifier
   let $icountry-identifiers := $element//openMDR:country_identifier
   let $ilanguage-identifiers := $element//openMDR:language_identifier
   let $inames := $element//openMDR:name
   let $idefinitions := $element//openMDR:definition_text
   let $isources := $element//openMDR:definition_source_reference
   let $ipreferred := string(fn:index-of($element//openMDR:preferred_designation,'true'))

   return

      lib-rendering:txfrm-webpage(
      $title,
      if ($action='Store Changes')
      then
         (
         if (
               local:DataElementConcept
                  (
                     $id,
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $preferred
                  )
            )
         then (local:success-page()  )
         else (local:input-page(
            'could not store document',
                     $id,
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $action,
                     $preferred
                  )
               )
         )
      else (
         if ($updating ='updating')
         then (
      local:input-page
               (
               '',
               $id,
               $reg-auth,
               $administrative-note,
               $administrative-status,
               $administered-by,
               $submitted-by,
               $registered-by,
               $context-ids,
               $country-identifiers,
               $language-identifiers,
               $names,
               $definitions,
               $sources,
               $action,
               $preferred
               )
         ) else (
               local:input-page
               (
               '',
               $id,
               $ireg-auth,
               $iadministrative-note,
               $iadministrative-status,
               $iadministered-by,
               $isubmitted-by,
               $iregistered-by,
               $icontext-ids,
               $icountry-identifiers,
               $ilanguage-identifiers,
               $inames,
               $idefinitions,
               $isources,
               $action,
               $ipreferred
               )
         )
       )

    )

xquery version "1.0";

(: ~
 : Module Name:             new property webpage and XQuery
 :
 : Module Version           2.0
 :
 : Date                     31st July 2007
 :
 : Copyright                The cagrid consortium
 :
 : Module overview          Creates and property and displays list
 :
 :)

(:~
 :    @author Steve Harris
 :    @version 0.1
 :
 :    @author Steve Harris
 :    @version 2.0
 :     now allows searching for concept terms
~ :)

  import module namespace
  lib-forms="http://www.cagrid.org/xquery/library/forms"
  at "../edit/m-lib-forms.xquery";

  import module namespace
  lib-util="http://www.cagrid.org/xquery/library/util"
  at "../library/m-lib-util.xquery";

  import module namespace
  lib-rendering="http://www.cagrid.org/xquery/library/rendering"
  at "../web/m-lib-rendering.xquery";

  import module namespace
  lib-make-admin-item="http://www.cagrid.org/xquery/library/make-admin-item"
  at "../edit/m-lib-make-admin-item.xquery";

declare namespace openMDR = "http://www.cagrid.org/schema/openMDR";
declare namespace ISO11179= "http://www.cagrid.org/schema/ISO11179";
declare namespace session="http://exist-db.org/xquery/session";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace exist = "http://exist.sourceforge.net/NS/exist";
declare namespace util="http://exist-db.org/xquery/util";

declare function local:DataElementConcept(
   $id as xs:string,
   $reg-auth as xs:string,
   $administrative-note as xs:string,
   $administrative-status as xs:string,
   $administered-by as xs:string,
   $submitted-by as xs:string,
   $registered-by as xs:string,
   $context-ids as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $preferred as xs:string?
   ) as xs:string
   {
   let $version := '0.1'

   let $object_class_id := request:get-parameter('object_class_id','')
   let $property_id := request:get-parameter('property_id','')
   let $conceptual_domain_id := request:get-parameter('conceptual_domain_id','')
   let $object_class_uri := request:get-parameter('object_class_uri','')
   let $property_uri := request:get-parameter('property_uri','')

   let $data-identifier-oc := substring-after(lib-forms:substring-before-last($id,'-'),'-')
   let $data-identifier-pr := substring-after(lib-forms:substring-before-last($id,'-'),'-')

   let $full-identifier-oc := concat($reg-auth, '-', $data-identifier-oc, '-', $version)
   let $full-identifier-pr := concat($reg-auth, '-', $data-identifier-pr, '-', $version)

   let $data-identifier := lib-forms:generate-id()
   let $new-identifier := concat($reg-auth, '-', $data-identifier, '-', $version)

   let $content := (
           lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
            lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
            lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
                    element openMDR:data_element_concept_conceptual_domain {$conceptual_domain_id},
                    element openMDR:data_element_concept_object_class {$object_class_id},
                    element openMDR:data_element_concept_property {$property_id})
let $object-class :=
   (
   element openMDR:Object_Class {
        lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier-oc,$version),
         lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
            lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
            lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
        element openMDR:reference_uri {$object_class_uri}
        }
   )

let $property :=
   (
    element openMDR:Property {
        lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier-pr,$version),
         lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
            lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
            lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
        element openMDR:reference_uri {$property_uri}
        }
   )

   (: compose the document :)
   let $document :=
      element openMDR:Data_Element_Concept {
            lib-make-admin-item:identifier-attributes($reg-auth,$data-identifier,$version),
            $content
           }

   return
   if ((
      if ($object_class_id > '')
      then 'stored'
      else lib-forms:store-document($object-class))='stored'
      )
   then (
      if ((
         if ($property_id > '')
         then 'stored'
         else lib-forms:store-document($property))='stored')
      then (
          if(lib-forms:store-document($document)='stored')
          then 'stored'
          else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store data element concept"))) )
          )
      else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store property"))) )
   )
   else ( response:redirect-to(xs:anyURI(concat("login.xquery?calling_page=newDataElementConcept.xquery&","Could not store object class"))) )

};

declare function local:input-page(
   $message as xs:string?,
   $id as xs:string,
   $reg-auth as xs:string,
   $administrative-note as xs:string,
   $administrative-status as xs:string,
   $administered-by as xs:string,
   $submitted-by as xs:string,
   $registered-by as xs:string,
   $context-ids as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $preferred as xs:string?,
   $action as xs:string?
   )

   {
   let $skip-name := substring-after($action,'delete naming entry')
   let $skip-name-index := if ($skip-name>'') then xs:int($skip-name) else 0

   return

                This form will allow you to create a new DataElementConcept in the metadata repository

          <form name="edit_DataElementConcept" action="editDataElementConcept.xquery" method="post" class="cagridForm" enctype="multipart/form-data">

             {lib-forms:hidden-element('id',$id)}
             {lib-forms:hidden-element('updating','updating')}

             {lib-forms:edit-admin-item($reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $preferred,
                     $action)}

                  Object Class URI

                     {lib-forms:find-concept-id('object_class_uri','get object class concept',request:get-parameter('object_class_uri',''))}

                   or select existing
                  {lib-forms:make-select-admin-item('object_class','object_class_id', request:get-parameter('object_class_id',''))}

                  Property URI

                     {lib-forms:find-concept-id('property_uri','get property concept',request:get-parameter('property_uri',''))}

                   or select existing
                     {lib-forms:make-select-admin-item('property','property_id', request:get-parameter('property_id',''))}

                  Conceptual Domain

                     {lib-forms:make-select-admin-item('conceptual_domain','conceptual_domain_id', request:get-parameter('conceptual_domain_id',''))}

	<input type="submit" name="update" value="Store"/>	<input type="submit" name="update" value="Clear"/>

          </form>

{$message}

   };

declare function local:success-page()
{
   let $calling-page := request:get-parameter("calling-page","")
   return

Property modified

Return to maintenance menu

Create another DataElementConcept

};

declare option exist:serialize "media-type=text/html method=xhtml doctype-public=-//W3C//DTD XHTML 1.0 Transitional//EN doctype-system=http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd";

   session:create(),
   let $id := request:get-parameter('id','')
   let $updating := request:get-parameter('updating','')
   let $title as xs:string := "Creating a New DataElementConcept"
   let $element := lib-util:mdrElement("DataElementConcept",$id)
   let $action := request:get-parameter('update','')

   let $reg-auth := request:get-parameter('registration-authority','')
   let $administrative-note := request:get-parameter('administrative-note','')
   let $administrative-status := request:get-parameter('administrative-status','')
   let $administered-by := request:get-parameter('administered-by','')
   let $submitted-by := request:get-parameter('submitted-by','')
   let $registered-by := request:get-parameter('registered-by','')
   let $context-ids := request:get-parameter('context-ids',())
   let $country-identifiers := request:get-parameter('country-identifiers',())
   let $language-identifiers := request:get-parameter('language-identifiers',())
   let $names := request:get-parameter('names',())
   let $definitions := request:get-parameter('definitions',())
   let $sources := request:get-parameter('sources',())
   let $preferred := request:get-parameter('preferred','')

   let $ireg-auth := string($element/@item_registration_authority_identifier)
   let $iadministrative-note := string($element//openMDR:administrative_note)
   let $iadministrative-status := string($element//openMDR:administrative_status)
   let $iadministered-by := string($element//openMDR:administered_by)
   let $isubmitted-by := string($element//openMDR:submitted_by)
   let $iregistered-by := string($element//openMDR:registered_by)
   let $icontext-ids := $element//openMDR:context_identifier
   let $icountry-identifiers := $element//openMDR:country_identifier
   let $ilanguage-identifiers := $element//openMDR:language_identifier
   let $inames := $element//openMDR:name
   let $idefinitions := $element//openMDR:definition_text
   let $isources := $element//openMDR:definition_source_reference
   let $ipreferred := string(fn:index-of($element//openMDR:preferred_designation,'true'))

   return

      lib-rendering:txfrm-webpage(
      $title,
      if ($action='Store Changes')
      then
         (
         if (
               local:DataElementConcept
                  (
                     $id,
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $preferred
                  )
            )
         then (local:success-page()  )
         else (local:input-page(
            'could not store document',
                     $id,
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $action,
                     $preferred
                  )
               )
         )
      else (
         if ($updating ='updating')
         then (
      local:input-page
               (
               '',
               $id,
               $reg-auth,
               $administrative-note,
               $administrative-status,
               $administered-by,
               $submitted-by,
               $registered-by,
               $context-ids,
               $country-identifiers,
               $language-identifiers,
               $names,
               $definitions,
               $sources,
               $action,
               $preferred
               )
         ) else (
               local:input-page
               (
               '',
               $id,
               $ireg-auth,
               $iadministrative-note,
               $iadministrative-status,
               $iadministered-by,
               $isubmitted-by,
               $iregistered-by,
               $icontext-ids,
               $icountry-identifiers,
               $ilanguage-identifiers,
               $inames,
               $idefinitions,
               $isources,
               $action,
               $ipreferred
               )
         )
       )

    )


Reverted the change in the script that generates teh W3C results for tests CastFOCA0003-1 and CastFOCA0001-1.

(: Schema for results :)
import schema default element namespace "http://www.w3.org/2005/02/query-test-XQTSResult" at "w3c_reportingresults/XQTSResult.xsd";

(: Test.xml file from ctest :)
declare variable $ctests as document-node() external;

if(fn:empty($ctests)) then
  fn:error()
else
  validate {
    <test-suite-result>
       <implementation name="Zorba"
         version='2.0 (svn rev. 9658)'
         anonymous-result-column="false">

         <organization
            name='FLWOR Foundation'
            website="http://zorba-xquery.com/"
            anonymous="false" />

         <submittor
            name="Zorba Team"
            email="contact@zorba-xquery.com" />

         <description>

Zorba is a general purpose XQuery processor implementing in C++
            the W3C family of specifications. It is not an XML database.
            The query processor has been designed to be embeddable in a
            variety of environments such as other programming languages
            extended with XML processing capabilities, browsers,
            database servers, XML message dispatchers, or smartphones.
            Its architecture employes a modular design, which allows customizing
            the Zorba query processor to the environment’s needs.
            In particular the architecture of the query processor allows a
            pluggable XML store (e.g. main memory, DOM stores, persistent
            disk-based large stores, S3 stores). Zorba runs on most platforms
            and is available under the Apache license v2. Currently, Zorba
            implements the following W3C specifications: XQuery 1.0, XQuery Update
            Facility 1.0, XQuery Scripting Extension 1.0, and XSLT 2.0 and XQuery 1.0
            Serialization.

         </description>

         <implementation-defined-items>
           <implementation-defined-item
              name="The revalidation modes that are supported by this implementation."
              value="lax, skip, strict" />

          <implementation-defined-item
             name="The default revalidation mode for this implementation."
             value="lax" />

         </implementation-defined-items>

         <features>
            <feature name='Minimum Conformance' supported='true' />
            <feature name='Schema Import' supported='true' />
            <feature name='Schema Validation' supported='true' />
            <feature name='Static Typing' supported='false' />
            <feature name='Static Typing Extensions' supported='false' />
            <feature name='Full Axis' supported='true' />
            <feature name='Module' supported='true' />
            <feature name='Serialization' supported='true' />
         </features>

         <context-properties>
            <context-property name="Boundary-space policy" context-type="static" value="strip"/>
            <context-property name="Ordering mode" context-type="static" value="ordered"/>
            <context-property name="Context item static type" context-type="static" value="item()"/>
            <context-property name="Default element/type namespace" context-type="static" value=""/>
            <context-property name="Default function namespace" context-type="static" value="http://www.w3.org/2005/xpath-functions"/>

            <context-property name="Default collation" context-type="static" value="http://www.w3.org/2005/xpath-functions/collation/codepoint"/>
            <context-property name="Construction mode" context-type="static" value="preserve"/>

            <context-property name="Default order for empty sequences" context-type="static" value="empty greatest"/>

            <context-property name="Copy-namespaces mode" context-type="static" value="inherit preserve"/>

         </context-properties>

       </implementation>

       <syntax>XQuery</syntax>

       <test-run dateRun="2011-01-03">
          <test-suite version="current"/>
          <transformation>
Standard
</transformation>
          <comparison>
Standard
</comparison>
          <otherComments>
XQTS taken from W3C CVS as of 2011-01-03.
</otherComments>
       </test-run>

      {
        for $test in $ctests/*:Site/*:Testing/*:Test
        let $testname := fn:tokenize(fn:data($test/*:Name), "/")[last()]
        return
        if (fn:contains(fn:data($test),'StaticTyping')) then
          <test-case
            name="{$testname}"
            result="not applicable"
            comment="Zorba does not support the 'Static Typing Feature'"
          />
        else
          <test-case
            name="{$testname}"
            result="{fn:substring(fn:data($test/@Status), 0, 5)}"
          />
       }
    </test-suite-result>
  }

(: Schema for results :)
import schema default element namespace "http://www.w3.org/2005/02/query-test-XQTSResult" at "w3c_reportingresults/XQTSResult.xsd";

(: Test.xml file from ctest :)
declare variable $ctests as document-node() external;

if(fn:empty($ctests)) then
  fn:error()
else
  validate {
    <test-suite-result>
       <implementation name="Zorba"
         version='1.5.0 (svn rev. 9658)'
         anonymous-result-column="false">

         <organization
            name='FLWOR Foundation'
            website="http://zorba-xquery.com/"
            anonymous="false" />

         <submittor
            name="Zorba Team"
            email="contact@zorba-xquery.com" />

         <description>

Zorba is a general purpose XQuery processor implementing in C++
            the W3C family of specifications. It is not an XML database.
            The query processor has been designed to be embeddable in a
            variety of environments such as other programming languages
            extended with XML processing capabilities, browsers,
            database servers, XML message dispatchers, or smartphones.
            Its architecture employes a modular design, which allows customizing
            the Zorba query processor to the environment’s needs.
            In particular the architecture of the query processor allows a
            pluggable XML store (e.g. main memory, DOM stores, persistent
            disk-based large stores, S3 stores). Zorba runs on most platforms
            and is available under the Apache license v2. Currently, Zorba
            implements the following W3C specifications: XQuery 1.0, XQuery Update
            Facility 1.0, XQuery Scripting Extension 1.0, and XSLT 2.0 and XQuery 1.0
            Serialization.

         </description>

         <implementation-defined-items>
           <implementation-defined-item
              name="The revalidation modes that are supported by this implementation."
              value="lax, skip, strict" />

          <implementation-defined-item
             name="The default revalidation mode for this implementation."
             value="lax" />

         </implementation-defined-items>

         <features>
            <feature name='Minimum Conformance' supported='true' />
            <feature name='Schema Import' supported='true' />
            <feature name='Schema Validation' supported='true' />
            <feature name='Static Typing' supported='false' />
            <feature name='Static Typing Extensions' supported='false' />
            <feature name='Full Axis' supported='true' />
            <feature name='Module' supported='true' />
            <feature name='Serialization' supported='true' />
         </features>

         <context-properties>
            <context-property name="Boundary-space policy" context-type="static" value="strip"/>
            <context-property name="Ordering mode" context-type="static" value="ordered"/>
            <context-property name="Context item static type" context-type="static" value="item()"/>
            <context-property name="Default element/type namespace" context-type="static" value=""/>
            <context-property name="Default function namespace" context-type="static" value="http://www.w3.org/2005/xpath-functions"/>

            <context-property name="Default collation" context-type="static" value="http://www.w3.org/2005/xpath-functions/collation/codepoint"/>
            <context-property name="Construction mode" context-type="static" value="preserve"/>

            <context-property name="Default order for empty sequences" context-type="static" value="empty greatest"/>

            <context-property name="Copy-namespaces mode" context-type="static" value="inherit preserve"/>

         </context-properties>

       </implementation>

       <syntax>XQuery</syntax>

       <test-run dateRun="2011-01-03">
          <test-suite version="current"/>
          <transformation>
Standard
</transformation>
          <comparison>
Standard
</comparison>
          <otherComments>
XQTS taken from W3C CVS as of 2011-01-03.
</otherComments>
       </test-run>

      {
        for $test in $ctests/*:Site/*:Testing/*:Test
        let $testname := fn:tokenize(fn:data($test/*:Name), "/")[last()]
        return
        if (fn:contains(fn:data($test),'StaticTyping')) then
          <test-case
            name="{$testname}"
            result="not applicable"
            comment="Zorba does not support the 'Static Typing Feature'"
          />
        else if (fn:contains(fn:data($test),'CastFOCA0001-1') or
                 fn:contains(fn:data($test),'CastFOCA0003-1')) then
          <test-case
            name="{$testname}"
            result="pass"
            comment="There is an openened bug #11400 with the W3C for this issue. Please see http://www.w3.org/Bugs/Public/show_bug.cgi?id=11400."
          />
        else
          <test-case
            name="{$testname}"
            result="{fn:substring(fn:data($test/@Status), 0, 5)}"
          />
       }
    </test-suite-result>
  }


[FIX] DBA: check permissions when changing directories

(:~
 : Change directory.
 :
 : @author Christian Grün, BaseX Team 2005-22, BSD License
 :)
module namespace dba = 'dba/files';

import module namespace config = 'dba/config' at '../lib/config.xqm';

(:~ Top category :)
declare variable $dba:CAT := 'files';

(:~
 : Changes the directory.
 : @param  $dir  directory
 : @return redirection
 :)
declare
  %rest:path('/dba/dir-change')
  %rest:query-param('dir', '{$dir}')
function dba:dir-change(
  $dir  as xs:string
) as element(rest:response) {
  try {
    let $sep := file:dir-separator()
    let $path := file:path-to-native(if(contains($dir, $sep)) then (
      $dir
    ) else (
      config:directory() || $dir || $sep)
    )
    return (
      (: ensure that the directory can be accessed :)
      prof:void(file:list($path)),

      config:directory($path),
      config:query('')
    ),
    web:redirect($dba:CAT)
  } catch file:io-error {
    web:redirect($dba:CAT, map { 'error': $err:description })
  }
};

(:~
 : Change directory.
 :
 : @author Christian Grün, BaseX Team 2005-22, BSD License
 :)
module namespace dba = 'dba/files';

import module namespace config = 'dba/config' at '../lib/config.xqm';

(:~ Top category :)
declare variable $dba:CAT := 'files';

(:~
 : Changes the directory.
 : @param  $dir  directory
 : @return redirection
 :)
declare
  %rest:path('/dba/dir-change')
  %rest:query-param('dir', '{$dir}')
function dba:dir-change(
  $dir  as xs:string
) as element(rest:response) {
  config:directory(
    if(contains($dir, file:dir-separator())) then (
      $dir
    ) else (
      file:path-to-native(config:directory() || $dir || '/')
    )
  ),
  config:query(''),
  web:redirect($dba:CAT)
};


[betterform]  fixed JavaScript imports

[betterform]  fixed JavaScript imports

git-svn-id: 1623499149f5af833cfad2814dce82e821210f6f@15419 8784284e-840f-0410-bd5a-a6a6012a0d1a

xquery version "1.0";
declare option exist:serialize "method=xhtml media-type=application/xhtml+html";

let $contextPath := request:get-context-path()
return

        <title>betterFORM Demo XForms: Address, Registration, FeatureExplorer</title>
        <link rel="stylesheet" type="text/css" href="./resources/InlineRoundBordersAlert.css"/>
        <link rel="stylesheet" type="text/css" href="./resources/timetracker.css"/>

                <xf:model id="model-1">
                    <xf:instance>
                        <data xmlns="">
                            <from>2000-01-01</from>
                            <to>2000-01-02</to>
                            <project/>
                            <billable/>
                            <billed/>
                        </data>
                    </xf:instance>
                    <xf:bind nodeset="from" type="xf:date"/>
                    <xf:bind nodeset="to" type="xf:date" />

                    <xf:submission id="s-query-tasks"
                                    resource="{$contextPath}/rest/db/betterform/apps/timetracker/views/list-items.xql"
                                    method="get"
                                    replace="embedHTML"
                                    targetid="embedInline"
                                    ref="instance()"
                                    validate="false">
                        <xf:action ev:event="xforms-submit-error">
                            <xf:message>Submission failed</xf:message>
                        </xf:action>
                    </xf:submission>

                    <xf:submission id="s-delete-task"
                                    method="delete"
                                    replace="none"
                                    validate="false">
                        <xf:resource value="concat('{$contextPath}/rest/db/betterform/apps/timetracker/data/task/',instance('i-vars')/currentTask,'.xml')"/>
                        <xf:header>
                            <xf:name>username</xf:name>
                            <xf:value>admin</xf:value>
                        </xf:header>
                        <xf:header>
                            <xf:name>password</xf:name>
                            <xf:value></xf:value>
                        </xf:header>
                        <xf:header>
                            <xf:name>realm</xf:name>
                            <xf:value>exist</xf:value>
                        </xf:header>

                        <xf:action ev:event="xforms-submit-done">

                            <xf:message level="ephemeral">Entry has been removed</xf:message>
                        </xf:action>
                    </xf:submission>

                    <xf:instance id="i-project" src="{$contextPath}/rest/db/betterform/apps/timetracker/data/project.xml" />

                    <xf:instance id="i-vars">
                        <data xmlns="">
                            <default-duration>120</default-duration>
                            <currentTask/>
                            <selectedTasks/>
                        </data>
                    </xf:instance>
                    <xf:bind nodeset="instance('i-vars')/default-duration" type="xf:integer"/>

                    <xf:submission  id="s-update-billed"
                                    ref="instance('i-vars')/selectedTasks"
                                    method="post"
                                    replace="new"
                                    resource="{$contextPath}/rest/db/betterform/apps/timetracker/reports/timeAndEffort.xql">
                                    <xf:message ev:event="xforms-submit">here it comes...</xf:message>
                    </xf:submission>

                    <xf:action ev:event="xforms-ready">
                        <xf:setvalue ref="to" value="substring(local-date(), 1, 10)"/>
                        <xf:recalculate/>

                        <xf:setvalue ref="from" value="'2010-01-01'"/>
                    </xf:action>

                </xf:model>

                <xf:trigger id="overviewTrigger">
                    <xf:label>Overview</xf:label>
                    <xf:send submission="s-query-tasks"/>
                </xf:trigger>

                <xf:trigger id="addTask">
                    <xf:label>new</xf:label>
                    <xf:action>
                        <xf:load show="embed" targetid="embedDialog">
                            <xf:resource
                                    value="'{$contextPath}/rest/db/betterform/apps/timetracker/edit/edit-item.xql#xforms'"/>
                        </xf:load>
                    </xf:action>
                </xf:trigger>

                <xf:trigger id="editTask">
                    <xf:label>new</xf:label>
                    <xf:action>
                        <xf:load show="embed" targetid="embedDialog">
                            <xf:resource value="concat('{$contextPath}/rest/db/betterform/apps/timetracker/edit/edit-item.xql#xforms?timestamp=',instance('i-vars')/currentTask)"/>
                        </xf:load>
                    </xf:action>
                </xf:trigger>

                <xf:trigger id="deleteTask">
                    <xf:label>delete</xf:label>
                    <xf:send submission="s-delete-task"/>
                </xf:trigger>

                <xf:input id="currentTask" ref="instance('i-vars')/currentTask">
                    <xf:label>This is just a dummy used by JS</xf:label>
                </xf:input>

                <xf:input id="selectedTaskIds" ref="instance('i-vars')/selectedTasks">
                    <xf:label>This is another dummy allowing to pass all selected tasks into an instance</xf:label>
                    <xf:send submission="s-update-billed" ev:event="xforms-value-changed"/>
                </xf:input>

Timetracker

                        Filter

                                        <xf:input ref="from" incremental="true">
                                            <xf:label>from</xf:label>
                                            <xf:action ev:event="xforms-value-changed">
                                                <xf:dispatch name="DOMActivate" targetid="overviewTrigger"/>
                                            </xf:action>
                                        </xf:input>

                                        <xf:input ref="to" incremental="true">
                                            <xf:label>to</xf:label>
                                            <xf:action ev:event="xforms-value-changed">
                                                <xf:dispatch  name="DOMActivate" targetid="overviewTrigger"/>
                                            </xf:action>
                                        </xf:input>

                                        <xf:select1 ref="project" appearance="minimal" incremental="true">
                                            <xf:label>Project</xf:label>
                                            <xf:action ev:event="xforms-value-changed">
                                                <xf:dispatch  name="DOMActivate" targetid="overviewTrigger"/>
                                            </xf:action>
                                            <xf:itemset nodeset="instance('i-project')/*">
                                                <xf:label ref="."/>
                                                <xf:value ref="."/>
                                            </xf:itemset>
                                        </xf:select1>

                                        <xf:select1 ref="billable" appearance="minimal" incremental="true">
                                            <xf:label>Billable</xf:label>
                                            <xf:action ev:event="xforms-value-changed">
                                                <xf:dispatch  name="DOMActivate" targetid="overviewTrigger"/>
                                            </xf:action>
                                            <xf:item>
                                                <xf:label>yes</xf:label>
                                                <xf:value>true</xf:value>
                                            </xf:item>
                                            <xf:item>
                                                <xf:label>no</xf:label>
                                                <xf:value>false</xf:value>
                                            </xf:item>
                                        </xf:select1>

                                        <xf:select1 ref="billed" appearance="minimal" incremental="true">
                                            <xf:label>Billed</xf:label>
                                            <xf:action ev:event="xforms-value-changed">
                                                <xf:dispatch  name="DOMActivate" targetid="overviewTrigger"/>
                                            </xf:action>
                                            <xf:item>
                                                <xf:label>not billed yet</xf:label>
                                                <xf:value>false</xf:value>
                                            </xf:item>
                                            <xf:item>
                                                <xf:label>already billed</xf:label>
                                                <xf:value>true</xf:value>
                                            </xf:item>
                                        </xf:select1>

                                        <xf:trigger id="closeFilter">
                                            <xf:label/>

                                        </xf:trigger>

                        New Task

                        Search

                        Settings

                        About

                    <xf:output value="concat(from,' - ',to)" id="durationLabel">
                        <xf:label/>
                    </xf:output>


Notes on sharing permissions

Notes on sharing permissions

svn path=/trunk/eXist/; revision=12898

xquery version "1.0";

module namespace sharing = "http://exist-db.org/mods/sharing";

import module namespace config = "http://exist-db.org/mods/config" at "config.xqm";
import module namespace security = "http://exist-db.org/mods/security" at "security.xqm";
declare namespace group = "http://exist-db.org/mods/sharing/group";

declare variable $sharing:groups-collection := fn:concat($config:mods-root, "/groups");

declare function sharing:get-groups() as element(group:group)*
{
    fn:collection($sharing:groups-collection)/group:group
};

declare function sharing:group-exists($groupId as xs:string) as xs:boolean
{
    exists(fn:collection($sharing:groups-collection)/group:group[@id eq $groupId])
};

declare function sharing:get-group-members($groupId) as xs:string*
{
        let $group := sharing:__group-id-to-system-group-name($groupId) return
            if($group)then(
                security:get-group-members($group)
            )else()
};

declare function sharing:get-group-id($collection as xs:string) as xs:string?
{
    let $security-group := security:get-group($collection) return
        fn:string(fn:collection($sharing:groups-collection)/group:group[group:system/group:group eq $security-group]/@id)
};

declare function sharing:group-readable($collection as xs:string) as xs:boolean
{
    let $group := security:get-group($collection) return
        if($group)then(
            security:group-can-read-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-readable($collection as xs:string, $groupId as xs:string) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
        if($group)then(
            security:group-can-read-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-writeable($collection as xs:string) as xs:boolean
{
    let $group := security:get-group($collection) return
        if($group)then(
            security:group-can-write-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-writeable($collection as xs:string, $groupId as xs:string) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
        if($group)then(
            security:group-can-write-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:other-readable($collection as xs:string) as xs:boolean
{
    security:other-can-read-collection($collection)
};

declare function sharing:other-writeable($collection as xs:string) as xs:boolean
{
    security:other-can-write-collection($collection)
};

declare function sharing:__group-id-to-system-group-name($groupId as xs:string) as xs:string?
{
    fn:collection($sharing:groups-collection)/group:group[@id eq $groupId]/group:system/group:group
};

declare function sharing:share-with-other($collection as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    security:set-other-can-read-collection($collection, $read)
    and
    security:set-other-can-write-collection($collection, $write)
};

declare function sharing:share-with-group($collection as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    security:set-group-can-read-collection($collection, $read)
    and
    security:set-group-can-write-collection($collection, $write)
};

declare function sharing:share-with-group($collection as xs:string, $groupId as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
    if($group)then
    (
        security:set-group-can-read-collection($collection, $group, $read)
        and
        security:set-group-can-write-collection($collection, $group, $write)
    )
    else
    (
        false()
    )
};

declare function sharing:is-group-owner($group-id as xs:string, $user as xs:string) as xs:boolean
{
    exists(sharing:get-group($group-id)/group:system[group:owner eq $user])
};

declare function sharing:create-group($group-name as xs:string, $owner as xs:string, $group-member as xs:string*) as xs:string?
{
    let $new-group-id := util:uuid(),
    $system-group-name :=  fn:concat($owner, ".", fn:lower-case(fn:replace($group-name, "[^a-zA-Z0-9]", ""))) return

        if(security:create-group($system-group-name, $group-member))then
        (
            let $group-doc := xmldb:store($sharing:groups-collection, (),
                <group:group id="{$new-group-id}">
                    <group:system>
                        <group:owner>{$owner}</group:owner>
                        <group:group>{$system-group-name}</group:group>
                    </group:system>
                    <group:name>{$group-name}</group:name>
                </group:group>
            ) return
                 (: NOTE -
                    using $system-group-name means that users can only share with groups of which they are already a member
                    otherwise $security:biblio-users-group could be used, allowing a user to share with any existing group (whether they are a member of that group or not!)
                 :)
                 security:set-resource-permissions($group-doc, $owner, $system-group-name, true(), true(), true(), false(), false(), false()),
                 $new-group-id
        )
        else()
};

declare function sharing:get-users-groups($user as xs:string) as element(group:group)*
{
    fn:collection($sharing:groups-collection)/group:group[group:system/group:group = security:get-groups($user)]
};

declare function sharing:get-group($group-id as xs:string) as element(group:group)? {
    fn:collection($sharing:groups-collection)/group:group[@id eq $group-id]
};

xquery version "1.0";

module namespace sharing = "http://exist-db.org/mods/sharing";

import module namespace config = "http://exist-db.org/mods/config" at "config.xqm";
import module namespace security = "http://exist-db.org/mods/security" at "security.xqm";
declare namespace group = "http://exist-db.org/mods/sharing/group";

declare variable $sharing:groups-collection := fn:concat($config:mods-root, "/groups");

declare function sharing:get-groups() as element(group:group)*
{
    fn:collection($sharing:groups-collection)/group:group
};

declare function sharing:group-exists($groupId as xs:string) as xs:boolean
{
    exists(fn:collection($sharing:groups-collection)/group:group[@id eq $groupId])
};

declare function sharing:get-group-members($groupId) as xs:string*
{
        let $group := sharing:__group-id-to-system-group-name($groupId) return
            if($group)then(
                security:get-group-members($group)
            )else()
};

declare function sharing:get-group-id($collection as xs:string) as xs:string?
{
    let $security-group := security:get-group($collection) return
        fn:string(fn:collection($sharing:groups-collection)/group:group[group:system/group:group eq $security-group]/@id)
};

declare function sharing:group-readable($collection as xs:string) as xs:boolean
{
    let $group := security:get-group($collection) return
        if($group)then(
            security:group-can-read-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-readable($collection as xs:string, $groupId as xs:string) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
        if($group)then(
            security:group-can-read-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-writeable($collection as xs:string) as xs:boolean
{
    let $group := security:get-group($collection) return
        if($group)then(
            security:group-can-write-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:group-writeable($collection as xs:string, $groupId as xs:string) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
        if($group)then(
            security:group-can-write-collection($group, $collection)
        ) else (
            false()
        )
};

declare function sharing:other-readable($collection as xs:string) as xs:boolean
{
    security:other-can-read-collection($collection)
};

declare function sharing:other-writeable($collection as xs:string) as xs:boolean
{
    security:other-can-write-collection($collection)
};

declare function sharing:__group-id-to-system-group-name($groupId as xs:string) as xs:string?
{
    fn:collection($sharing:groups-collection)/group:group[@id eq $groupId]/group:system/group:group
};

declare function sharing:share-with-other($collection as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    security:set-other-can-read-collection($collection, $read)
    and
    security:set-other-can-write-collection($collection, $write)
};

declare function sharing:share-with-group($collection as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    security:set-group-can-read-collection($collection, $read)
    and
    security:set-group-can-write-collection($collection, $write)
};

declare function sharing:share-with-group($collection as xs:string, $groupId as xs:string, $read as xs:boolean, $write as xs:boolean) as xs:boolean
{
    let $group := sharing:__group-id-to-system-group-name($groupId) return
    if($group)then
    (
        security:set-group-can-read-collection($collection, $group, $read)
        and
        security:set-group-can-write-collection($collection, $group, $write)
    )
    else
    (
        false()
    )
};

declare function sharing:is-group-owner($group-id as xs:string, $user as xs:string) as xs:boolean
{
    exists(sharing:get-group($group-id)/group:system[group:owner eq $user])
};

declare function sharing:create-group($group-name as xs:string, $owner as xs:string, $group-member as xs:string*) as xs:string?
{
    let $new-group-id := util:uuid(),
    $system-group-name :=  fn:concat($owner, ".", fn:lower-case(fn:replace($group-name, "[^a-zA-Z0-9]", ""))) return

        if(security:create-group($system-group-name, $group-member))then
        (
            let $group-doc := xmldb:store($sharing:groups-collection, (),
                <group:group id="{$new-group-id}">
                    <group:system>
                        <group:owner>{$owner}</group:owner>
                        <group:group>{$system-group-name}</group:group>
                    </group:system>
                    <group:name>{$group-name}</group:name>
                </group:group>
            ) return
                 security:set-resource-permissions($group-doc, $owner, $system-group-name, true(), true(), true(), false(), false(), false()),
                 $new-group-id
        )
        else()
};

declare function sharing:get-users-groups($user as xs:string) as element(group:group)*
{
    fn:collection($sharing:groups-collection)/group:group[group:system/group:group = security:get-groups($user)]
};

declare function sharing:get-group($group-id as xs:string) as element(group:group)? {
    fn:collection($sharing:groups-collection)/group:group[@id eq $group-id]
};


Fixed collectresults.xql to output the correct default namespace

svn path=/trunk/eXist-1.0/; revision=4464

declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace empty="";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename="results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml"" ) )

let $cases := fn:collection(  '/db/XQTS' )//test-case
return
<test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult">
        <implementation name="eXist-{$product-version}" version="{$product-build}" anonymous-result-column="false">

                <organization name="eXist Open Source native XML database"  website="http://www.exist-db.org" anonymous="false"/>

                <submittor name="eXist XQTS testsuite runner" email="xqts@exist-db.org"/>

                <description>

eXist is an Open Source native XML database featuring efficient,
                        index-based XQuery processing, automatic indexing, extensions for full-text
                        search,  XUpdate  support and tight integration with existing XML development tools.

                </description>

                <implementation-defined-items>

                </implementation-defined-items>

                <features>

                <feature name="Minimal Conformance" supported="true"/>
                <feature name="Schema Import" supported="false"/>
                <feature name="Schema Validation" supported="false"/>
                <feature name="Static Typing" supported="false"/>
                <feature name="Static Typing Extensions" supported="false"/>
                <feature name="Full Axis" supported="true"/>
                <feature name="Module" supported="true"/>
                <feature name="Serialization" supported="true"/>
                <feature name="Trivial XML Embedding" supported="false"/>
						  </features>

                <context-properties>

                </context-properties>

        </implementation>

        <syntax>XQuery</syntax>

        <test-run dateRun="{fn:current-dateTime()}">
                <test-suite version="{$test-suite}"/>
                <transformation>

No unusual transformations.

                </transformation>
                <comparison>

No unusual comparisons

                </comparison>
                <otherComments>

The test run took n seconds.

                </otherComments>
        </test-run>

{
		(: for $case in fn:collection(  '/db/XQTS' )//*:test-case :)
    for $case in $cases
    order by $case/@name
    return <test-case name="{$case/@name}" result="{$case/@result}" />
}
</test-suite-result>

(: declare default element namespace "http://www.w3.org/2005/02/query-test-XQTSResult"; :)
declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename="results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml"" ) )

return
<test-suite-result>
        <implementation name="eXist-{$product-version}" version="{$product-build}" anonymous-result-column="false">

                <organization name="eXist Open Source native XML database"  website="http://www.exist-db.org" anonymous="false"/>

                <submittor name="eXist XQTS testsuite runner" email="xqts@exist-db.org"/>

                <description>

eXist is an Open Source native XML database featuring efficient,
                        index-based XQuery processing, automatic indexing, extensions for full-text
                        search,  XUpdate  support and tight integration with existing XML development tools.

                </description>

                <implementation-defined-items>

                </implementation-defined-items>

                <features>

                <feature name="Minimal Conformance" supported="true"/>
                <feature name="Schema Import" supported="false"/>
                <feature name="Schema Validation" supported="false"/>
                <feature name="Static Typing" supported="false"/>
                <feature name="Static Typing Extensions" supported="false"/>
                <feature name="Full Axis" supported="true"/>
                <feature name="Module" supported="true"/>
                <feature name="Serialization" supported="true"/>
                <feature name="Trivial XML Embedding" supported="false"/>
						  </features>

                <context-properties>

                </context-properties>

        </implementation>

        <syntax>XQuery</syntax>

        <test-run dateRun="{fn:current-dateTime()}">
                <test-suite version="{$test-suite}"/>
                <transformation>

No unusual transformations.

                </transformation>
                <comparison>

No unusual comparisons

                </comparison>
                <otherComments>

The test run took n seconds.

                </otherComments>
        </test-run>

{
		(: for $case in fn:collection(  '/db/XQTS' )//*:test-case :)
    for $case in fn:collection(  '/db/XQTS' )//test-case
    order by $case/@name
    return <test-case name="{$case/@name}" result="{$case/@result}" />
}
</test-suite-result>


added complex diacrit test-case ... reactivated test-teardown

xquery version "3.0";

module namespace analyze="http://exist-db.org/xquery/lucene/test/analyzers";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $analyze:XCONF1 :=
    <collection xmlns="http://exist-db.org/collection-config/1.0">
        <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <lucene diacritics="no">
                <parser class="org.apache.lucene.queryparser.analyzing.AnalyzingQueryParser"/>
                <text qname="p"/>
            </lucene>
        </index>
        <triggers>
            <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
        </triggers>
    </collection>;

declare variable $analyze:XCONF2 :=
    <collection xmlns="http://exist-db.org/collection-config/1.0">
        <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <lucene diacritics="yes">
                <text qname="p"/>
            </lucene>
        </index>
        <triggers>
            <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
        </triggers>
    </collection>;

declare
    %test:setUp
function analyze:setup() {
    let $testCol := xmldb:create-collection("/db", "lucenetest")
    let $testCol1 := xmldb:create-collection("/db/lucenetest", "test1")
    let $testCol2 := xmldb:create-collection("/db/lucenetest", "test2")
    let $confCol := xmldb:create-collection("/db/system/config/db", "lucenetest")
    let $confCol1 := xmldb:create-collection("/db/system/config/db/lucenetest", "test1")
    let $confCol2 := xmldb:create-collection("/db/system/config/db/lucenetest", "test2")
    return (
        xmldb:store($confCol1, "collection.xconf", $analyze:XCONF1),
        xmldb:store($testCol1, "test.xml",
            <test>

Rüsselsheim

Russelsheim

Māori

Maori

ܦܘܼܪܫܵܢܵܐ

ܦܘܽܪܫܳܢܳܐ

ܦܘܪܫܢܐ

פָּעַל

פעל

بَردَيصان

برديصان

nǚ

nü

nu

zìyóu

ziyou

            </test>
        ),
        xmldb:store($confCol2, "collection.xconf", $analyze:XCONF2),
        xmldb:store($testCol2, "test.xml",
            <test>

Rüsselsheim

Russelsheim

Māori

Maori

ܦܘܼܪܫܵܢܵܐ

ܦܘܽܪܫܳܢܳܐ

ܦܘܪܫܢܐ

פָּעַל

פעל

بَردَيصان

برديصان

nǚ

nü

nu

zìyóu

ziyou

            </test>
        )
    )
};

declare
    %test:args("russelsheim")
    %test:assertEquals(2)
    %test:args("rüsselsheim")
    %test:assertEquals(2)
    %test:args("maori")
    %test:assertEquals(2)
    %test:args("Māori")
    %test:assertEquals(2)
    %test:args("ܦܘܼܪܫܵܢܵܐ")
    %test:assertEquals(3)
    %test:args("ܦܘܽܪܫܳܢܳܐ")
    %test:assertEquals(3)
    %test:args("ܦܘܪܫܢܐ")
    %test:assertEquals(3)
    %test:args("פָּעַל")
    %test:assertEquals(2)
    %test:args("פעל")
    %test:assertEquals(2)
    %test:args("بَردَيصان")
    %test:assertEquals(2)
    %test:args("برديصان")
    %test:assertEquals(2)
    %test:args("nǚ")
    %test:assertEquals(3)
    %test:args("nü")
    %test:assertEquals(3)
    %test:args("nu")
    %test:assertEquals(3)
    %test:args("zìyóu")
    %test:assertEquals(2)
    %test:args("ziyou")
    %test:assertEquals(2)
function analyze:no-diacrictics($term as xs:string) {
    count(collection("/db/lucenetest/test1")//p[ft:query(., $term)])
};

declare
    %test:args("russelsheim")
    %test:assertEquals(1)
    %test:args("rüsselsheim")
    %test:assertEquals(1)
    %test:args("maori")
    %test:assertEquals(1)
    %test:args("Māori")
    %test:assertEquals(1)
    %test:args("ܦܘܼܪܫܵܢܵܐ")
    %test:assertEquals(1)
    %test:args("ܦܘܽܪܫܳܢܳܐ")
    %test:assertEquals(1)
    %test:args("ܦܘܪܫܢܐ")
    %test:assertEquals(1)
    %test:args("פָּעַל")
    %test:assertEquals(1)
    %test:args("פעל")
    %test:assertEquals(1)
    %test:args("بَردَيصان")
    %test:assertEquals(1)
    %test:args("برديصان")
    %test:assertEquals(1)
    %test:args("nu")
    %test:assertEquals(1)
    %test:args("nü")
    %test:assertEquals(1)
    %test:args("nǚ")
    %test:assertEquals(1)
    %test:args("ziyou")
    %test:assertEquals(1)
    %test:args("zìyóu")
    %test:assertEquals(1)
function analyze:diacrictics($term as xs:string) {
    count(collection("/db/lucenetest/test2")//p[ft:query(., $term)])
};

declare
    %test:args("rüssels*")
    %test:assertEquals(2)
    %test:args("russels*")
    %test:assertEquals(2)
    %test:args("maor*")
    %test:assertEquals(2)
    %test:args("Māor*")
    %test:assertEquals(2)
    %test:args("ܦܘܪ*")
    %test:assertEquals(3)
    %test:args("פע*")
    %test:assertEquals(2)
    %test:args("بردي*")
    %test:assertEquals(2)
    %test:args("ziy*")
    %test:assertEquals(2)
    %test:args("n*")
    %test:assertEquals(3)
function analyze:query-parser($term as xs:string) {
    count(collection("/db/lucenetest/test1")//p[ft:query(., $term)])
};

declare
    %test:tearDown
function analyze:tearDown() {
    xmldb:remove("/db/lucenetest"),
    xmldb:remove("/db/system/config/db/lucenetest")
};

xquery version "3.0";

module namespace analyze="http://exist-db.org/xquery/lucene/test/analyzers";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare variable $analyze:XCONF1 :=
    <collection xmlns="http://exist-db.org/collection-config/1.0">
        <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <lucene diacritics="no">
                <parser class="org.apache.lucene.queryparser.analyzing.AnalyzingQueryParser"/>
                <text qname="p"/>
            </lucene>
        </index>
        <triggers>
            <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
        </triggers>
    </collection>;

declare variable $analyze:XCONF2 :=
    <collection xmlns="http://exist-db.org/collection-config/1.0">
        <index xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <lucene diacritics="yes">
                <text qname="p"/>
            </lucene>
        </index>
        <triggers>
            <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
        </triggers>
    </collection>;

declare
    %test:setUp
function analyze:setup() {
    let $testCol := xmldb:create-collection("/db", "lucenetest")
    let $testCol1 := xmldb:create-collection("/db/lucenetest", "test1")
    let $testCol2 := xmldb:create-collection("/db/lucenetest", "test2")
    let $confCol := xmldb:create-collection("/db/system/config/db", "lucenetest")
    let $confCol1 := xmldb:create-collection("/db/system/config/db/lucenetest", "test1")
    let $confCol2 := xmldb:create-collection("/db/system/config/db/lucenetest", "test2")
    return (
        xmldb:store($confCol1, "collection.xconf", $analyze:XCONF1),
        xmldb:store($testCol1, "test.xml",
            <test>

Rüsselsheim

Russelsheim

Māori

Maori

ܦܘܼܪܫܵܢܵܐ

ܦܘܽܪܫܳܢܳܐ

ܦܘܪܫܢܐ

פָּעַל

פעל

بَردَيصان

برديصان

nǚ

nu

zìyóu

ziyou

            </test>
        ),
        xmldb:store($confCol2, "collection.xconf", $analyze:XCONF2),
        xmldb:store($testCol2, "test.xml",
            <test>

Rüsselsheim

Russelsheim

Māori

Maori

ܦܘܼܪܫܵܢܵܐ

ܦܘܽܪܫܳܢܳܐ

ܦܘܪܫܢܐ

פָּעַל

פעל

بَردَيصان

برديصان

nǚ

nu

zìyóu

ziyou

            </test>
        )
    )
};

(:declare :)
(:    %test:tearDown:)
(:function analyze:tearDown() {:)
(:    xmldb:remove("/db/lucenetest"),:)
(:    xmldb:remove("/db/system/config/db/lucenetest"):)
(:};:)

declare
    %test:args("russelsheim")
    %test:assertEquals(2)
    %test:args("rüsselsheim")
    %test:assertEquals(2)
    %test:args("maori")
    %test:assertEquals(2)
    %test:args("Māori")
    %test:assertEquals(2)
    %test:args("ܦܘܼܪܫܵܢܵܐ")
    %test:assertEquals(3)
    %test:args("ܦܘܽܪܫܳܢܳܐ")
    %test:assertEquals(3)
    %test:args("ܦܘܪܫܢܐ")
    %test:assertEquals(3)
    %test:args("פָּעַל")
    %test:assertEquals(2)
    %test:args("פעל")
    %test:assertEquals(2)
    %test:args("بَردَيصان")
    %test:assertEquals(2)
    %test:args("برديصان")
    %test:assertEquals(2)
    %test:args("nǚ")
    %test:assertEquals(2)
    %test:args("nu")
    %test:assertEquals(2)
    %test:args("zìyóu")
    %test:assertEquals(2)
    %test:args("ziyou")
    %test:assertEquals(2)
function analyze:no-diacrictics($term as xs:string) {
    count(collection("/db/lucenetest/test1")//p[ft:query(., $term)])
};

declare
    %test:args("russelsheim")
    %test:assertEquals(1)
    %test:args("rüsselsheim")
    %test:assertEquals(1)
    %test:args("maori")
    %test:assertEquals(1)
    %test:args("Māori")
    %test:assertEquals(1)
    %test:args("ܦܘܼܪܫܵܢܵܐ")
    %test:assertEquals(1)
    %test:args("ܦܘܽܪܫܳܢܳܐ")
    %test:assertEquals(1)
    %test:args("ܦܘܪܫܢܐ")
    %test:assertEquals(1)
    %test:args("פָּעַל")
    %test:assertEquals(1)
    %test:args("פעל")
    %test:assertEquals(1)
    %test:args("بَردَيصان")
    %test:assertEquals(1)
    %test:args("برديصان")
    %test:assertEquals(1)
    %test:args("nǚ")
    %test:assertEquals(1)
    %test:args("nu")
    %test:assertEquals(1)
    %test:args("zìyóu")
    %test:assertEquals(1)
    %test:args("ziyou")
    %test:assertEquals(1)
function analyze:diacrictics($term as xs:string) {
    count(collection("/db/lucenetest/test2")//p[ft:query(., $term)])
};

declare
    %test:args("rüssels*")
    %test:assertEquals(2)
    %test:args("russels*")
    %test:assertEquals(2)
    %test:args("maor*")
    %test:assertEquals(2)
    %test:args("Māor*")
    %test:assertEquals(2)
    %test:args("ܦܘܪ*")
    %test:assertEquals(3)
    %test:args("פע*")
    %test:assertEquals(2)
    %test:args("بردي*")
    %test:assertEquals(2)
function analyze:query-parser($term as xs:string) {
    count(collection("/db/lucenetest/test1")//p[ft:query(., $term)])
};