Created static reference to Quotation identifier as it's now used elsewhere.

module namespace notes="http://cefn.com/readinglog/notes";

import module namespace template="http://cefn.com/readinglog/template" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/template.xq";

declare namespace ann = "http://www.zorba-xquery.com/annotations";

declare default element namespace "http://www.w3.org/1999/xhtml";

declare variable $notes:authors := "Authors";
declare variable $notes:concepts := "Concepts";
declare variable $notes:quotations := "Quotations";
declare variable $notes:headings := (
	$notes:authors,
	$notes:concepts,
	'Methodology',
	'Field of Study',
	'Quotations',
	'References'
);
declare variable $notes:errorlink := '/error';

(: Introspects the noted document's unique id from any doc or contained note node :)
(: TODO CH this should be generalised to permit URLs and ISBNs to be listed.
 Powells books seems a promising way to link to ISBNs e.g. http://www.powells.com/biblio/9781449342685
 though amazon may be able to do something similar with 10 digit ISBNs
 there is a visually identical unicode character to the forward slash with Unicode 0x2044 (fraction slash)
 :)
declare function notes:paperid($node){
	replace(base-uri(notes:paperroot($node)),".*/([^/]+)\.[^/]+$", "$1")
};

declare function notes:papertitle($node){
	notes:paperroot($node)//h1/string(.)
};

declare function notes:paperroot($node){
	typeswitch($node)
		case document-node() return $node
		default return root($node)
};

declare %ann:nondeterministic function notes:allnotes(){
	template:loadhtml("public/notes/")
};

declare %ann:nondeterministic function notes:notesoftype($type){
	notes:filterbytype(notes:allnotes()//*,$type)
};

declare function notes:filterbytype($nodes,$type){
	$nodes[not(self::h2)][not(self::br)][preceding::h2[1]//text()[contains(.,$type)]][not(normalize-space(string(.))='')]
};

declare function notes:gettype($node){
	if($node/ancestor::h1) then
			'Titles'
		else
			normalize-space(string-join($node/(preceding::h2[1])/text(),""))
};

declare function notes:followingheader($nodes,$title){
	$nodes//*[preceding-sibling::h2[1][text()[normalize-space(.)=$title]]]
};

(: Returns the type of a given item, either 'pdf', 'book' or 'url' :)
declare function notes:sourcetype($item){
	let $id := notes:paperid($item)
	return
		if(starts-with($id,'isbn-')) then
			'book'
		else if(starts-with($id, 'http://')) then
			'url'
		else
			'pdf'
};

(: Accepts either hash values or nodes from within the noted paper :)
declare function notes:paperlinks($item){
	let $id := 	if($item instance of xs:string) then
						$item
					else
						notes:paperid($item),
		$source := notes:sourcetype($item),
		$link := switch ($source)
					case 'book'	return concat('http://www.powells.com/biblio/', replace($id,'(isbn|-)',''))
					case 'url'	return $id
					case 'pdf' return concat('papers/',$id,'.pdf')
					default return $notes:errorlink
	return

			[{$source} notes]

};

(: Indicates a priority order for individual note types e.g. in search results:)
declare function notes:typepriority($type){
	let $priorities := ('Titles','Notes','Concepts','Quotations'),
		$matches := index-of(reverse($priorities),$type)
	return if(count($matches)) then $matches[1] else 0
};

module namespace notes="http://cefn.com/readinglog/notes";

import module namespace template="http://cefn.com/readinglog/template" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/template.xq";

declare namespace ann = "http://www.zorba-xquery.com/annotations";

declare default element namespace "http://www.w3.org/1999/xhtml";

declare variable $notes:authors := "Authors";
declare variable $notes:concepts := "Concepts";
declare variable $notes:headings := (
	$notes:authors,
	$notes:concepts,
	'Methodology',
	'Field of Study',
	'Quotations',
	'References'
);
declare variable $notes:errorlink := '/error';

(: Introspects the noted document's unique id from any doc or contained note node :)
(: TODO CH this should be generalised to permit URLs and ISBNs to be listed.
 Powells books seems a promising way to link to ISBNs e.g. http://www.powells.com/biblio/9781449342685
 though amazon may be able to do something similar with 10 digit ISBNs
 there is a visually identical unicode character to the forward slash with Unicode 0x2044 (fraction slash)
 :)
declare function notes:paperid($node){
	replace(base-uri(notes:paperroot($node)),".*/([^/]+)\.[^/]+$", "$1")
};

declare function notes:papertitle($node){
	notes:paperroot($node)//h1/string(.)
};

declare function notes:paperroot($node){
	typeswitch($node)
		case document-node() return $node
		default return root($node)
};

declare %ann:nondeterministic function notes:allnotes(){
	template:loadhtml("public/notes/")
};

declare %ann:nondeterministic function notes:notesoftype($type){
	notes:filterbytype(notes:allnotes()//*,$type)
};

declare function notes:filterbytype($nodes,$type){
	$nodes[not(self::h2)][not(self::br)][preceding::h2[1]//text()[contains(.,$type)]][not(normalize-space(string(.))='')]
};

declare function notes:gettype($node){
	if($node/ancestor::h1) then
			'Titles'
		else
			normalize-space(string-join($node/(preceding::h2[1])/text(),""))
};

declare function notes:followingheader($nodes,$title){
	$nodes//*[preceding-sibling::h2[1][text()[normalize-space(.)=$title]]]
};

(: Returns the type of a given item, either 'pdf', 'book' or 'url' :)
declare function notes:sourcetype($item){
	let $id := notes:paperid($item)
	return
		if(starts-with($id,'isbn-')) then
			'book'
		else if(starts-with($id, 'http://')) then
			'url'
		else
			'pdf'
};

(: Accepts either hash values or nodes from within the noted paper :)
declare function notes:paperlinks($item){
	let $id := 	if($item instance of xs:string) then
						$item
					else
						notes:paperid($item),
		$source := notes:sourcetype($item),
		$link := switch ($source)
					case 'book'	return concat('http://www.powells.com/biblio/', replace($id,'(isbn|-)',''))
					case 'url'	return $id
					case 'pdf' return concat('papers/',$id,'.pdf')
					default return $notes:errorlink
	return

			[{$source} notes]

};

(: Indicates a priority order for individual note types e.g. in search results:)
declare function notes:typepriority($type){
	let $priorities := ('Titles','Notes','Concepts','Quotations'),
		$matches := index-of(reverse($priorities),$type)
	return if(count($matches)) then $matches[1] else 0
};


@class and @type

@class and @type

declare variable $pos := //parts-of-speech;

declare function local:pos($t)
{
  let $description :=  string($pos/value[@tag = $t/@part-of-speech]/@summary)
  let $class :=
    switch ($description)
      case "interrogative adverb" return "adverb"
      case "relative adverb" return "adverb"
      case "common noun" return "noun"
      case "proper noun" return "noun"
      case "cardinal numeral" return "numeral"
      case "ordinal numeral" return "numeral"
      case "demonstrative pronoun" return "pronoun"
      case "indefinite pronoun" return "pronoun"
      case "interrogative pronoun" return "pronoun"
      case "relative pronoun" return "pronoun"
      case "personal pronoun" return "pronoun"
      case "personal reflexive pronoun" return "pronoun"
      case "possessive pronoun" return "pronoun"
      case "possessive reflexive pronoun" return "pronoun"
      case "reciprocal pronoun" return "pronoun"
      case "" return ()
      default return $description
  let $type :=
    switch ($description)
      case "interrogative adverb" return "interrogative"
      case "relative adverb" return "relative"
      case "common noun" return "common"
      case "proper noun" return "proper"
      case "cardinal numeral" return "cardinal"
      case "ordinal numeral" return "ordinal"
      case "demonstrative pronoun" return "demonstrative"
      case "indefinite pronoun" return "indefinite"
      case "interrogative pronoun" return "interrogative"
      case "relative pronoun" return "relative"
      case "personal pronoun" return "personal"
      case "personal reflexive pronoun" return "personal relative"
      case "possessive pronoun" return "possessive"
      case "possessive reflexive pronoun" return "possessive reflexive"
      case "reciprocal pronoun" return "reciprocal"
      default return ()
  return
    (
      $class ! attribute class {$class},
      $type ! attribute type {$type}
    )
};

declare function local:token($t)
{
  <w>
    {
      local:pos($t),
      attribute role {$t/@relation},
      attribute id {$t/@id},
      $t/@head-id ! attribute head-id {$t/@head-id }
    }
    {
      string($t/@form)
    }
  </w>,
  $t/@presentation-after[. != ' '] ! <pc>{string(.)}</pc>
};

declare function local:unwrap($t, $stok)
{
  let $children :=  $stok[@head-id = $t/@id]
  let $seq := ($children | $t)/.
  return
    if ($children)
    then
      <wg role="{$t/@relation}">
        {
          for $s in $seq
          return
            if ($s is $t)
            then local:token($t)
            else local:unwrap($s, $stok)
        }
      </wg>
    else local:token($t)
};

declare function local:sentence($s)
{
  <sentence>
    {
      attribute id { $s/@id }
    }
    {
      let $stok := $s//token
      for $t in $stok[not(@head-id)]
      return local:unwrap($t, $stok)
    }
  </sentence>
};

<?xml-stylesheet href="treedown.css"?>,
<?xml-stylesheet href="boxwood.css"?>,
<book>
  {
    for $s in //sentence
    return local:sentence($s)
  }
</book>

declare function local:token($t)
{
  <w>
    {
      attribute role {$t/@relation},
      attribute id {$t/@id},
      attribute head-id {$t/@head-id }
    }
    {
      string($t/@form)
    }
  </w>,
  $t/@presentation-after[. != ' '] ! <pc>{string(.)}</pc>
};

declare function local:unwrap($t, $stok)
{
  let $children :=  $stok[@head-id = $t/@id]
  let $seq := ($children | $t)/.
  return
    if ($children)
    then
      <wg role="{$t/@relation}">
        {
          for $s in $seq
          return
            if ($s is $t)
            then local:token($t)
            else local:unwrap($s, $stok)
        }
      </wg>
    else local:token($t)
};

declare function local:sentence($s)
{
  <sentence>
    {
      attribute id { $s/@id }
    }
    {
      let $stok := $s//token
      for $t in $stok[not(@head-id)]
      return local:unwrap($t, $stok)
    }
  </sentence>
};

<?xml-stylesheet href="treedown.css"?>,
<?xml-stylesheet href="boxwood.css"?>,
<book>
  {
    for $s in //sentence
    return local:sentence($s)
  }
</book>


Declared the geometry prefix.

Declared the geometry prefix.

(:*******************************************************:)
(: Test: mainModule16.xq                                 :)
(: Written By: Sorin Nasoi                               :)
(: Date: 2008/05/26                                      :)
(: Purpose: Error XQST0036                               :)
(:*******************************************************:)

import module namespace math = "http://example.org/math-functions" at
"libraryModule12.xqlib";

declare namespace geometry = "http://www.zorba-xquery.com/schema/test/triangle_schema";

<result>{math:area(geometry:triangle("Right"))}</result>


[ignore] First step to make html admin client using new xquery3 expressions. Step one: use the switch statement in stead of the long if then else if then else if then construction.
Made menu invisible when user is not logged in

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

xquery version "3.0";
(:
    $Id$

    Main module of the database administration interface.
:)

declare namespace admin = "http://exist-db.org/xquery/admin-interface";

declare namespace request = "http://exist-db.org/xquery/request";
declare namespace session = "http://exist-db.org/xquery/session";
declare namespace util = "http://exist-db.org/xquery/util";
declare namespace xdb = "http://exist-db.org/xquery/xmldb";

import module namespace status = "http://exist-db.org/xquery/admin-interface/status" at "status.xqm";
import module namespace browse = "http://exist-db.org/xquery/admin-interface/browse" at "browse.xqm";
import module namespace users = "http://exist-db.org/xquery/admin-interface/users" at "users.xqm";
import module namespace xqueries = "http://exist-db.org/xquery/admin-interface/xqueries" at "xqueries.xqm";
import module namespace shut = "http://exist-db.org/xquery/admin-interface/shutdown" at "shutdown.xqm";
import module namespace setup = "http://exist-db.org/xquery/admin-interface/setup" at "setup.xqm";
import module namespace rev="http://exist-db.org/xquery/admin-interface/revisions" at "versions.xqm";
import module namespace backup="http://exist-db.org/xquery/admin-interface/backup" at "backup.xqm";
import module namespace prof="http://exist-db.org/xquery/profiling" at "trace.xqm";
import module namespace grammar="http://exist-db.org/xquery/admin-interface/grammar" at "grammar.xqm";
import module namespace install="http://exist-db.org/xquery/install-tools" at "install.xqm";
import module namespace fundocs="http://exist-db.org/xquery/admin/fundocs" at "fundocs.xqm";
import module namespace repomanager="http://exist-db.org/xquery/admin-interface/repo" at "repo.xqm";
import module namespace indexes="http://exist-db.org/xquery/admin-interface/indexes" at "indexes.xqm";

declare option exist:serialize "method=xhtml media-type=text/html";

(:
    Display the version, SVN revision and user info in the top right corner
:)
declare function admin:info-header() as element()
{

Version: { util:system-property( "product-version" ) }

SVN Revision: { util:system-property( "svn-revision" ) }

Build: {util:system-property("product-build")}

User: { xdb:get-current-user() }

};

(:
    Display the menu on left side
:)
declare function admin:menu-panel() as element()
{
    let $link := session:encode-url(request:get-uri())
    return

Select a Page

Browse

Collections

Indexes

Install

Documentation

Examples

System

Shutdown

Status

Tooling

Backups

Package Repository

Query Profiling

User Management

View

Grammar cache

Running Jobs

Home

Logout

};

(:
    Select the page to show. Every page is defined in its own module
:)
declare function admin:panel() as element()
{
    let $panel := request:get-parameter("panel", "status")[1] return
        switch ($panel)
            case "browse"    return  browse:main()
            case "users"     return  users:main()
            case "xqueries"  return  xqueries:main()
            case "shutdown"  return  shut:main()
            case "setup"     return  setup:main()
            case "fundocs"   return  fundocs:main()
    		case "repo"      return  repomanager:main()
    		case "revisions" return  rev:main()
    		case "backup"    return  backup:main()
    	    case "trace"     return  prof:main()
            case "grammar"   return  grammar:main()
            case "install"   return  install:main()
            case "indexes"   return  indexes:main()
            default          return  status:main()
};

declare function admin:panel-header() {
    let $panel := request:get-parameter("panel", "status")[1]
    return
        if ($panel[1] eq "install") then
            install:header()
        else
            <xf:model xmlns:xf="http://www.w3.org/2002/xforms">
            </xf:model>
};

(:~
    Display the login form.
:)
declare function admin:display-login-form() as element()
{

Login

This is a protected resource. Only registered database users can log
        in. If you have not set up any users, login as "admin" and leave the
        password field empty. Note that the "guest" user is not permitted access.

        <form action="{session:encode-url(request:get-uri())}" method="post">

                    Please Login

                    Username:
                    <input name="user" type="text" size="20"/>

                    Password:
                    <input name="pass" type="password" size="20"/>

                    <input type="submit" value="Login"/>

            {
                for $param in request:get-parameter-names()
                return
                    <input type="hidden" name="{$param}"
                        value="{request:get-parameter($param, ())}"/>
            }
        </form>

};

(: main entry point :)
let $userParam := request:get-parameter("user", ())[1]
let $passwdParam := request:get-parameter("pass", ())[1]
let $isLoggedIn :=  if(xdb:get-current-user() eq "guest") then
    (
        (: is this a login attempt? :)
        if($userParam and not(empty($passwdParam)))then
        (
            if($userParam = ("", "guest") )then
            (
                (: prevent the guest user from accessing the admin webapp :)
                false()
            )
            else
            (
                (: try and log the user in :)
                xdb:login( "/db", $userParam, $passwdParam, true() )
            )
        )
        else
        (
            (: prevent the guest user from accessing the admin webapp :)
            false()
        )
    )
    else
    (
        (: if we are already logged in, are we logging out - i.e. set permissions back to guest :)
        if(request:get-parameter("logout",()))then
        (
        	let $null  := xdb:login("/db", "guest", "guest")
            let $inval := session:invalidate()

            return false()
        )
        else
        (
             (: we are already logged in and we are not the guest user :)
            true()
        )
    )
return (
    <?css-conversion no?>,

            <title>eXist Database Administration</title>
            <link type="text/css" href="admin.css" rel="stylesheet"/>
			<link type="text/css" href="styles/prettify.css" rel="stylesheet"/>
			<link type="text/css" href="../scripts/yui/yui-skin.css" rel="stylesheet"/>
            <link rel="shortcut icon" href="../resources/exist_icon_16x16.ico"/>
			<link rel="icon" href="../resources/exist_icon_16x16.png" type="image/png"/>

			{ admin:panel-header() }

                { admin:info-header() }

                    {
                        if($isLoggedIn) then
                            admin:menu-panel()
                        else
                        ()
                    }

                        Logged in as: {xdb:get-current-user()}

                {
                    if($isLoggedIn)then
                    (
                        admin:panel()
                    )
                    else
                    (
                        admin:display-login-form()
                    )
                }

)

xquery version "1.0";
(: $Id$ :)
(:
    Main module of the database administration interface.
:)

declare namespace admin = "http://exist-db.org/xquery/admin-interface";

declare namespace request = "http://exist-db.org/xquery/request";
declare namespace session = "http://exist-db.org/xquery/session";
declare namespace util = "http://exist-db.org/xquery/util";
declare namespace xdb = "http://exist-db.org/xquery/xmldb";

import module namespace status = "http://exist-db.org/xquery/admin-interface/status" at "status.xqm";
import module namespace browse = "http://exist-db.org/xquery/admin-interface/browse" at "browse.xqm";
import module namespace users = "http://exist-db.org/xquery/admin-interface/users" at "users.xqm";
import module namespace xqueries = "http://exist-db.org/xquery/admin-interface/xqueries" at "xqueries.xqm";
import module namespace shut = "http://exist-db.org/xquery/admin-interface/shutdown" at "shutdown.xqm";
import module namespace setup = "http://exist-db.org/xquery/admin-interface/setup" at "setup.xqm";
import module namespace rev="http://exist-db.org/xquery/admin-interface/revisions" at "versions.xqm";
import module namespace backup="http://exist-db.org/xquery/admin-interface/backup" at "backup.xqm";
import module namespace prof="http://exist-db.org/xquery/profiling" at "trace.xqm";
import module namespace grammar="http://exist-db.org/xquery/admin-interface/grammar" at "grammar.xqm";
import module namespace install="http://exist-db.org/xquery/install-tools" at "install.xqm";
import module namespace fundocs="http://exist-db.org/xquery/admin/fundocs" at "fundocs.xqm";
import module namespace repomanager="http://exist-db.org/xquery/admin-interface/repo" at "repo.xqm";
import module namespace indexes="http://exist-db.org/xquery/admin-interface/indexes" at "indexes.xqm";

declare option exist:serialize "method=xhtml media-type=text/html";

(:
    Display the version, SVN revision and user info in the top right corner
:)
declare function admin:info-header() as element()
{

Version: { util:system-property( "product-version" ) }

SVN Revision: { util:system-property( "svn-revision" ) }

Build: {util:system-property("product-build")}

User: { xdb:get-current-user() }

};

(:
    Select the page to show. Every page is defined in its own module
:)
declare function admin:panel() as element()
{
    let $panel := request:get-parameter("panel", "status")[1] return
        if($panel eq "browse") then
        (
            browse:main()
        )
        else if($panel eq "users") then
        (
            users:main()
        )
         else if($panel eq "xqueries") then
        (
            xqueries:main()
        )
        else if($panel eq "shutdown") then
        (
            shut:main()
        )
        else if($panel eq "setup") then
        (
            setup:main()
        )
        else if ($panel eq "fundocs") then
        (
            fundocs:main()
        )
		else if ($panel eq "repo") then
		(
			repomanager:main()
		)
		else if ($panel eq "revisions") then
		(
			rev:main()
		)

		else if ($panel eq "backup") then
		(
		    backup:main()
		)
	    else if ($panel eq "trace") then
	    (
	        prof:main()
        )
        else if ($panel eq "grammar") then
	    (
	        grammar:main()
        )
        else if ($panel eq "install") then
        (
            install:main()
        )
        else if ($panel eq "indexes") then
        (
            indexes:main()
        )
        else
        (
            status:main()
        )
};

declare function admin:panel-header() {
    let $panel := request:get-parameter("panel", "status")[1]
    return
        if ($panel[1] eq "install") then
            install:header()
        else
            <xf:model xmlns:xf="http://www.w3.org/2002/xforms">
            </xf:model>
};

(:~
    Display the login form.
:)
declare function admin:display-login-form() as element()
{

Login

This is a protected resource. Only registered database users can log
        in. If you have not set up any users, login as "admin" and leave the
        password field empty. Note that the "guest" user is not permitted access.

        <form action="{session:encode-url(request:get-uri())}" method="post">

                    Please Login

                    Username:
                    <input name="user" type="text" size="20"/>

                    Password:
                    <input name="pass" type="password" size="20"/>

                    <input type="submit" value="Login"/>

            {
                for $param in request:get-parameter-names()
                return
                    <input type="hidden" name="{$param}"
                        value="{request:get-parameter($param, ())}"/>
            }
        </form>

};

(: main entry point :)
let $userParam := request:get-parameter("user", ())[1]
let $passwdParam := request:get-parameter("pass", ())[1]
let $isLoggedIn :=  if(xdb:get-current-user() eq "guest")then
    (
        (: is this a login attempt? :)
        if($userParam and not(empty($passwdParam)))then
        (
            if($userParam = ("", "guest") )then
            (
                (: prevent the guest user from accessing the admin webapp :)
                false()
            )
            else
            (
                (: try and log the user in :)
                xdb:login( "/db", $userParam, $passwdParam, true() )
            )
        )
        else
        (
            (: prevent the guest user from accessing the admin webapp :)
            false()
        )
    )
    else
    (
        (: if we are already logged in, are we logging out - i.e. set permissions back to guest :)
        if(request:get-parameter("logout",()))then
        (
        	let $null  := xdb:login("/db", "guest", "guest")
            let $inval := session:invalidate()

            return false()
        )
        else
        (
             (: we are already logged in and we are not the guest user :)
            true()
        )
    )
return (
    <?css-conversion no?>,

            <title>eXist Database Administration</title>
            <link type="text/css" href="admin.css" rel="stylesheet"/>
			<link type="text/css" href="styles/prettify.css" rel="stylesheet"/>
			<link type="text/css" href="../scripts/yui/yui-skin.css" rel="stylesheet"/>
            <link rel="shortcut icon" href="../resources/exist_icon_16x16.ico"/>
			<link rel="icon" href="../resources/exist_icon_16x16.png" type="image/png"/>

			{ admin:panel-header() }

                {admin:info-header()}

Select a Page

                    {
                        let $link := session:encode-url(request:get-uri())
                        return

Browse

Collections

Indexes

Install

Documentation

Examples

System

Shutdown

Status

Tooling

Backups

Package Repository

Query Profiling

User Management

View

Grammar cache

Running Jobs

Home

Logout

                    }

                        Logged in as: {xdb:get-current-user()}

                {
                    if($isLoggedIn)then
                    (
                        admin:panel()
                    )
                    else
                    (
                        admin:display-login-form()
                    )
                }

)


Updated documentation to return () explicitly.

jsoniq version "1.0";

(:
 : Copyright 2006-2013 The FLWOR Foundation.
 :
 : Licensed under the Apache License, Version 2.0 (the "License");
 : you may not use this file except in compliance with the License.
 : You may obtain a copy of the License at
 :
 : http://www.apache.org/licenses/LICENSE-2.0
 :
 : Unless required by applicable law or agreed to in writing, software
 : distributed under the License is distributed on an "AS IS" BASIS,
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 : See the License for the specific language governing permissions and
 : limitations under the License.
 :)

(:===========================================================================:)

(:~
 : This module provides functions for performing FTP commands.
 :

 : @author Paul J. Lucas
 : @library cURL Library
 : @project Zorba/Input Output/FTP Client
 :)
module namespace ftp = "http://zorba.io/modules/ftp-client";

declare namespace an = "http://zorba.io/annotations";
declare namespace ver = "http://zorba.io/options/versioning";

declare option ver:module-version "1.0";

(:~
 : Attempts to connect to an FTP server specified by the given URI.
 :
 : @param $uri The address of the FTP server to connect to.
 : It may either be simple host-name
 : (ftp.example.com)
 : or a URI using the ftp
 : or ftps (FTP over SSL/TLS)
 : schemes
 : (ftp://ftp.example.com).
 : If the latter,
 : the URI may also contain
 : username,
 : password,
 : and
 : port
 : authority subcomponents
 : per RFC 3986.
 : @param $options The options to use:
 :

 :
user

 :

 :        The user to log in as;
 :        default: "ftp" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the user, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
password

 :

 :        The password to use to log in;
 :        default: "ftp@example.com" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the password, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
port

 :

 :        The port number to use;
 :        default: whatever the default for the protocol is.
 :        If $uri is actually a URI instead of a simple host-name,
 :        the port, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
protocol

 :

 :        The protocol to use,
 :        either "ftp' or "ftps";
 :        default: "ftp".
 :        If $uri is actually a URI instead of a simple host-name,
 :        the protocol, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
SSL-communication

 :

 :        Whether to use SSL/TLS, one of:
 :

 :
"none"

 :
Don't use SSL.

 :
"try"

 :
Try using SSL, but, if unsuccessful, continue anyway.

 :
"control"

 :
Require SSL for the control connection.

 :
"all"

 :
Require SSL for all communication.

 :

 :        default:
 :        "none" for protocol "ftp"
 :        and
 :        "all" for protocol "ftps".
 :        Note that any value other than "none"
 :        for "ftp" implies explicit SSL;
 :        use of "ftps" implies implicit SSL.
 :        See "Methods of invoking security."
 :

 :
SSL-verify

 :

 :        When doing FTP over SSL/TLS,
 :        whether to verify the authenticity of the server's certificate
 :        and that the certificate is for that server;
 :        default: true.
 :        (You should never set this to false
 :        unless you are testing your own FTP server
 :        with a self-signed certificate.)
 :

 :
trace

 :

 :        Whether to emit information to standard error
 :        tracing the communication between the FTP client and server;
 :        default: false.
 :

 :

 : @return an opaque URI that serves as a connection handle to be used with
 : other functions in this module.
 : @error ftp:ALREADY_CONNECTED if $uri is already connected to.
 : @error ftp:INVALID_ARGUMENT if any option is invalid.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:connect( $uri as string, $options as object )
  as anyURI external;

(:~
 : Attempts to connect to an FTP server specified by the given URI.
 :
 : @param $uri The address of the FTP server to connect to.
 : It may either be simple host-name
 : (ftp.example.com)
 : or a URI using the ftp
 : or ftps (FTP over SSL/TLS)
 : schemes
 : (ftp://ftp.example.com).
 : If the latter,
 : the URI may also contain
 : username,
 : password,
 : and
 : port
 : authority subcomponents
 : per RFC 3986.
 : @param $options The options to use:
 :

 :
user

 :

 :        The user to log in as;
 :        default: "ftp" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the user, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
password

 :

 :        The password to use to log in;
 :        default: "ftp@example.com" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the password, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
port

 :

 :        The port number to use;
 :        default: whatever the default for the protocol is.
 :        If $uri is actually a URI instead of a simple host-name,
 :        the port, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
protocol

 :

 :        The protocol to use,
 :        either "ftp' or "ftps";
 :        default: "ftp".
 :        If $uri is actually a URI instead of a simple host-name,
 :        the protocol, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
SSL-communication

 :

 :        Whether to use SSL/TLS, one of:
 :

 :
"none"

 :
Don't use SSL.

 :
"try"

 :
Try using SSL, but, if unsuccessful, continue anyway.

 :
"control"

 :
Require SSL for the control connection.

 :
"all"

 :
Require SSL for all communication.

 :

 :        default:
 :        "none" for protocol "ftp"
 :        and
 :        "all" for protocol "ftps".
 :        Note that any value other than "none"
 :        for "ftp" implies explicit SSL;
 :        use of "ftps" implies implicit SSL.
 :        See "Methods of invoking security."
 :

 :
SSL-verify

 :

 :        When doing FTP over SSL/TLS,
 :        whether to verify the authenticity of the server's certificate
 :        and that the certificate is for that server;
 :        default: true.
 :        (You should never set this to false
 :        unless you are testing your own FTP server
 :        with a self-signed certificate.)
 :

 :
trace

 :

 :        Whether to emit information to standard error
 :        tracing the communication between the FTP client and server;
 :        default: false.
 :

 :

 : @return an opaque URI that serves as a connection handle to be used with
 : other functions in this module.
 : @error ftp:ALREADY_CONNECTED if $uri is already connected to.
 : @error ftp:INVALID_ARGUMENT if any option is invalid.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:connect-nondeterministic( $uri as string, $options as object )
  as anyURI
{
  ftp:connect( $uri, $options )
};

(:~
 : Deletes a file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to delete.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:delete( $conn as string, $remote-path as string )
  as () external;

(:~
 : Gets a binary file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.
 : @return the binary content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-binary( $conn as anyURI, $remote-path as string )
  as base64Binary external;

(:~
 : Gets a binary file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.
 : @return the binary content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-binary-nondeterministic( $conn as anyURI, $remote-path as string )
  as base64Binary
{
  ftp:get-binary( $conn, $remote-path )
};

(:~
 : Gets a text file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @param $encoding The character encoding of the file.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-text( $conn as anyURI, $remote-path as string, $encoding as string )
  as string external;

(:~
 : Gets a text file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @param $encoding The character encoding of the file.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-text-nondeterministic( $conn as anyURI, $remote-path as string,
                               $encoding as string )
  as string
{
  ftp:get-text( $conn, $remote-path, $encoding )
};

(:~
 : Gets a text file, presumed to be encoded in UTF-8, from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-text( $conn as anyURI, $remote-path as string )
  as string
{
  ftp:get-text( $conn, $remote-path, "UTF-8" )
};

(:~
 : Gets a text file, presumed to be encoded in UTF-8, from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-text-nondeterministic( $conn as anyURI, $remote-path as string )
  as string
{
  ftp:get-text( $conn, $remote-path, "UTF-8" )
};

(:~
 : Gets a listing for a directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The full path of the directory on the FTP server to get
 : the directory listing for.
 : An empty path is equivalent to /.
 : @return Returns a sequence of JSON objects, one per file or subdirectory in
 : the listing.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:list( $conn as anyURI, $remote-path as string )
  as object* external;

(:~
 : Gets a listing for a directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The full path of the directory on the FTP server to get
 : the directory listing for.
 : An empty path is equivalent to /.
 : @return Returns a sequence of JSON objects, one per file or subdirectory in
 : the listing.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:list-nondeterministic( $conn as anyURI, $remote-path as string )
  as object*
{
  ftp:list( $conn, $remote-path )
};

(:~
 : Creates a directory on the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the new directory to create.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:mkdir( $conn as string, $remote-path as string )
  as () external;

(:~
 : Uploads binary data to a file to the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $binary The binary data to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-binary( $conn as anyURI, $binary as base64Binary,
                $remote-path as string )
  as () external;

(:~
 : Uploads text to a file to the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $text The text to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @param $encoding The character encoding of the file.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-text( $conn as anyURI, $text as string, $remote-path as string,
              $encoding as string )
  as () external;

(:~
 : Uploads text to a UTF-8 encoded file on the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $text The text to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-text( $conn as anyURI, $text as string, $remote-path as string )
  as ()
{
  ftp:put-text( $conn, $text, $remote-path, "UTF-8" )
};

(:~
 : Renames a file or directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-from-path The path of the file or directory to rename.
 : @param $remote-to-path The new name.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-from-path or
 : $remote-to-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:rename( $conn as string, $remote-from-path as string,
            $remote-to-path as string )
  as () external;

(:~
 : Removes a directory from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the directory to remove.
 : @return the empty sequence.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:rmdir( $conn as string, $remote-path as string )
  as () external;

(:===========================================================================:)

(: vim:set syntax=xquery et sw=2 ts=2: :)

jsoniq version "1.0";

(:
 : Copyright 2006-2013 The FLWOR Foundation.
 :
 : Licensed under the Apache License, Version 2.0 (the "License");
 : you may not use this file except in compliance with the License.
 : You may obtain a copy of the License at
 :
 : http://www.apache.org/licenses/LICENSE-2.0
 :
 : Unless required by applicable law or agreed to in writing, software
 : distributed under the License is distributed on an "AS IS" BASIS,
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 : See the License for the specific language governing permissions and
 : limitations under the License.
 :)

(:===========================================================================:)

(:~
 : This module provides functions for performing FTP commands.
 :

 : @author Paul J. Lucas
 : @library cURL Library
 : @project Zorba/Input Output/FTP Client
 :)
module namespace ftp = "http://zorba.io/modules/ftp-client";

declare namespace an = "http://zorba.io/annotations";
declare namespace ver = "http://zorba.io/options/versioning";

declare option ver:module-version "1.0";

(:~
 : Attempts to connect to an FTP server specified by the given URI.
 :
 : @param $uri The address of the FTP server to connect to.
 : It may either be simple host-name
 : (ftp.example.com)
 : or a URI using the ftp
 : or ftps (FTP over SSL/TLS)
 : schemes
 : (ftp://ftp.example.com).
 : If the latter,
 : the URI may also contain
 : username,
 : password,
 : and
 : port
 : authority subcomponents
 : per RFC 3986.
 : @param $options The options to use:
 :

 :
user

 :

 :        The user to log in as;
 :        default: "ftp" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the user, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
password

 :

 :        The password to use to log in;
 :        default: "ftp@example.com" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the password, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
port

 :

 :        The port number to use;
 :        default: whatever the default for the protocol is.
 :        If $uri is actually a URI instead of a simple host-name,
 :        the port, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
protocol

 :

 :        The protocol to use,
 :        either "ftp' or "ftps";
 :        default: "ftp".
 :        If $uri is actually a URI instead of a simple host-name,
 :        the protocol, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
SSL-communication

 :

 :        Whether to use SSL/TLS, one of:
 :

 :
"none"

 :
Don't use SSL.

 :
"try"

 :
Try using SSL, but, if unsuccessful, continue anyway.

 :
"control"

 :
Require SSL for the control connection.

 :
"all"

 :
Require SSL for all communication.

 :

 :        default:
 :        "none" for protocol "ftp"
 :        and
 :        "all" for protocol "ftps".
 :        Note that any value other than "none"
 :        for "ftp" implies explicit SSL;
 :        use of "ftps" implies implicit SSL.
 :        See "Methods of invoking security."
 :

 :
SSL-verify

 :

 :        When doing FTP over SSL/TLS,
 :        whether to verify the authenticity of the server's certificate
 :        and that the certificate is for that server;
 :        default: true.
 :        (You should never set this to false
 :        unless you are testing your own FTP server
 :        with a self-signed certificate.)
 :

 :
trace

 :

 :        Whether to emit information to standard error
 :        tracing the communication between the FTP client and server;
 :        default: false.
 :

 :

 : @return an opaque URI that serves as a connection handle to be used with
 : other functions in this module.
 : @error ftp:ALREADY_CONNECTED if $uri is already connected to.
 : @error ftp:INVALID_ARGUMENT if any option is invalid.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:connect( $uri as string, $options as object )
  as anyURI external;

(:~
 : Attempts to connect to an FTP server specified by the given URI.
 :
 : @param $uri The address of the FTP server to connect to.
 : It may either be simple host-name
 : (ftp.example.com)
 : or a URI using the ftp
 : or ftps (FTP over SSL/TLS)
 : schemes
 : (ftp://ftp.example.com).
 : If the latter,
 : the URI may also contain
 : username,
 : password,
 : and
 : port
 : authority subcomponents
 : per RFC 3986.
 : @param $options The options to use:
 :

 :
user

 :

 :        The user to log in as;
 :        default: "ftp" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the user, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
password

 :

 :        The password to use to log in;
 :        default: "ftp@example.com" (for anonymous FTP).
 :        If $uri is actually a URI instead of a simple host-name,
 :        the password, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
port

 :

 :        The port number to use;
 :        default: whatever the default for the protocol is.
 :        If $uri is actually a URI instead of a simple host-name,
 :        the port, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
protocol

 :

 :        The protocol to use,
 :        either "ftp' or "ftps";
 :        default: "ftp".
 :        If $uri is actually a URI instead of a simple host-name,
 :        the protocol, if specified, must be part of the URI
 :        and the value of this option is ignored.
 :

 :
SSL-communication

 :

 :        Whether to use SSL/TLS, one of:
 :

 :
"none"

 :
Don't use SSL.

 :
"try"

 :
Try using SSL, but, if unsuccessful, continue anyway.

 :
"control"

 :
Require SSL for the control connection.

 :
"all"

 :
Require SSL for all communication.

 :

 :        default:
 :        "none" for protocol "ftp"
 :        and
 :        "all" for protocol "ftps".
 :        Note that any value other than "none"
 :        for "ftp" implies explicit SSL;
 :        use of "ftps" implies implicit SSL.
 :        See "Methods of invoking security."
 :

 :
SSL-verify

 :

 :        When doing FTP over SSL/TLS,
 :        whether to verify the authenticity of the server's certificate
 :        and that the certificate is for that server;
 :        default: true.
 :        (You should never set this to false
 :        unless you are testing your own FTP server
 :        with a self-signed certificate.)
 :

 :
trace

 :

 :        Whether to emit information to standard error
 :        tracing the communication between the FTP client and server;
 :        default: false.
 :

 :

 : @return an opaque URI that serves as a connection handle to be used with
 : other functions in this module.
 : @error ftp:ALREADY_CONNECTED if $uri is already connected to.
 : @error ftp:INVALID_ARGUMENT if any option is invalid.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:connect-nondeterministic( $uri as string, $options as object )
  as anyURI
{
  ftp:connect( $uri, $options )
};

(:~
 : Deletes a file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to delete.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:delete( $conn as string, $remote-path as string )
  external;

(:~
 : Gets a binary file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.
 : @return the binary content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-binary( $conn as anyURI, $remote-path as string )
  as base64Binary external;

(:~
 : Gets a binary file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.
 : @return the binary content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-binary-nondeterministic( $conn as anyURI, $remote-path as string )
  as base64Binary
{
  ftp:get-binary( $conn, $remote-path )
};

(:~
 : Gets a text file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @param $encoding The character encoding of the file.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-text( $conn as anyURI, $remote-path as string, $encoding as string )
  as string external;

(:~
 : Gets a text file from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @param $encoding The character encoding of the file.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-text-nondeterministic( $conn as anyURI, $remote-path as string,
                               $encoding as string )
  as string
{
  ftp:get-text( $conn, $remote-path, $encoding )
};

(:~
 : Gets a text file, presumed to be encoded in UTF-8, from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:get-text( $conn as anyURI, $remote-path as string )
  as string
{
  ftp:get-text( $conn, $remote-path, "UTF-8" )
};

(:~
 : Gets a text file, presumed to be encoded in UTF-8, from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the file to get.  It must not be empty.
 : @return the text content of $remote-path.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:get-text-nondeterministic( $conn as anyURI, $remote-path as string )
  as string
{
  ftp:get-text( $conn, $remote-path, "UTF-8" )
};

(:~
 : Gets a listing for a directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The full path of the directory on the FTP server to get
 : the directory listing for.
 : An empty path is equivalent to /.
 : @return Returns a sequence of JSON objects, one per file or subdirectory in
 : the listing.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare function
ftp:list( $conn as anyURI, $remote-path as string )
  as object* external;

(:~
 : Gets a listing for a directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The full path of the directory on the FTP server to get
 : the directory listing for.
 : An empty path is equivalent to /.
 : @return Returns a sequence of JSON objects, one per file or subdirectory in
 : the listing.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:nondeterministic function
ftp:list-nondeterministic( $conn as anyURI, $remote-path as string )
  as object*
{
  ftp:list( $conn, $remote-path )
};

(:~
 : Creates a directory on the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the new directory to create.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:mkdir( $conn as string, $remote-path as string )
  external;

(:~
 : Uploads binary data to a file to the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $binary The binary data to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-binary( $conn as anyURI, $binary as base64Binary,
                $remote-path as string )
  external;

(:~
 : Uploads text to a file to the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $text The text to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @param $encoding The character encoding of the file.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty
 : or $encoding is either an invalid or unsupported encoding.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-text( $conn as anyURI, $text as string, $remote-path as string,
              $encoding as string )
  external;

(:~
 : Uploads text to a UTF-8 encoded file on the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $text The text to upload.
 : @param $remote-path The path of the file to upload to. It must not be empty.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:put-text( $conn as anyURI, $text as string, $remote-path as string )
{
  ftp:put-text( $conn, $text, $remote-path, "UTF-8" )
};

(:~
 : Renames a file or directory on an FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-from-path The path of the file or directory to rename.
 : @param $remote-to-path The new name.
 : @error ftp:INVALID_ARGUMENT if $remote-from-path or
 : $remote-to-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:rename( $conn as string, $remote-from-path as string,
            $remote-to-path as string )
  external;

(:~
 : Removes a directory from the FTP server.
 :
 : @param $conn The opaque URI connection handle previously returned by
 : ftp:connect().
 : @param $remote-path The path of the directory to remove.
 : @error ftp:INVALID_ARGUMENT if $remote-path is empty.
 : @error ftp:NOT_CONNECTED if $conn is either an invalid handle
 : or is no longer a valid handle.
 : @error ftp:FTP_ERROR if there was some other FTP error.
 :)
declare %an:sequential function
ftp:rmdir( $conn as string, $remote-path as string )
  external;

(:===========================================================================:)

(: vim:set syntax=xquery et sw=2 ts=2: :)


Update json-xml-01.xq

Update json-xml-01.xq

import module namespace jsd="http://zorba.io/modules/json-xml";
import module namespace jsdi="http://jsoniq.org/functions";

declare variable $jsnTree := jsdi:parse-json('{
"phone" : ["604 123-1234","406 321-4321"],
"phoneNumbers2" : [ "212 732-1234", "646 123-4567" ]
}');
declare variable $asXML := jsd:json-to-xml($jsnTree);

$asXML

import module namespace jsd="http://zorba.io/modules/json-xml";
import module namespace jsdi="http://jsoniq.org/functions";

declare variable $jsnTree := jsdi:parse-json('{
"phone" : ["604 123-1234","406 321-4321"],
"phoneNumbers2" : [ "212 732-1234", "646 123-4567" ]
}');
declare variable $asXML := jsd:json-to-xml($jsnTree);

[
  $asXML
]