Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
discovery index for data API, closes #20
- Loading branch information
1 parent
f3812ff
commit f6cab9e
Showing
5 changed files
with
145 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
xquery version "3.0"; | |||
(: API module for functions for index URIs | |||
: | |||
: Functions assume that the following has already been done: | |||
: authentication, | |||
: content negotiation | |||
: | |||
: Copyright 2012 Efraim Feinstein <efraim@opensiddur.org> | |||
: Open Siddur Project | |||
: Licensed Under the GNU Lesser General Public License, version 3 or later | |||
:) | |||
module namespace dindex = 'http://jewishliturgy.org/api/data/index'; | |||
|
|||
declare namespace rest="http://exquery.org/ns/rest/annotation/"; | |||
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; | |||
declare namespace o="http://a9.com/-/spec/opensearch/1.1/"; | |||
|
|||
(:~ list all available data APIs :) | |||
declare | |||
%rest:GET | |||
%rest:path("/data") | |||
%rest:produces("application/xhtml+xml", "text/html", "application/xml", "text/xml") | |||
function dindex:list( | |||
) as item()+ { | |||
<rest:response> | |||
<output:serialization-parameters> | |||
<output:method value="html5"/> | |||
</output:serialization-parameters> | |||
</rest:response>, | |||
<html xmlns="http://www.w3.org/1999/xhtml"> | |||
<head> | |||
<title>Open Siddur API Index</title> | |||
</head> | |||
<body> | |||
<ul class="results"> | |||
<li class="result"> | |||
{((: TODO: replace request:get-uri() with rest:get-absolute-uri() | |||
:))} | |||
<a class="discovery" href="{request:get-uri()}/transliteration">Transliteration</a> | |||
</li> | |||
</ul> | |||
</body> | |||
</html> | |||
}; | |||
|
|||
declare | |||
%rest:GET | |||
%rest:path("/data/OpenSearchDescription") | |||
%rest:query-param("source", "{$source}", "") | |||
%rest:produces("application/opensearchdescription+xml","application/xml","text/xml") | |||
function dindex:open-search( | |||
$source as xs:string | |||
) as item()+ { | |||
<rest:response> | |||
<output:serialization-parameters> | |||
<output method="xml"/> | |||
</output:serialization-parameters> | |||
</rest:response>, | |||
<o:OpenSearchDescription | |||
xmlns:jsearch="http://jewishliturgy.org/ns/search"> | |||
<o:ShortName>Open Siddur Search</o:ShortName> | |||
<o:Description>Full text search of Open Siddur texts.</o:Description> | |||
<o:Tags>siddur</o:Tags> | |||
<o:Contact>efraim@opensiddur.org</o:Contact> | |||
<o:Url type="application/xhtml+xml" | |||
template="{$source}?q={{searchTerms}}&start={{startIndex?}}&max-results={{count?}}" | |||
/> | |||
</o:OpenSearchDescription> | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<TestSuite | |||
xmlns:tei="http://www.tei-c.org/ns/1.0" | |||
xmlns:j="http://jewishliturgy.org/ns/jlptei/1.0" | |||
xmlns:jx="http://jewishliturgy.org/ns/jlp-processor" | |||
xmlns:o="http://a9.com/-/spec/opensearch/1.1/" | |||
xmlns:http="http://expath.org/ns/http-client"> | |||
<suiteName>Data API index test</suiteName> | |||
<description> | |||
<p>Test the data API index</p> | |||
<author>Efraim Feinstein</author> | |||
<copyright>Copyright 2012 Efraim Feinstein, | |||
Licensed under the GNU Lesser General Public License, version 3 or later</copyright> | |||
</description> | |||
<setup/> | |||
<namespace prefix="html">http://www.w3.org/1999/xhtml</namespace> | |||
<namespace prefix="o">http://a9.com/-/spec/opensearch/1.1/</namespace> | |||
<imports> | |||
import module namespace dindex="http://jewishliturgy.org/api/data/index" | |||
at "xmldb:exist:///code/api/data/dindex.xqm"; | |||
</imports> | |||
<TestSet> | |||
<testName>dindex:list()</testName> | |||
<test> | |||
<task>GET</task> | |||
<code><![CDATA[ | |||
dindex:list() | |||
]]></code> | |||
<class href="../common.t.xml#SerializeHTML5"/> | |||
<xpath desc="returns a results class">.//html:*[@class='results']</xpath> | |||
<xpath desc="returns at least one result class">count(.//html:li[@class='result']) >= 1</xpath> | |||
</test> | |||
</TestSet> | |||
<TestSet> | |||
<testName>dindex:open-search()</testName> | |||
<test> | |||
<task>GET, no source</task> | |||
<code><![CDATA[ | |||
dindex:open-search("") | |||
]]></code> | |||
<xpath desc="An OpenSearch description is returned">self::o:OpenSearchDescription</xpath> | |||
</test> | |||
</TestSet> | |||
</TestSuite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,9 +1,35 @@ | |||
xquery version "1.0"; | xquery version "3.0"; | ||
(: this controller simply redirects to /code/api :) | (: This controller behaves like a fill-in for RESTXQ. | ||
: It does not do content negotiation. | |||
: Copyright 2012 Efraim Feinstein <efraim@opensiddur.org> | |||
: Licensed under the GNU Lesser General Public License, version 3 or later | |||
:) | |||
import module namespace api="http://jewishliturgy.org/modules/api" | |||
at "xmldb:exist:///code/api/modules/api.xqm"; | |||
import module namespace dindex="http://jewishliturgy.org/api/data/index" | |||
at "xmldb:exist:///code/api/data/dindex.xqm"; | |||
|
|||
declare namespace exist="http://exist.sourceforge.net/NS/exist"; | declare namespace exist="http://exist.sourceforge.net/NS/exist"; | ||
|
|
||
declare variable $exist:path external; | declare variable $exist:path external; | ||
declare variable $exist:resource external; | |||
|
|
||
<exist:dispatch> | let $uri := request:get-uri() | ||
<exist:redirect url="/code/api/data/{$exist:path}"/> | let $authenticated := | ||
</exist:dispatch> | (: log in if you can, otherwise, let the access be checked | ||
: by the called function | |||
:) | |||
api:request-authentication() | |||
return | |||
api:rest-response( | |||
switch (api:get-method()) | |||
case "GET" | |||
return | |||
if ($exist:resource="OpenSearchDescription") | |||
then | |||
dindex:open-search(request:get-parameter("source", "")) | |||
else | |||
dindex:list() | |||
default | |||
return api:rest-error(405, "Method not allowed") | |||
) |