From: <wol...@us...> - 2009-10-29 17:55:16
|
Revision: 10289 http://exist.svn.sourceforge.net/exist/?rev=10289&view=rev Author: wolfgang_m Date: 2009-10-29 17:55:04 +0000 (Thu, 29 Oct 2009) Log Message: ----------- [feature] XQueryURLRewrite has been extended and may now serve as a single entry point into the web application. This makes it possible to have multiple root paths, which are either mapped to some path on the file system or a collection within the database. For example, the main web application could be served from a database collection, while URL paths starting with /fs point into the /webapp directory on the file system. The controller.xql files, which define how a request to a certain path is handled, are now much more portable. With a properly written controller.xql, it should be possible to move an entire XQuery application from one directory to another or even from a directory into the database without changing any links or paths. Modified Paths: -------------- trunk/eXist/webapp/admin/admin.xql trunk/eXist/webapp/admin/controller.xql trunk/eXist/webapp/sandbox/controller.xql trunk/eXist/webapp/sandbox/get-examples.xql trunk/eXist/webapp/xforms/controller.xql Modified: trunk/eXist/webapp/admin/admin.xql =================================================================== --- trunk/eXist/webapp/admin/admin.xql 2009-10-29 17:50:35 UTC (rev 10288) +++ trunk/eXist/webapp/admin/admin.xql 2009-10-29 17:55:04 UTC (rev 10289) @@ -180,19 +180,23 @@ <div class="content"> <div class="guide"> <div class="guide-title">Select a Page</div> - <ul> - <li><a href="..">Home</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=status">System Status</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=browse">Browse Collections</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=users">User Management</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=xqueries">View Running Jobs</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=setup">Examples Setup</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=backup">Backups</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=trace">Query Profiling</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=grammar">Grammar cache</a></li> - <li><a href="{session:encode-url(request:get-uri())}?panel=shutdown">Shutdown</a></li> - <li><a href="{session:encode-url(request:get-uri())}?logout=yes">Logout</a></li> - </ul> + { + let $link := session:encode-url(request:get-uri()) + return + <ul> + <li><a href="..">Home</a></li> + <li><a href="{$link}?panel=status">System Status</a></li> + <li><a href="{$link}?panel=browse">Browse Collections</a></li> + <li><a href="{$link}?panel=users">User Management</a></li> + <li><a href="{$link}?panel=xqueries">View Running Jobs</a></li> + <li><a href="{$link}?panel=setup">Examples Setup</a></li> + <li><a href="{$link}?panel=backup">Backups</a></li> + <li><a href="{$link}?panel=trace">Query Profiling</a></li> + <li><a href="{$link}?panel=grammar">Grammar cache</a></li> + <li><a href="{$link}?panel=shutdown">Shutdown</a></li> + <li><a href="{$link}?logout=yes">Logout</a></li> + </ul> + } <div class="userinfo"> Logged in as: {xdb:get-current-user()} </div> Modified: trunk/eXist/webapp/admin/controller.xql =================================================================== --- trunk/eXist/webapp/admin/controller.xql 2009-10-29 17:50:35 UTC (rev 10288) +++ trunk/eXist/webapp/admin/controller.xql 2009-10-29 17:55:04 UTC (rev 10289) @@ -3,33 +3,24 @@ import module namespace request="http://exist-db.org/xquery/request"; import module namespace xdb = "http://exist-db.org/xquery/xmldb"; -let $uri := request:get-uri() -let $context := request:get-context-path() -let $path := substring-after($uri, $context) -let $name := replace($uri, '^.*/([^/]+)$', '$1') -return - if (starts-with($path, "/admin/backups")) then - let $user := xdb:get-current-user() - return - if (not(xdb:is-admin-user($user))) then - <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> - <redirect url="../admin.xql"/> - </dispatch> - else - <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> - <forward url="/admin/retrieve-backup.xql"> - <add-parameter name="archive" value="{$name}"/> - </forward> - </dispatch> - else if (matches($path, "admin/?$")) then - <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> - <redirect url="admin.xql"/> - </dispatch> - else if ($name eq "admin.xql") then - <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> - <forward url="/admin/admin.xql"/> - </dispatch> - else - <ignore xmlns="http://exist.sourceforge.net/NS/exist"> - <cache-control cache="yes"/> - </ignore> \ No newline at end of file +if (starts-with($exist:path, "/backups")) then + let $user := xdb:get-current-user() + return + if (not(xdb:is-admin-user($user))) then + <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> + <redirect url="../admin.xql"/> + </dispatch> + else + <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> + <forward url="/admin/retrieve-backup.xql"> + <add-parameter name="archive" value="{$exist:resource}"/> + </forward> + </dispatch> + else if ($exist:path = "/") then + <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> + <redirect url="admin.xql"/> + </dispatch> + else + <ignore xmlns="http://exist.sourceforge.net/NS/exist"> + <cache-control cache="yes"/> + </ignore> \ No newline at end of file Modified: trunk/eXist/webapp/sandbox/controller.xql =================================================================== --- trunk/eXist/webapp/sandbox/controller.xql 2009-10-29 17:50:35 UTC (rev 10288) +++ trunk/eXist/webapp/sandbox/controller.xql 2009-10-29 17:55:04 UTC (rev 10289) @@ -7,11 +7,9 @@ be handled like any other query. The results are then passed to a second XQuery, session.xql, for post-processing. :) -import module namespace xdb = "http://exist-db.org/xquery/xmldb"; - (: Root path: redirect to sandbox.xql :) -if ($exist:resource eq '/') then +if ($exist:path eq '/') then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <redirect url="sandbox.xql"/> </dispatch> Modified: trunk/eXist/webapp/sandbox/get-examples.xql =================================================================== --- trunk/eXist/webapp/sandbox/get-examples.xql 2009-10-29 17:50:35 UTC (rev 10288) +++ trunk/eXist/webapp/sandbox/get-examples.xql 2009-10-29 17:55:04 UTC (rev 10289) @@ -6,7 +6,7 @@ <select id="saved" name="saved"> <option value=""></option> { - for $entry in //example-queries/query + for $entry in collection("/db")//example-queries/query return <option value="{$entry/code}">{$entry/description}</option> } Modified: trunk/eXist/webapp/xforms/controller.xql =================================================================== --- trunk/eXist/webapp/xforms/controller.xql 2009-10-29 17:50:35 UTC (rev 10288) +++ trunk/eXist/webapp/xforms/controller.xql 2009-10-29 17:55:04 UTC (rev 10289) @@ -33,17 +33,13 @@ }; let $dummy := local:setup() -let $uri := request:get-uri() -let $context := request:get-context-path() -let $path := substring-after($uri, $context) -let $name := replace($uri, '^.*/([^/]+)$', '$1') return - if (matches($path, '/xforms/?$')) then + if ($exist:path eq '/') then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> - <redirect url="{$context}/xforms/examples.xml"/> + <redirect url="examples.xml"/> </dispatch> (: send docbook docs through the db2xhtml stylesheet :) - else if (ends-with($uri, 'examples.xml') or ends-with($uri, 'xforms.xml')) then + else if ($exist:resource = ('examples.xml', 'xforms.xml')) then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <view> <forward servlet="XSLTServlet"> @@ -61,8 +57,8 @@ </dispatch> (: for the following examples, the xsltforms.xsl stylesheet is applied on the *server*, not the client :) - else if ($name = ('todo-list.xml', 'shakespeare.xml')) then - let $relPath := if ($name eq 'todo-list.xml') then '../' else '' + else if ($exist:resource = ('todo-list.xml', 'shakespeare.xml')) then + let $relPath := if ($exist:resource eq 'todo-list.xml') then '../' else '' return <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <view> @@ -85,7 +81,7 @@ </view> <cache-control cache="yes"/> </dispatch> - else if ($name eq 'test.xql') then + else if ($exist:resource eq 'test.xql') then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <view> <forward servlet="XSLTServlet"> @@ -102,16 +98,16 @@ <cache-control cache="yes"/> </dispatch> (: make sure the global css and js files are resolved :) - else if ($name = ('default-style.css', 'default-style2.css', 'curvycorners.js') - or matches($path, 'resources/')) then - let $newPath := replace($path, '^.*/([^/]+/[^/]+)$', '/$1') + else if ($exist:resource = ('default-style.css', 'default-style2.css', 'curvycorners.js') + or matches($exist:path, 'resources/')) then + let $newPath := replace($exist:path, '^.*/([^/]+/[^/]+)$', '/$1') return <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <forward url="{$newPath}"/> <cache-control cache="yes"/> </dispatch> - else if (matches($path, 'syntax/.*\.(css|js)')) then - let $newPath := replace($path, '^.*/([^/]+/syntax/[^/]+)$', '/$1') + else if (matches($exist:path, 'syntax/.*\.(css|js)')) then + let $newPath := replace($exist:path, '^.*/([^/]+/syntax/[^/]+)$', '/$1') return <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <forward url="{$newPath}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |