module namespace menu = "http://www.architextus.com/xquery/library/how2_menus"; import module namespace app = "http://www.architextus.com/xquery/library/how2_appvars" at "How2_AppVars.xqm"; import module namespace content-refs = "http://www.architextus.com/xquery/library/how2_contentrefs" at "How2_ContentRefs.xqm"; import module namespace error = "http://www.architextus.com/xquery/library/how2_error" at "How2_ErrorMngr.xqm"; import module namespace filter = "http://www.architextus.com/xquery/library/how2_filter" at "How2_Filter.xqm"; declare namespace rest="http://exquery.org/ns/restxq"; declare %rest:path("/xml-menu/{$menu-id}") %rest:GET %rest:query-param("lang", "{$lang}", 'en-us') function menu:xml-get-menu($menu-id as xs:string, $lang as xs:string) as node()*{ for $x in app:open-db($lang)//menu[@id=$menu-id] return $x }; declare %rest:path("/menus/preprocess-menus") %rest:GET %rest:query-param("lang", "{$lang}", 'en-us') %output:method("html") %output:html-version("5.0") updating function menu:preprocess-menus($lang as xs:string*){ let $add-id-xsl := app:get-translation-preparation-xsl() for $lg in $lang return (if (db:exists($lg)) then let $menus := db:open($lg)//*[name()='menu'] for $menu in $menus let $prompted-menu := content-refs:resolve-references($menu, , $lg, 'no') let $prompted-menu-with-ids := xslt:transform($prompted-menu, $add-id-xsl) return (db:replace("processed-menus", concat($lg, '/', $menu/data(@id), '.xml'), document{$prompted-menu-with-ids}), if ($lg=$lang[last()] and $menu=$menus[last()]) then db:output(

Done

) else ()) else (db:replace("processed-menus", concat($lg, "-stub.xml"), document{}), if ($lg=$lang[last()]) then db:output(

Done

) else ())) }; declare %rest:path("/xml-menu-filtered/{$menu-id}") %rest:GET %rest:query-param("application", "{$application}", '') %rest:query-param("carrier", "{$carrier}", '') %rest:query-param("country", "{$country}", '') %rest:query-param("lang", "{$lang}", 'en-us') %rest:query-param("model", "{$model}", '') %rest:query-param("os", "{$os}", '') %rest:query-param("submenu-id", "{$submenu-id}", '0') %rest:query-param("keywords", "{$keywords}", '') %rest:query-param("static", "{$static}", '') function menu:xml-filtered-get-menu($menu-id as xs:string, $submenu-id as xs:string, $application as xs:string, $carrier as xs:string, $country as xs:string, $lang as xs:string, $model as xs:string, $os as xs:string, $keywords as xs:string, $static as xs:string) as node()*{ let $processed-menu-id := if (starts-with($menu-id, '0')) then (substring-after($menu-id, '0')) else $menu-id let $x := menu:xml-get-menu($processed-menu-id, $lang) let $prompted-content := if (db:exists('processed-menus') and $static = 'no') then if (exists(app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang])) then app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang] else content-refs:resolve-references($x, , $lang, $static) else content-refs:resolve-references($x, , $lang, $static) let $filtered-content := filter:filter-node($prompted-content, $application, $carrier, $country, $lang, $model, $os) return $filtered-content }; declare %rest:path("/menu/{$menu-id}/{$submenu-id}") %rest:GET %rest:query-param("application", "{$application}", '') %rest:query-param("carrier", "{$carrier}", '') %rest:query-param("country", "{$country}", '') %rest:query-param("lang", "{$lang}", 'en-us') %rest:query-param("model", "{$model}", '') %rest:query-param("os", "{$os}", '') %rest:query-param("static", "{$static}", 'no') %output:indent("no") %output:method("html") %output:html-version("5.0") function menu:html-get-menugroup($menu-id as xs:string, $submenu-id as xs:string, $application as xs:string, $carrier as xs:string, $country as xs:string, $lang as xs:string, $model as xs:string, $os as xs:string, $static as xs:string) as node()*{ let $x := menu:xml-get-menu($menu-id, $lang) let $prompted-content := if (db:exists('processed-menus') and $static = 'no') then if (exists(app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang])) then app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang] else content-refs:resolve-references($x, , $lang, $static) else content-refs:resolve-references($x, , $lang, $static) let $filtered-content := filter:filter-node($prompted-content, $application, $carrier, $country, $lang, $model, $os) (: To html: The context at the first level is the menu itself :) let $params := map{ "menu-id" :=$menu-id, "submenu-id" := $submenu-id, "application" := $application, "carrier" := $carrier, "country" := $country, "lang" := $lang, "model" := $model, "os" := $os, "rest-path" := $app:basex_rest_path, "restxq-path" := $app:basex_restxq_path, "static" := $static} let $stylesheet := doc(app:get-menu2html-xsl()) return xslt:transform($filtered-content, $stylesheet, $params) }; declare %rest:path("/menu/{$menu-id}") %rest:GET %rest:query-param("application", "{$application}", '') %rest:query-param("carrier", "{$carrier}", '') %rest:query-param("country", "{$country}", '') %rest:query-param("lang", "{$lang}", 'en-us') %rest:query-param("model", "{$model}", '') %rest:query-param("os", "{$os}", '') %rest:query-param("submenu-id", "{$submenu-id}", '0') %rest:query-param("static", "{$static}", 'no') %output:indent("no") %output:method("html") %output:html-version("5.0") function menu:html-get-menu($menu-id as xs:string, $application as xs:string, $carrier as xs:string, $country as xs:string, $lang as xs:string, $model as xs:string, $os as xs:string, $submenu-id as xs:string, $static as xs:string) as node()*{ if ($submenu-id != '0' and $submenu-id != '' and $submenu-id != $menu-id) (: Redirect when back action returns info about a submenu :) then menu:html-get-menugroup($menu-id, $submenu-id, $application, $carrier, $country, $lang, $model, $os, $static) else let $x := menu:xml-get-menu($menu-id, $lang) return if (normalize-space($x/@id) = "") then error:menu-not-found($menu-id, '', $lang) else (: Get prompt strings and icons :) let $prompted-content := if (db:exists('processed-menus') and $static = 'no') then if (exists(app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang])) then app:open-db('processed-menus')//*[name()='menu'][@id=$menu-id][@xml:lang=$lang] else content-refs:resolve-references($x, , $lang, $static) else content-refs:resolve-references($x, , $lang, $static) let $filtered-content := filter:filter-node($prompted-content, $application, $carrier, $country, $lang, $model, $os) (: To html: The context at the first level is the menu itself :) let $params := map{ "menu-id" :=$menu-id, "submenu-id" := $menu-id, "application" := $application, "carrier" := $carrier, "country" := $country, "lang" := $lang, "model" := $model, "os" := $os, "rest-path" := $app:basex_rest_path, "restxq-path" := $app:basex_restxq_path, "static" := $static} let $stylesheet := doc(app:get-menu2html-xsl()) return xslt:transform($filtered-content, $stylesheet, $params) }; declare %rest:path("/full-menu/{$menu-id}") %rest:GET %rest:query-param("application", "{$application}", '') %rest:query-param("carrier", "{$carrier}", '') %rest:query-param("country", "{$country}", '') %rest:query-param("lang", "{$lang}", 'en-us') %rest:query-param("model", "{$model}", '') %rest:query-param("os", "{$os}", '') %rest:query-param("submenu-id", "{$submenu-id}", '0') %rest:query-param("static", "{$static}", 'no') %output:indent("no") %output:method("html") %output:html-version("5.0") function menu:html-get-full-menu($menu-id as xs:string, $application as xs:string, $carrier as xs:string, $country as xs:string, $lang as xs:string, $model as xs:string, $os as xs:string, $submenu-id as xs:string, $static as xs:string) as node()*{ (: As div... created for review html --> PDF, for languages where FOP doesn't support all characters :) (: Get filtered menu :) let $filtered-menu := menu:xml-filtered-get-menu($menu-id, $menu-id, $application, $carrier, $country, $lang, $model, $os, '', $static) (: Display menu :) let $params := map{ "menu-id" :=$menu-id, "submenu-id" := $menu-id, "application" := $application, "carrier" := $carrier, "country" := $country, "lang" := $lang, "model" := $model, "os" := $os, "rest-path" := $app:basex_rest_path, "restxq-path" := $app:basex_restxq_path} let $stylesheet := doc(app:get-menu2htmlreview-xsl()) let $result := xslt:transform($filtered-menu, $stylesheet, $params) return $result }; declare %rest:path("/full-menu-static-search-index/{$menu-id}") %rest:GET %rest:query-param("application", "{$application}", '') %rest:query-param("carrier", "{$carrier}", '') %rest:query-param("country", "{$country}", '') %rest:query-param("lang", "{$lang}", 'en-us') %rest:query-param("model", "{$model}", '') %rest:query-param("os", "{$os}", '') %rest:query-param("submenu-id", "{$submenu-id}", '0') %rest:query-param("static", "{$static}", 'yes') %output:indent("no") %output:method("xml") function menu:html-get-full-menu-static-search-index($menu-id as xs:string, $application as xs:string, $carrier as xs:string, $country as xs:string, $lang as xs:string, $model as xs:string, $os as xs:string, $submenu-id as xs:string, $static as xs:string) as node()*{ (: As div... created for review html --> PDF, for languages where FOP doesn't support all characters :) (: Get filtered menu :) let $filtered-menu := menu:xml-filtered-get-menu($menu-id, $menu-id, $application, $carrier, $country, $lang, $model, $os, '', $static) (: Display menu :) let $params := map{ "menu-id" :=$menu-id, "submenu-id" := $menu-id, "application" := $application, "carrier" := $carrier, "country" := $country, "lang" := $lang, "model" := $model, "os" := $os, "rest-path" := $app:basex_rest_path, "restxq-path" := $app:basex_restxq_path} let $stylesheet := doc(concat($app:app-resource-location, 'ScriptsAndStyles/HowToTransform_MenuStaticSearchIndex.xsl')) let $result := xslt:transform($filtered-menu, $stylesheet, $params) return $result };