@@ -655,7 +655,7 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
655655
656656 let $default-group := ($import-configs/self::*:configuration/@default-group , "Default" )[1 ]
657657 for $group in fn:distinct-values ((
658- $import-configs/descendant-or-self::gr:group /gr:group-name,
658+ $import-configs/descendant-or-self::gr:group /gr:group-name/ fn:string () ,
659659 $import-configs/descendant-or-self::*/(
660660 self::gr:http-server, self::gr:xdbc-server,
661661 self::gr:odbc-server, self::gr:task-server, self::db:database
@@ -678,7 +678,7 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
678678 let $databases := $import-configs/descendant-or-self::db:database[
679679 @group = $group or ( $group = $default-group and fn:empty (@group ) )
680680 ]
681- let $group-config := $import-configs/descendant-or-self::gr:group [gr:group-name = $group]
681+ let $group-config := $import-configs/descendant-or-self::gr:group [gr:group-name/ fn:string () = $group]
682682 where fn:exists ($servers | $databases | $group-config)
683683 return
684684 <group>
@@ -727,7 +727,7 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
727727 let $_ :=
728728 if ($silent) then ()
729729 else
730- for $group in $config/gr:groups/gr:group /gr:group-name
730+ for $group in $config/gr:groups/gr:group /gr:group-name/ fn:string ()
731731 let $hosts := ($config/ho:hosts/ho:host[ho:group /@name = $group], try { xdmp:group-hosts (xdmp:group ($group)) } catch ($ignore) {})
732732 where fn:empty ($hosts)
733733 return
@@ -740,6 +740,43 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
740740 return if ($keep-comments) then $config else setup:suppress-comments ($config)
741741};
742742
743+ declare function setup:split-config ($config as element (configuration), $app-name as xs:string) as node ()* {
744+ for $part in (
745+ $config/*/*,
746+ $config/gr:groups/gr:group /(
747+ (gr:http-servers, gr:xdbc-servers, gr:odbc-servers)/*,
748+ gr:task-server
749+ )
750+ )
751+ let $type := fn:local-name ($part)
752+
753+ let $name :=
754+ if ($part instance of element (gr:task-server)) then
755+ "TaskServer"
756+ else
757+ $part/*[local-name () = ("name" , "forest-name" , "local-name" , concat ($type, "-name" ))][1 ]
758+ /fn:replace (fn:replace (fn:string (), "^(.*/)?([^/]+)" , "$2" ), "^\$\{group\}$" , "default-group" )
759+
760+ let $path := fn:replace (fn:replace ($type, "(http|xdbc|odbc|task)-" , "" ) || "s" , "ys$" , "ies" )
761+ let $path :=
762+ if (fn:contains (fn:namespace-uri ($part), "security" )) then
763+ "security/" || $path
764+ else
765+ fn:replace ($path, "assignments/" , "forests/" )
766+
767+ let $file := fn:replace ($name, "(@ml.|[${}])" , "" ) || ".xml"
768+
769+ return (
770+ comment { "SAVE-PART-AS:" || $path || "/" || $file },
771+ typeswitch ($part)
772+ case element (gr:group )
773+ return element gr:group {
774+ $part/@*,
775+ $part/(node () except (gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server))
776+ }
777+ default return $part
778+ )
779+ };
743780
744781(:
745782 base-name : Original forest base name - this should be the name from the config.
0 commit comments