Created
November 1, 2012 17:53
-
-
Save adamfowleruk/3995365 to your computer and use it in GitHub Desktop.
article controller main function
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
declare function c:main() as item()* | |
{ | |
let $acount := xdmp:estimate((fn:doc()/article)) | |
return | |
( | |
ch:add-value("articlecount",$acount), | |
ch:add-value("title", "Articles") | |
) | |
}; |
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
xquery version "1.0-ml"; | |
import module namespace vh = "http://marklogic.com/roxy/view-helper" | |
at "/roxy/lib/view-helper.xqy"; | |
declare option xdmp:mapping "false"; | |
<div xmlns="http://www.w3.org/1999/xhtml" class="articles main"> | |
<h2>{fn:string(vh:get("title"))}</h2> | |
<p>There are currently {fn:string(vh:get("articlecount"))} | |
articles in the database. | |
</p> | |
<form action="/articles/doupload.html" method="POST" | |
enctype="multipart/form-data"> | |
<h2>Upload article XML</h2> | |
<label for="upload">File: </label> | |
<input type="file" id="upload" name="upload" size="50"/> | |
<br/> | |
<input type="submit" value="Upload"/> | |
</form> | |
</div> |
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
(: Must be invoked with a POST in order to be allowed to add a doc :) | |
declare function c:doupload() as item()* | |
{ | |
(: 1. upload doc :) | |
let $file := xdmp:get-request-field("upload") | |
(: Now get XML described doc from our file upload :) | |
let $xml := xdmp:unquote($file,"","repair-full") | |
let $uri := fn:concat("/articles/",xdmp:random(),".xml") | |
let $docresult := | |
xdmp:document-insert($uri,$xml,xdmp:default-permissions(), | |
(xdmp:default-collections(),"articles") | |
) | |
return | |
xdmp:redirect-response("/articles") | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment