Index: openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl 3 Sep 2024 15:37:34 -0000 1.2 +++ openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl 22 Oct 2024 09:37:22 -0000 1.3 @@ -101,6 +101,7 @@ # loading order. The commands are executed very early, this means # that, e.g., util::which is not yet available. # +::acs::register_icanuse "domDoc asTclValue" [expr {[apm_version_names_compare [package require tdom] 0.9.5] >= 0}] ::acs::register_icanuse "gnugrep" [acs::cmd_error_contains [list exec grep -V] GNU] ::acs::register_icanuse "ns_asynclogfile" {[info commands ::ns_asynclogfile] ne ""} ::acs::register_icanuse "ns_baseunit" {[info commands ::ns_baseunit] ne ""} Index: openacs-4/packages/acs-tcl/tcl/json-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/json-procs.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/acs-tcl/tcl/json-procs.tcl 11 Sep 2024 06:15:48 -0000 1.13 +++ openacs-4/packages/acs-tcl/tcl/json-procs.tcl 22 Oct 2024 09:37:22 -0000 1.14 @@ -653,60 +653,64 @@ return [join $output \n] } -ad_proc util::tdomDoc2dict {doc} { +if {![::acs::icanuse "domDoc asTclValue"]} { - Helper proc for util::json2dict, which outputsreturns the provided - tDOM document in the form of a Tcl dict. + ad_proc -private util::tdomNodes2dict { nodes parentType } { -} { - return [util::tdomNodes2dict [$doc childNodes] [$doc jsonType]] -} + Helper proc for util::json2dict, which returns the tDOM structure + in the form of a Tcl dict. + Use this proc only on dom structures created with "porse -json", + since it depends on the internal node structure of tDOM. It would + be certainly better to have this function built-in in tDOM (call + like "asDict", similar to "asXML") -ad_proc -private util::tdomNodes2dict { nodes parentType } { + @return dict + @author Gustaf Neumann + } { + set result "" + foreach n $nodes { + set children [$n childNodes] + set jsonType [$n jsonType] + set childrendValue [util::tdomNodes2dict $children $jsonType] - Helper proc for util::json2dict, which returns the tDOM structure - in the form of a Tcl dict. - - Use this proc only on dom structures created with "porse -json", - since it depends on the internal node structure of tDOM. It would - be certainly better to have this function built-in in tDOM (call - like "asDict", similar to "asXML") - - @return dict - @author Gustaf Neumann -} { - set result "" - foreach n $nodes { - set children [$n childNodes] - set jsonType [$n jsonType] - set childrendValue [util::tdomNodes2dict $children $jsonType] - - switch $jsonType { - OBJECT { - if {[$n nodeName] ne "objectcontainer" || $parentType eq "OBJECT"} { - lappend result [$n nodeName] + switch $jsonType { + OBJECT { + if {[$n nodeName] ne "objectcontainer" || $parentType eq "OBJECT"} { + lappend result [$n nodeName] + } + lappend result $childrendValue } - lappend result $childrendValue + NONE { + lappend result [$n nodeName] $childrendValue + } + ARRAY { + if {[$n nodeName] ne "arraycontainer" || $parentType eq "OBJECT"} { + lappend result [$n nodeName] + } + lappend result $childrendValue + } + default { + set op [expr {[llength $nodes] > 1 ? "lappend" : "set"} ] + $op result [$n nodeValue] + } } - NONE { - lappend result [$n nodeName] $childrendValue - } - ARRAY { - if {[$n nodeName] ne "arraycontainer" || $parentType eq "OBJECT"} { - lappend result [$n nodeName] - } - lappend result $childrendValue - } - default { - set op [expr {[llength $nodes] > 1 ? "lappend" : "set"} ] - $op result [$n nodeValue] - } } + return $result } - return $result } +ad_proc util::tdomDoc2dict {doc} { + + Helper proc for util::json2dict, which outputsreturns the provided + tDOM document in the form of a Tcl dict. + +} { + expr {[::acs::icanuse "domDoc asTclValue"] + ? [$doc asTclValue] + : [util::tdomNodes2dict [$doc childNodes] [$doc jsonType]] } +} + ad_proc util::json2dict { jsonText } { Parse JSON text into a Tcl dict. @@ -722,7 +726,9 @@ } { #ns_log notice "PARSE\n$jsonText" set doc [dom parse -json -- $jsonText] - set result [util::tdomDoc2dict $doc] + set result [expr {[::acs::icanuse "domDoc asTclValue"] + ? [$doc asTclValue] + : [util::tdomDoc2dict $doc]}] $doc delete return $result } Index: openacs-4/packages/acs-tcl/tcl/test/json-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/json-test-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-tcl/tcl/test/json-test-procs.tcl 3 Sep 2024 15:37:34 -0000 1.2 +++ openacs-4/packages/acs-tcl/tcl/test/json-test-procs.tcl 22 Oct 2024 09:37:22 -0000 1.3 @@ -8,7 +8,6 @@ -cats {api smoke} \ -procs { util::json2dict - util::tdomNodes2dict } \ json_to_dict {