Changeset 258
- Timestamp:
- 03/19/10 14:32:10 (14 years ago)
- Location:
- MDService/trunk/xquery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService/trunk/xquery/cmd-model.xql
r256 r258 20 20 else 21 21 $cmd-index, 22 $format := request:get-parameter("format", "xml"),22 $format := request:get-parameter("format", $cmd-model:responseFormatXml), 23 23 $collection := fn:concat("/db/cmdi-mirror/", request:get-parameter("collection", "silang_data")), 24 24 $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1)) 25 25 return 26 26 if ($operation eq $cmd-model:getCollections) then 27 (:cmd-model:get-collections() :) <error>Unimplemented</error>27 cmd-model:get-collections($collection, $format, $max-depth) 28 28 else if ($operation eq $cmd-model:queryModel) then 29 29 cmd-model:query-model($cmd-index-path, $collection, $format, $max-depth) -
MDService/trunk/xquery/cmd-model.xqm
r256 r258 23 23 declare variable $cmd-model:docTypeTerms as xs:string := "Terms"; 24 24 declare variable $cmd-model:docTypeSuffix as xs:string := "Values"; 25 26 declare variable $cmd-model:responseFormatXml as xs:string := "xml"; 27 declare variable $cmd-model:responseFormatJSon as xs:string := "json"; 28 declare variable $cmd-model:responseFormatText as xs:string := "text"; 25 29 26 30 declare variable $cmd-model:xmlExt as xs:string := ".xml"; … … 70 74 71 75 (: 76 Recurse for collections 77 :) 78 declare function cmd-model:recurse-collections($collection as xs:string, $depth as xs:integer) as item()* { 79 let $children := xdb:get-child-collections($collection) 80 return 81 if (fn:exists($children)) then 82 let $child-results := 83 for $child in $children 84 return 85 cmd-model:recurse-collections(concat($collection, '/', xs:string($child)), $depth), 86 $current := <Collection>{$collection}</Collection> 87 return ($current, $child-results) 88 else 89 <Collection>{$collection}</Collection> 90 }; 91 92 (: 72 93 73 94 :) … … 174 195 }; 175 196 197 (: 198 Seraliseringsformat. 199 :) 200 declare function cmd-model:serialise-as($item as node(), $format as xs:string) as item()? { 201 if ($format eq $cmd-model:responseFormatJSon) then 202 let $option := util:declare-option("exist:serialize", "method=text media-type=application/json") 203 return 204 (: json:xml-to-json($item) :) $item 205 else (: $cmd-model:responseFormatXml, $cmd-model:responseFormatText:) 206 $item 207 }; 208 209 176 210 (:~ 177 211 API function queryModel. 178 212 :) 179 declare function cmd-model:query-model($cmd-index-path as xs:string, $collection as xs:string+, $format as xs:string, $max-depth as xs:integer) as node() { 180 if ($format eq "json") then 181 let $option := util:declare-option("exist:serialize", "method=text media-type=application/json") 182 return 183 (: json:xml-to-json( :) cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth) (:) :) 184 else 185 cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth) 186 }; 213 declare function cmd-model:query-model($cmd-index-path as xs:string, $collection as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() { 214 cmd-model:serialise-as(cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth), $format) 215 }; 216 217 (:~ 218 API function getCollections. 219 :) 220 declare function cmd-model:get-collections($collections as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() { 221 let $children := for $collection-item in $collections 222 return 223 cmd-model:recurse-collections($collection-item, $max-depth) 224 return 225 cmd-model:serialise-as(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $format) 226 227 };
Note: See TracChangeset
for help on using the changeset viewer.