xquery version "1.0-ml"; (: : Client Query Application : : Copyright (c) 2002-2010 Mark Logic Corporation. All Rights Reserved. : : 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. : : The use of the Apache License does not indicate that this project is : affiliated with the Apache Software Foundation. :) import module namespace c = "com.marklogic.developer.cq.controller" at "lib-controller.xqy"; import module namespace d = "com.marklogic.developer.cq.debug" at "lib-debug.xqy"; import module namespace su = "com.marklogic.developer.cq.security" at "lib-security-utils.xqy"; import module namespace v = "com.marklogic.developer.cq.view" at "lib-view.xqy"; import module namespace x = "com.marklogic.developer.cq.xquery" at "lib-xquery.xqy"; declare namespace sess = "com.marklogic.developer.cq.session"; declare option xdmp:mapping "false"; declare variable $SESSIONS as element(sess:session)* := c:sessions(); d:check-debug(), c:set-content-type(), { v:get-html-head('sessions', false(), true()),

Welcome to cq

This is Mark Logic cq, a web-based query tool for MarkLogic Server. You can find out more about MarkLogic Server and cq at developer.marklogic.com. You may also find it helpful to read the cq README file.

The admin user can install pre-defined roles for cq by clicking on this install-roles.xqy link.

return to cq

{ (: placeholder for local sessions :) element div { attribute id { "sessions-local" }, attribute class { "hidden" }, element h1 { "Local Sessions" }, element p { 'These sessions use storage provided by your browser.', 'You can also ', element a { attribute href { 'session-import-local.xqy' }, 'import' }, ' sessions from local XML files.' } }, element h1 { 'Server Sessions' }, (: force session initialization :) let $s := $c:SESSION return (), if (exists($c:SESSION-EXCEPTION)) then

WARNING: server session storage has been disabled, because of an error.

Perhaps you have disabled server storage of sessions for this instance of cq. If so, you can ignore this error and use local sessions, or return to cq.

{ if ($c:SESSION-DB eq 0) then

You are running cq from the filesystem. Make sure that the directory {$c:SESSION-DIRECTORY} exists, and that MarkLogic Server can write to it.

Make sure that the current user has the following exec privileges:

  • http://marklogic.com/xdmp/privileges/xdmp-document-get
  • http://marklogic.com/xdmp/privileges/xdmp-filesystem-directory
  • http://marklogic.com/xdmp/privileges/xdmp-save

else

You are running cq from a modules database, { xdmp:database-name($c:SESSION-DB) }. You are logged in as { $su:USER }. Make sure that the directory {$c:SESSION-DIRECTORY} exists, and that your login can write to it.

}

The admin user may be able to fix this problem by clicking on this install-roles.xqy link, then granting the cq-sessions roles to your user login. Please consult the README for more information about cq.

The complete error message follows:


{
            xdmp:quote($c:SESSION-EXCEPTION)
          }

else

These sessions are stored on the server.

On this page you can start a new session, or resume a saved session. Your sessions will be stored in the modules location on the current server: { xdmp:get-request-header("Host") }. Your sessions will be stored in the { if (xdmp:modules-database() eq 0) then "filesystem," else ("database", xdmp:database-name(xdmp:modules-database())), " " } under the path { $c:SESSION-DIRECTORY }.

Note that if your modules location is a database, you must have write permission for the uri { $c:SESSION-DIRECTORY } in order to create sessions. If you do not have read permission for a session, you will not be able to view it. If a session is locked by another user, you will not be able to resume it.

{ let $sessions := c:sessions() let $d := d:debug(("sessions:", count($sessions))) return if (exists($sessions)) then element div {
, element table { element tr { for $i in ( "session name", "user", "created", "last modified", "") return element th { $i } }, for $i in $sessions let $id := c:session-id($i) let $uri := c:session-uri($i) (: we only care about the lock that expires last :) let $conflicting := c:conflicting-locks($uri, 1) let $name as xs:string := ($i/sess:name, "(unnamed)")[1] return element tr { element td { $name }, element td { string($i/sec:user) }, element td { data($i/sess:created) }, element td { data($i/sess:last-modified) }, element td { if (empty($conflicting)) then () else text { "by", $conflicting/lock:owner, "until", adjust-dateTime-to-timezone( x:epoch-seconds-to-dateTime( $conflicting/lock:timestamp + $conflicting/lock:timeout ) ) }, (: only show resume button if there are no conflicting locks :) element input { attribute type { "button" }, attribute title { data($i/sess:query-buffers/sess:query[1]) }, attribute onclick { concat("list.resumeSession('", $id, "')") }, attribute value { "Resume", (' ', $id)[ $d:DEBUG ] } }[ not($conflicting) ], $x:NBSP, (: clone button :) element input { attribute type { "button" }, attribute title { "clone this session" }, attribute onclick { concat("list.cloneSession('", $id, "', this)") }, attribute value { "Clone", (' ', $id)[ $d:DEBUG ] } }, $x:NBSP, (: export button :) element input { attribute type { "button" }, attribute title { "export this session" }, attribute onclick { concat("list.exportServerSession('", $id, "', this)") }, attribute value { "Export", (' ', $id)[ $d:DEBUG ] } }, $x:NBSP, (: only show delete button if there are no conflicting locks :) element input { attribute type { "button" }, attribute title { "permanently delete this session" }, attribute onclick { concat("list.deleteSession('", $id, "', this)") }, attribute value { "Delete", (' ', $id)[ $d:DEBUG ] } }[ not($conflicting) ] } } } } else

There are no resumable sessions. Please create a new session.

}
}
} (: session.xqy :)