proc getExitHandler
::xowiki::policy5 proc getExitHandler {} {::nsf::exithandler get}
proc setExitHandler
::xowiki::policy5 proc setExitHandler newbody {::nsf::exithandler set $newbody}
proc unsetExitHandler
::xowiki::policy5 proc unsetExitHandler {} {::nsf::exithandler unset}
instproc __api_make_doc
::xowiki::policy5 instproc __api_make_doc {inst proc_name} {
upvar doc doc private private public public deprecated deprecated
if {$doc eq ""} {
set doc_elements(main) ""
} else {
ad_parse_documentation_string $doc doc_elements
}
set defaults [list]
foreach a [my info ${inst}args $proc_name] {
if {[my info ${inst}default $proc_name $a d]} {lappend defaults $a $d}
}
set public [expr {$private ? false : true}]
set doc_elements(public_p) $public
set doc_elements(private_p) $private
set doc_elements(deprecated_p) $deprecated
set doc_elements(warn_p) $deprecated
set doc_elements(varargs_p) [expr {[lsearch args [my info ${inst}args $proc_name]]>-1}]
set doc_elements(flags) [list]
set doc_elements(switches) [list]
foreach f [my info ${inst}nonposargs $proc_name] {
set pair [split [lindex $f 0 0] :]
set sw [string range [lindex $pair 0] 1 end]
lappend doc_elements(switches) $sw
lappend doc_elements(flags) $sw [lindex $pair 1]
#my log "default_value $proc_name: $sw -> '[lindex $f 1]' <$pair/$f>"
if {[lindex $pair 1] eq "switch" && [lindex $f 1] eq ""} {
set default "false"
} else {
set default [lindex $f 1]
}
#my log "default_value $proc_name: $sw -> 'default' <$pair/$f>"
lappend defaults $sw $default
}
set doc_elements(default_values) $defaults
set doc_elements(positionals) [my info ${inst}args $proc_name]
# argument documentation finished
set scope [::xotcl::api scope]
set doc_elements(script) [::xotcl::api script_name $scope]
set proc_index [::xotcl::api proc_index $scope [self] ${inst}proc $proc_name]
if {![nsv_exists api_proc_doc $proc_index]} {
nsv_lappend api_proc_doc_scripts $doc_elements(script) $proc_index
}
#my log "doc_elements=[array get doc_elements]"
#my log "SETTING api_proc_doc '$proc_index'"
nsv_set api_proc_doc $proc_index [array get doc_elements]
}
instproc __api_make_forward_doc
::xowiki::policy5 instproc __api_make_forward_doc {inst method_name} {
upvar doc doc private private public public deprecated deprecated
if {$doc eq ""} {
set doc_elements(main) ""
} else {
ad_parse_documentation_string $doc doc_elements
#my log "doc_elements=[array get doc_elements]"
}
set defaults [list]
set public [expr {$private ? false : true}]
set doc_elements(public_p) $public
set doc_elements(private_p) $private
set doc_elements(deprecated_p) $deprecated
set doc_elements(warn_p) $deprecated
set doc_elements(varargs_p) false
set doc_elements(flags) [list]
set doc_elements(switches) [list]
set doc_elements(default_values) [list]
set doc_elements(positionals) [list]
# argument documentation finished
set scope [::xotcl::api scope]
set doc_elements(script) [::xotcl::api script_name $scope]
set proc_index [::xotcl::api proc_index $scope [self] ${inst}forward $method_name]
if {![nsv_exists api_proc_doc $proc_index]} {
nsv_lappend api_proc_doc_scripts $doc_elements(script) $proc_index
}
#my log "doc_elements=[array get doc_elements]"
#my log "SETTING api_proc_doc '$proc_index'"
nsv_set api_proc_doc $proc_index [array get doc_elements]
}
instproc __timediff
::xowiki::policy5 instproc __timediff {} {
set now [ns_time get]
if {[ns_conn isconnected]} {
set start_time [ns_conn start]
} else {
if {![info exists ::__start_time]} {set ::__start_timestamp $now}
set start_time $::__start_timestamp
}
set t [ns_time diff $now $start_time]
set ms [expr {[ns_time seconds $t]*1000 + [ns_time microseconds $t]/1000}]
if {[info exists ::__last_timestamp]} {
set t [ns_time diff $now $::__last_timestamp]
set dms [expr {[ns_time seconds $t]*1000 + [ns_time microseconds $t]/1000}]
set diff ", ${dms}ms"
} else {
set diff ""
}
set ::__last_timestamp $now
return "${ms}ms$diff"
}
instproc abstract
::xowiki::policy5 instproc abstract {methtype methname arglist} {
if {$methtype ne "proc" && $methtype ne "instproc" && $methtype ne "method"} {
error "invalid method type '$methtype', must be either 'proc', 'instproc' or 'method'."
}
:$methtype $methname $arglist "
if {!\[::xotcl::self isnextcall\]} {
error \"Abstract method $methname $arglist called\"
} else {::xotcl::next}
"
}
instproc ad_doc
::xowiki::policy5 instproc ad_doc doc_string {
ad_parse_documentation_string $doc_string doc_elements
set scope [::xotcl::api scope]
set doc_elements(script) [::xotcl::api script_name $scope]
set proc_index [::xotcl::api object_index $scope [self]]
#if {![nsv_exists api_proc_doc $proc_index]} {
# nsv_lappend api_proc_doc_scripts $doc_elements(script) $proc_index
#}
set doc_elements(public_p) true
set doc_elements(private_p) false
set doc_elements(varargs_p) false
set doc_elements(deprecated_p) false
set doc_elements(warn_p) false
set doc_elements(default_values) ""
set doc_elements(switches) ""
set doc_elements(positionals) ""
set doc_elements(flags) ""
nsv_set api_proc_doc $proc_index [array get doc_elements]
nsv_set api_library_doc $proc_index [array get doc_elements]
set file_index $doc_elements(script)
if {[nsv_exists api_library_doc $file_index]} {
array set elements [nsv_get api_library_doc $file_index]
}
set oldDoc [expr {[info exists elements(main)] ? [lindex $elements(main) 0] : ""}]
set prefix "This file defines the following Objects and Classes"
set entry [::xotcl::api object_link $scope [self]]
if {![string match *$prefix* $oldDoc]} {
append oldDoc "<p>$prefix: $entry"
} else {
append oldDoc ", $entry"
}
set elements(main) [list $oldDoc]
#my log "elements = [array get elements]"
nsv_set api_library_doc $file_index [array get elements]
}
instproc ad_forward
::xowiki::policy5 instproc ad_forward {{-private:switch false} {-deprecated:switch false} {-warn:switch false} {-debug:switch false} method_name doc args} {
uplevel [self] forward $method_name $args
my __api_make_forward_doc "" $method_name
}
instproc ad_proc
::xowiki::policy5 instproc ad_proc {{-private:switch false} {-deprecated:switch false} {-warn:switch false} {-debug:switch false} proc_name arguments doc body} {
uplevel [list [self] proc $proc_name $arguments $body]
my __api_make_doc "" $proc_name
}
instproc asHTML
::xowiki::policy5 instproc asHTML {{-master defaultMaster} -page:switch} {
require_html_procs
dom createDocument html doc
set root [$doc documentElement]
if {!$page} {
$root appendFromScript {my render}
set n [$root childNode]
if {$n eq ""} {
return ""
}
return [$n asHTML]
} else {
set slave [$master decorate $root]
$slave appendFromScript {my render}
ns_return 200 text/html [$root asHTML]
}
}
instproc check
::xowiki::policy5 instproc check checkoptions {
::nsf::method::assertion [self] check [::xotcl::checkoption_xotcl1_to_internal $checkoptions]
}
instproc debug
::xowiki::policy5 instproc debug msg {
ns_log debug "[self] [self callingclass]->[self callingproc]: $msg"
}
instproc destroy_on_cleanup
::xowiki::policy5 instproc destroy_on_cleanup {} {
#my log "--cleanup adding ::xo::cleanup([self]) [list [self] destroy]"
set ::xo::cleanup([self]) [list [self] destroy]
}
instproc ds
::xowiki::policy5 instproc ds msg {
ds_comment "[self]: $msg, ([self callingclass]->[self callingproc] [my __timediff])"
}
instproc extractConfigureArg
::xowiki::policy5 instproc extractConfigureArg {al name {cutTheArg 0}} {
set value ""
upvar $al argList
set largs [llength $argList]
for {set i 0} {$i < $largs} {incr i} {
if {[lindex $argList $i] == $name && $i + 1 < $largs} {
set startIndex $i
set endIndex [expr {$i + 1}]
while {$endIndex < $largs &&
[string first - [lindex $argList $endIndex]] != 0} {
lappend value [lindex $argList $endIndex]
incr endIndex
}
}
}
if {[info exists startIndex] && $cutTheArg != 0} {
set argList [lreplace $argList $startIndex [expr {$endIndex - 1}]]
}
return $value
}
instproc filtersearch
::xowiki::policy5 instproc filtersearch filter {
set handle [::nsf::directdispatch [::nsf::current object] ::nsf::methods::object::info::lookupfilter $filter]
return [method_handle_to_xotcl $handle]
}
instproc forward
::xowiki::policy5 instproc forward {-default -earlybinding:switch -methodprefix -objscope:switch -onerror -verbose:switch method target args} {
set arglist [list]
if {[info exists default]} {lappend arglist -default $default}
if {$earlybinding} {lappend arglist "-earlybinding"}
if {[info exists methodprefix]} {lappend arglist -methodprefix $methodprefix}
if {$objscope} {lappend arglist "-objframe"}
if {[info exists onerror]} {lappend arglist -onerror $onerror}
if {$verbose} {lappend arglist -verbose}
if {[info exists target]} {lappend arglist $target}
if {[llength $args] > 0} {lappend arglist {*}$args}
set r [::nsf::method::forward [self] -per-object $method {*}$arglist]
return $r
}
instproc hasclass
::xowiki::policy5 instproc hasclass cl {
if {![::nsf::is class $cl]} {return 0}
if {[::nsf::directdispatch [self] ::nsf::methods::object::info::hasmixin $cl]} {return 1}
::nsf::directdispatch [self] ::nsf::methods::object::info::hastype $cl
}
instproc init
::xowiki::policy5 instproc init args {
if {![::nsf::current isnextcall] && [llength $args] > 0 && [::nsf::configure debug] > 0} {
::nsf::log Warning "Arguments '$args' to constructor of object [self] are most likely not processed"
}
}
instproc isclass
::xowiki::policy5 instproc isclass {{class {[self]}}} {::nsf::is class $class}
instproc ismetaclass
::xowiki::policy5 instproc ismetaclass {{class {[self]}}} {::nsf::is metaclass $class}
instproc ismixin
::xowiki::policy5 instproc ismixin class {
return [expr {[::nsf::is class $class] &&
[my ::nsf::methods::object::info::hasmixin $class]}]
}
instproc isobject
::xowiki::policy5 instproc isobject {{object {[self]}}} {::nsf::object::exists $object}
instproc istype
::xowiki::policy5 instproc istype class {
return [expr {[::nsf::is class $class] &&
[::nsf::directdispatch [self] ::nsf::methods::object::info::hastype $class]}]
}
instproc log
::xowiki::policy5 instproc log msg {
ns_log notice "$msg, [self] [self callingclass]->[self callingproc] ([my __timediff])"
}
instproc method
::xowiki::policy5 instproc method {name arguments body} {
:proc $name $arguments $body
}
instproc msg
::xowiki::policy5 instproc msg {{-html false} msg} {
if {[ns_conn isconnected]} {
set msg "[self]: $msg ([self callingclass]->[self callingproc])"
if {$html} {
util_user_message -html -message $msg
} else {
util_user_message -message $msg
}
}
}
instproc objectparameter
::xowiki::policy5 instproc objectparameter {} {
set parameterDefinitions [list]
set class [nsf::directdispatch [self] ::nsf::methods::object::info::class]
foreach slot [nsf::directdispatch $class ::nsf::methods::class::info::slotobjects -closure -type ::nx::Slot] {
lappend parameterDefinitions [$slot getParameterSpec]
}
lappend parameterDefinitions args:alias,method=residualargs,args
return $parameterDefinitions
}
instproc proc
::xowiki::policy5 instproc proc {name arguments body precondition postcondition} {
set conditions [list]
if {[info exists precondition]} {lappend conditions -precondition $precondition}
if {[info exists postcondition]} {lappend conditions -postcondition $postcondition}
::nsf::method::create [self] -per-object $name $arguments $body {*}$conditions
}
instproc procsearch
::xowiki::policy5 instproc procsearch name {
set handle [::nsf::directdispatch [::nsf::current object] ::nsf::methods::object::info::lookupmethod $name]
return [method_handle_to_xotcl $handle]
}
instproc qn
::xowiki::policy5 instproc qn query_name {
set qn "dbqd.[my uplevel [list self class]]-[my uplevel [list self proc]].$query_name"
return $qn
}
instproc self
::xowiki::policy5 instproc self {} ::xotcl::self
instproc serialize
::xowiki::policy5 instproc serialize {} {
::Serializer deepSerialize [self]
}
instproc set_instance_vars_defaults
::xowiki::policy5 instproc set_instance_vars_defaults {} :configure
instproc show-object
::xowiki::policy5 instproc show-object {} {
#
# Allow to show an arbitrary object via API-browser. Per-default,
# e.g. site-wide can use e.g. /xowiki/index?m=show-object
#
set form [rp_getform]
ns_set update $form object [self]
ns_set update $form show_source [::xo::cc query_parameter "show_source" 1]
ns_set update $form show_methods [::xo::cc query_parameter "show_methods" 2]
ns_set update $form show_variables [::xo::cc query_parameter "show_variables" 1]
rp_internal_redirect /packages/xotcl-core/www/show-object
}
instproc unknown
::xowiki::policy5 instproc unknown {m args} {
if {![self isnext]} {
error "[self]: unable to dispatch method '$m'"
}
}
instproc vwait
::xowiki::policy5 instproc vwait varName {
if {[regexp {:[^:]*} $varName]} {
error "invalid varName '$varName'; only plain or fully qualified variable names allowed"
}
if {[string match ::* $varName]} {
::vwait $varName
} else {
::vwait :$varName
}
}