[bugfix] Fix licence.

[bugfix] Fix licence.

(:
 : eXist-db Open Source Native XML Database
 : Copyright (C) 2001 The eXist-db Authors
 :
 : info@exist-db.org
 : http://www.exist-db.org
 :
 : This library is free software; you can redistribute it and/or
 : modify it under the terms of the GNU Lesser General Public
 : License as published by the Free Software Foundation; either
 : version 2.1 of the License, or (at your option) any later version.
 :
 : This library is distributed in the hope that it will be useful,
 : but WITHOUT ANY WARRANTY; without even the implied warranty of
 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 : Lesser General Public License for more details.
 :
 : You should have received a copy of the GNU Lesser General Public
 : License along with this library; if not, write to the Free Software
 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 :)
 (:~
  : @see https://github.com/eXist-db/exist/issues/3390
  :)
xquery version "3.1";

module namespace t="http://exist-db.org/xquery/test";

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

declare
    %test:assertFalse
function t:castable-test() {
    "0" castable as xs:QName
};


check whether number server file is available

declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace hgv = "HGV";
declare option saxon:output "method=xml";
declare option saxon:output "indent=yes";
declare variable $idpData external;

(: java -Xms512m -Xmx1536m net.sf.saxon.Query -q:idno.xql idpData=.../idp.data > idno.xml :)

<list>{
  (for $doc in collection(concat($idpData, '/HGV_meta_EpiDoc?select=*.xml;recurse=yes'))

    let $hgv := string($doc//tei:publicationStmt/tei:idno[@type = 'filename'])
    let $tm  := string($doc//tei:publicationStmt/tei:idno[@type = 'TM'])
    let $ddb := string($doc//tei:publicationStmt/tei:idno[@type = 'ddb-hybrid'])

    let $dclpFile := concat($idpData, '/DCLP/', ceiling(number($tm) div 1000), '/', $tm, '.xml')
    let $dclpEpiDoc := if(doc-available($dclpFile))then(doc($dclpFile))else()
    let $dclp := if($dclpEpiDoc)then(string($dclpEpiDoc//tei:publicationStmt/tei:idno[@type = 'dclp-hybrid']))else()

    return <item>
    <idno type="hgv">{data($hgv)}</idno>
    <idno type="tm">{data($tm)}</idno>
    <idno type="ddb">{data($ddb)}</idno>
    {if($dclp)then(
      <idno type="dclp">{data($dclp)}</idno>
    )else()}
    </item>
  ,
  for $doc in collection(concat($idpData, '/DCLP?select=*.xml;recurse=yes'))[.//tei:div[@type = 'edition'][@xml:lang = ('grc', 'la', 'egy-Egyd', 'cop', 'ara')]]

    let $tm   := $doc/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type = 'TM']
    let $dclp := $doc/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type = 'dclp-hybrid']
    let $numberServer := concat('http://papyri.info/dclp/', $tm, '/rdf')
    let $dclpRdf := if(doc-available($numberServer))then(doc($numberServer))else(trace($numberServer, 'Numberserver not available')) (: cl: dieser Zugriff mit vorhergehendem Test kostet ca. eine halbe Stunde :)

    return if($dclpRdf//rdf:Description[starts-with(@rdf:about, 'http://papyri.info/hgv')])then(<item><idno type="tm">{data($tm)}</idno><idno type="dclp">{data($dclp)}</idno></item>)else()
    )
}</list>

declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace hgv = "HGV";
declare option saxon:output "method=xml";
declare option saxon:output "indent=yes";
declare variable $idpData external;

(: java -Xms512m -Xmx1536m net.sf.saxon.Query -q:idno.xql idpData=.../idp.data > idno.xml :)

<list>{
  (for $doc in collection(concat($idpData, '/HGV_meta_EpiDoc?select=*.xml;recurse=yes'))

    let $hgv := string($doc//tei:publicationStmt/tei:idno[@type = 'filename'])
    let $tm  := string($doc//tei:publicationStmt/tei:idno[@type = 'TM'])
    let $ddb := string($doc//tei:publicationStmt/tei:idno[@type = 'ddb-hybrid'])

    let $dclpFile := concat($idpData, '/DCLP/', ceiling(number($tm) div 1000), '/', $tm, '.xml')
    let $dclpEpiDoc := if(doc-available($dclpFile))then(doc($dclpFile))else()
    let $dclp := if($dclpEpiDoc)then(string($dclpEpiDoc//tei:publicationStmt/tei:idno[@type = 'dclp-hybrid']))else()

    return <item>
    <idno type="hgv">{data($hgv)}</idno>
    <idno type="tm">{data($tm)}</idno>
    <idno type="ddb">{data($ddb)}</idno>
    {if($dclp)then(
      <idno type="dclp">{data($dclp)}</idno>
    )else()}
    </item>
  ,
  for $doc in collection(concat($idpData, '/DCLP?select=*.xml;recurse=yes'))[.//tei:div[@type = 'edition'][@xml:lang = ('grc', 'la', 'egy-Egyd', 'cop', 'ara')]]

    let $tm   := $doc/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type = 'TM']
    let $dclp := $doc/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type = 'dclp-hybrid']
    let $dclpRdf := doc(concat('http://papyri.info/dclp/', $tm, '/rdf')) (: cl: dieser Zugriff kostet ca. eine halbe Stunde :)

    return if($dclpRdf//rdf:Description[starts-with(@rdf:about, 'http://papyri.info/hgv')])then(<item><idno type="tm">{data($tm)}</idno><idno type="dclp">{data($dclp)}</idno></item>)else()
    )
}</list>


fix svg hedge, zero width j and add remote example

module namespace svg-util='http://code.google.com/p/xrx/svg-util';
declare namespace svg="http://www.w3.org/2000/svg";

(: some simple functions to make a wild guess on the font sizes.  We just need to get
close to create a box around the text so four categories of font sizes works fine for
99.9% of my data element names :)

(: A very rough guess at the width of this string in pixels since we don't have font-width information :)
declare function svg-util:string-width($input as xs:string) as xs:double {
   let $very-wide := svg-util:count-very-wide($input) * 15.0
   let $wide := svg-util:count-wide($input) * 11.1
   let $normal-lower-case := svg-util:count-normal-lower-case($input) * 8.9
   let $narrow := svg-util:count-narrow($input) * 4
   return $very-wide + $wide + $normal-lower-case + $narrow
};

(: Count only the uppercase letters by replaceing all lowercase, numbers and special chars with nulls. :)
declare function svg-util:count-upper-case($input as xs:string) as xs:integer {
  string-length(replace($input, '^[a-z0-9_\-]*', ''))
};

(: Count only the lowercase letters by replaceing all uppercase, numbers and special chars with nulls. :)
declare function svg-util:count-lower-case($input as xs:string) as xs:integer {
  string-length(replace($input, '^[A-Z0-9_\-]*', ''))
};

(: The number of very wide letters like "M" and "W" letters in a string :)
declare function svg-util:count-very-wide($input as xs:string) as xs:integer {
  string-length(replace($input, '[^MWmw]*', ''))
};

(: The number of non-mw uppercase letters in a string :)
declare function svg-util:count-wide($input as xs:string) as xs:integer {
   string-length(replace($input, '[^ABCDEFGHIJKLNOPQRSTUVXYZ]*', ''))
};

(: The number of normal lowercase letters, number, -, _ except i and l :)
declare function svg-util:count-normal-lower-case($input as xs:string) as xs:integer {
   string-length(replace($input, '[^abcdefghjknopqrstuvxyz234567890_\-]*', ''))
};

(: The number of narrow letters like "i" and "l" the number "1" in a string :)
declare function svg-util:count-narrow($input as xs:string) as xs:integer {
   string-length(replace($input, '[^il1]*', ''))
};

module namespace svg-util='http://code.google.com/p/xrx/svg-util';
declare namespace svg="http://www.w3.org/2000/svg";

(: some simple functions to make a wild guess on the font sizes.  We just need to get
close to create a box around the text so four categories of font sizes works fine for
99.9% of my data element names :)

(: A very rough guess at the width of this string in pixels since we don't have font-width information :)
declare function svg-util:string-width($input as xs:string) as xs:double {
   let $very-wide := svg-util:count-very-wide($input) * 15.0
   let $wide := svg-util:count-wide($input) * 11.1
   let $normal-lower-case := svg-util:count-normal-lower-case($input) * 8.9
   let $narrow := svg-util:count-narrow($input) * 4
   return $very-wide + $wide + $normal-lower-case + $narrow
};

(: Count only the uppercase letters by replaceing all lowercase, numbers and special chars with nulls. :)
declare function svg-util:count-upper-case($input as xs:string) as xs:integer {
  string-length(replace($input, '^[a-z0-9_\-]*', ''))
};

(: Count only the lowercase letters by replaceing all uppercase, numbers and special chars with nulls. :)
declare function svg-util:count-lower-case($input as xs:string) as xs:integer {
  string-length(replace($input, '^[A-Z0-9_\-]*', ''))
};

(: The number of very wide letters like "M" and "W" letters in a string :)
declare function svg-util:count-very-wide($input as xs:string) as xs:integer {
  string-length(replace($input, '[^MWmw]*', ''))
};

(: The number of non-mw uppercase letters in a string :)
declare function svg-util:count-wide($input as xs:string) as xs:integer {
   string-length(replace($input, '[^ABCDEFGHIJKLNOPQRSTUVXYZ]*', ''))
};

(: The number of normal lowercase letters, number, -, _ except i and l :)
declare function svg-util:count-normal-lower-case($input as xs:string) as xs:integer {
   string-length(replace($input, '[^abcdefghknopqrstuvxyz234567890_\-]*', ''))
};

(: The number of narrow letters like "i" and "l" the number "1" in a string :)
declare function svg-util:count-narrow($input as xs:string) as xs:integer {
   string-length(replace($input, '[^ijl1]*', ''))
};


Changing Adam's recent changes

Changing Adam's recent changes

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

(:
    Module: trigger database shutdown.
:)
module namespace shutdown="http://exist-db.org/xquery/admin-interface/shutdown";

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

declare function shutdown:main($user as xs:string, $password as xs:string) as element() {

Database Shutdown

        {
            if(not(xdb:is-admin-user($user))) then

                    Only users of the "dba" group can shutdown the database.

            else
                let $shutdown := request:get-parameter("action", ())
                return
                    if($shutdown) then

					        Database shutdown starts in {request:get-parameter("delay", "2")} sec.
				            {exist:shutdown($user, $password, request:get-parameter("delay", "2") cast as xs:long)}

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

Clicking on the button below will trigger a database shutdown. If
                            you are running the database with the webserver included in the distribution,
                            this will also shut down the webserver. Otherwise, only the database will close
                            down.

                                    <input type="submit" name="action" value="Shutdown"/>
                                    Delay in seconds: <input type="text" size="6" name="delay" value="2"/>

                            <input type="hidden" name="panel" value="shutdown"/>
                        </form>
        }

};

(:
    Module: trigger database shutdown.
:)
module namespace shutdown="http://exist-db.org/xquery/admin-interface/shutdown";

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

declare function shutdown:main($user as xs:string, $password as xs:string) as element() {

Database Shutdown

        {
            if(not(xdb:is-admin-user($user))) then

                    Only users of the "dba" group can shutdown the database.

            else
                let $shutdown := request:get-parameter("action", ())
                return
                    if($shutdown) then

					        Database shutdown starts in {request:get-parameter("delay", "2")} sec.
				            {eXist:shutdown($user, $password, request:get-parameter("delay", "2") cast as xs:long)}

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

Clicking on the button below will trigger a database shutdown. If
                            you are running the database with the webserver included in the distribution,
                            this will also shut down the webserver. Otherwise, only the database will close
                            down.

                                    <input type="submit" name="action" value="Shutdown"/>
                                    Delay in seconds: <input type="text" size="6" name="delay" value="2"/>

                            <input type="hidden" name="panel" value="shutdown"/>
                        </form>
        }

};