ATWF A Tcl Web Framwork

Check-in [404ee3bf92]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixes for renaming

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@606 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db

Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:404ee3bf928b8dd7f3b6a3ef1d0574e11752f8f3
User & Date: arnulf@wiedemann-pri.de 2010-12-03 19:01:32
Context
2010-12-03
21:21
remove debugging output

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@607 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: e10769921b user: arnulf@wiedemann-pri.de tags: trunk

19:01
fixes for renaming

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@606 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: 404ee3bf92 user: arnulf@wiedemann-pri.de tags: trunk

18:23
fixes for renaming

git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@605 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db check-in: c002cd617e user: arnulf@wiedemann-pri.de tags: trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/ATWF/Applications/Resources/Frontcontroller.tcl.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Applications::Resources::Frontcontroller {
    inherit ::ATWF::Applications::Resources::Resourcebase

     # @variable ::ATWF::Controller::Front
    protected variable _front [list]

    constructor {options} {
        chain $options
    } {
    }

................................................................................
    public method init {}
    public method getFrontController {}
}

  #============================ init ===========================================
  # Initialize Front Controller
  # 
  # @return ::ATWF::Controller::Front
::itcl::body Applications::Resources::Frontcontroller::init {} {
    set front [getFrontController]
        
    foreach {key value} [getOptions] {
        switch [string tolower $key] {
        controllerdirectory {
            if {![::itcl::is object $value] && ([llength $value] == 1)} {
................................................................................
          }
        throwexceptions {
            $front throwExceptions $value
          }
        actionhelperpaths {
            if {[llength $value] >= 2} {
                foreach {helperPrefix helperPath} $value {
                    ::ATWF::Controller::Action::HelperBroker::addPath $helperPath $helperPrefix
                }
            }
          }
        default {
            $front setParam $key $value
          }
        }
................................................................................

    return $front
}

  #============================ getFrontController =============================
  # Retrieve front controller instance
  # 
  # @return ::ATWF::Controller::Front
::itcl::body Applications::Resources::Frontcontroller::getFrontController {} {
    if {$_front eq ""} {
	classIsLoaded ::ATWF::Controllers::Front
        set _front [::ATWF::Controllers::Front::getInstance]
    }
    return $_front
}

} ; # END ::ATWF








|







 







|







 







|







 







|










25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Applications::Resources::Frontcontroller {
    inherit ::ATWF::Applications::Resources::Resourcebase

     # @variable ::ATWF::Controllers::Front
    protected variable _front [list]

    constructor {options} {
        chain $options
    } {
    }

................................................................................
    public method init {}
    public method getFrontController {}
}

  #============================ init ===========================================
  # Initialize Front Controller
  # 
  # @return ::ATWF::Controllers::Front
::itcl::body Applications::Resources::Frontcontroller::init {} {
    set front [getFrontController]
        
    foreach {key value} [getOptions] {
        switch [string tolower $key] {
        controllerdirectory {
            if {![::itcl::is object $value] && ([llength $value] == 1)} {
................................................................................
          }
        throwexceptions {
            $front throwExceptions $value
          }
        actionhelperpaths {
            if {[llength $value] >= 2} {
                foreach {helperPrefix helperPath} $value {
                    ::ATWF::Controllers::Actions::HelperBroker::addPath $helperPath $helperPrefix
                }
            }
          }
        default {
            $front setParam $key $value
          }
        }
................................................................................

    return $front
}

  #============================ getFrontController =============================
  # Retrieve front controller instance
  # 
  # @return ::ATWF::Controllers::Front
::itcl::body Applications::Resources::Frontcontroller::getFrontController {} {
    if {$_front eq ""} {
	classIsLoaded ::ATWF::Controllers::Front
        set _front [::ATWF::Controllers::Front::getInstance]
    }
    return $_front
}

} ; # END ::ATWF

Changes to library/ATWF/Applications/Resources/View.tcl.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #============================ init ===========================================
  # Defined by Application_Resource_Resource
  #
  # @return View
::itcl::body Applications::Resources::View::init {} {
    set view [getView]

    set viewRenderer [uplevel #0 ::ATWF::Controller::Action::Helper::ViewRenderer #auto]
    $viewRenderer setView $view
    ::ATWF::Controller::Action::HelperBroker::addHelper $viewRenderer
    return $view
}

  #============================ getView ========================================
  # Retrieve view object
  # 
  # @return View







|

|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #============================ init ===========================================
  # Defined by Application_Resource_Resource
  #
  # @return View
::itcl::body Applications::Resources::View::init {} {
    set view [getView]

    set viewRenderer [uplevel #0 ::ATWF::Controllers::Actions::Helpers::ViewRenderer #auto]
    $viewRenderer setView $view
    ::ATWF::Controllers::Actions::HelperBrokers::addHelper $viewRenderer
    return $view
}

  #============================ getView ========================================
  # Retrieve view object
  # 
  # @return View

Changes to library/ATWF/Controllers/Actions/HelperBroker.tcl.

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::HelperBroker {
     inherit ::ATWF::Base

     # _actionController - ActionController reference
     #
     # @variable Controller::Action
    protected variable _actionController [list]

     # @variable LoaderPluginLoader
    protected common _pluginLoader [list]

     # $_helpers - Helper array
     #
................................................................................
        
    return $_stack
}
    
  #============================ constructor ====================================
  # Constructor
  #
  # @param ::ATWF::Controller::Action actionController
  # @return void
::itcl::body Controllers::Actions::HelperBroker::constructor {actionController} {
    set _actionController $actionController
    foreach {className helper} [[getStack] getHelpersByName] {
        $helper setActionController $actionController
        $helper init
     }
................................................................................

  #============================ __call =========================================
  # Method overloading
  #
  # @param  string method
  # @param  array args
  # @return mixed
  # @throws ::ATWF::Controller::Action if helper does not have a direct() method
::itcl::body Controllers::Actions::HelperBroker::__call {method args} {
    set helper [getHelper $method]
    if {![methodExists $helper direct]} {
        return -code error "Helper \"$method\" does not support overloading via direct"
     }
    return [$helper direct $args]
}







|







 







|







 







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::HelperBroker {
     inherit ::ATWF::Base

     # _actionController - ActionController reference
     #
     # @variable Controllers::Actions
    protected variable _actionController [list]

     # @variable LoaderPluginLoader
    protected common _pluginLoader [list]

     # $_helpers - Helper array
     #
................................................................................
        
    return $_stack
}
    
  #============================ constructor ====================================
  # Constructor
  #
  # @param ::ATWF::Controllers::Action actionController
  # @return void
::itcl::body Controllers::Actions::HelperBroker::constructor {actionController} {
    set _actionController $actionController
    foreach {className helper} [[getStack] getHelpersByName] {
        $helper setActionController $actionController
        $helper init
     }
................................................................................

  #============================ __call =========================================
  # Method overloading
  #
  # @param  string method
  # @param  array args
  # @return mixed
  # @throws ::ATWF::Controllers::Actions if helper does not have a direct() method
::itcl::body Controllers::Actions::HelperBroker::__call {method args} {
    set helper [getHelper $method]
    if {![methodExists $helper direct]} {
        return -code error "Helper \"$method\" does not support overloading via direct"
     }
    return [$helper direct $args]
}

Changes to library/ATWF/Controllers/Actions/HelperBrokers/PriorityStack.tcl.

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
public method getHelpersByPriority {} { return $_helpersByPriority }
}

  #============================ __get ==========================================
  # Magic property overloading for returning helper by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controller::Action::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__get {helperName} {
    if {![dict exists $_helpersByNameRef $helperName]} {
        return false
    }
    
    return [dict get $_helpersByNameRef $helperName]
}
    
  #============================ __isset ========================================
  # Magic property overloading for returning if helper is set by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controller::Action::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__isset {helperName} {
    return [dict exists $_helpersByNameRef $helperName]
}
    
  #============================ __unset ========================================
  # Magic property overloading for unsetting if helper is exists by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controller::Action::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__unset {helperName} {
    return [offsetUnset $helperName]
}
    
  #============================ push ===========================================
  # push helper onto the stack
  #
  # @param ::ATWF::Controller::Action::Helper helper
  # @return Controllers::Actions::HelperBrokers::PriorityStack
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::push {helper} {
    offsetSet [getNextFreeHigherPriority] $helper
    return $this
}
    
  #============================ getIterator ====================================
................................................................................
    }
}
    
  #============================ offsetSet ======================================
  # offsetSet()
  #
  # @param int $priority
  # @param ::ATWF::Controller::Action::Helper::Helper helper
  # @return ::ATWF::Controllers::Actions::HelperBrokers::PriorityStack
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::offsetSet {priority helper} {
    if {![isInstanceOf ::ATWF::Controller::Action::Helper::Helper $helper]} {
        return -code error "helper must extend ::ATWF::Controller::Action::Helper::Helper."
    }
    
    if {[dict exists $_helpersByNameRef [$helper getName]]} {
        # remove any object with the same name to retain BC compailitbility
        # @todo At ZF 2.0 time throw an exception here.
        offsetUnset [$helper getName]
    }







|












|








|







|







 







|


|
|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
public method getHelpersByPriority {} { return $_helpersByPriority }
}

  #============================ __get ==========================================
  # Magic property overloading for returning helper by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controllers::Actions::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__get {helperName} {
    if {![dict exists $_helpersByNameRef $helperName]} {
        return false
    }
    
    return [dict get $_helpersByNameRef $helperName]
}
    
  #============================ __isset ========================================
  # Magic property overloading for returning if helper is set by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controllers::Actions::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__isset {helperName} {
    return [dict exists $_helpersByNameRef $helperName]
}
    
  #============================ __unset ========================================
  # Magic property overloading for unsetting if helper is exists by name
  #
  # @param string $helperName    The helper name
  # @return ::ATWF::Controllers::Actions::Helper
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::__unset {helperName} {
    return [offsetUnset $helperName]
}
    
  #============================ push ===========================================
  # push helper onto the stack
  #
  # @param ::ATWF::Controllers::Actions::Helper helper
  # @return Controllers::Actions::HelperBrokers::PriorityStack
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::push {helper} {
    offsetSet [getNextFreeHigherPriority] $helper
    return $this
}
    
  #============================ getIterator ====================================
................................................................................
    }
}
    
  #============================ offsetSet ======================================
  # offsetSet()
  #
  # @param int $priority
  # @param ::ATWF::Controllers::Actions::Helpers::Helper helper
  # @return ::ATWF::Controllers::Actions::HelperBrokers::PriorityStack
::itcl::body Controllers::Actions::HelperBrokers::PriorityStack::offsetSet {priority helper} {
    if {![isInstanceOf ::ATWF::Controllers::Actions::Helpers::Helper $helper]} {
        return -code error "helper must extend ::ATWF::Controllers::Actions::Helpers::Helper."
    }
    
    if {[dict exists $_helpersByNameRef [$helper getName]]} {
        # remove any object with the same name to retain BC compailitbility
        # @todo At ZF 2.0 time throw an exception here.
        offsetUnset [$helper getName]
    }

Changes to library/ATWF/Controllers/Actions/Helpers/ActionStack.tcl.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::Helpers::ActionStack {
    inherit ::ATWF::Controllers::Actions::Helpers::Helper

     # @variable ::ATWF::Controller::Plugin::ActionStack
    protected variable _actionStack [list]

    constructor {} {}

    public method pushStack {next}
    public method actionToStack {action {controller {}} {module {}} {params {}}}
    public method direct {action {controller {}} {module {}} {params {}}}
................................................................................
  #============================ constructor ====================================
  # Constructor
  #
  # Register action stack plugin
  # 
  # @return void
::itcl::body Controllers::Actions::Helpers::ActionStack::constructor {} {
    set front [::ATWF::Controller::Front::getInstance]
    if {![$front hasPlugin ::ATWF::Controller::Plugin::ActionStack]}{
        set _actionStack [uplevel #0 ::ATWF::Controller::Plugin::ActionStack #auto]
        $front registerPlugin $_actionStack 97]
    } else {
        set _actionStack [$front getPlugin ::ATWF::Controller::Plugin::ActionStack]
    }
}

  #============================ pushStack ======================================
  # Push onto the stack 
  # 
  # @param  ::ATWF::Controller::Request::Abstract $next 
  # @return ::ATWF::Controllers::Actions::Helpers::ActionStack Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ActionStack::pushStack {next} {
    $_actionStack pushStack $next
    return $this
}

  #============================ actionToStack ==================================
  # Push a new action onto the stack
  # 
  # @param  string $action 
  # @param  string $controller 
  # @param  string $module 
  # @param  array  $params
  # @throws ::ATWF::Controller::Action::Exception 
  # @return ::ATWF::Controllers::Actions::Helpers::ActionStack
::itcl::body Controllers::Actions::Helpers::ActionStack::actionToStack {action {controller {}} {module {}} {params {}}} {
    if {[isInstanceOf ::ATWF::Controller::Request::Request $action[} {
        return [pushStack $action]
    } else {
        if {[::itcl::is object $action]} {
            return -code error "ActionStack requires either a request object or minimally a string action"
        }
    }

    set request [getRequest]

    if {![isInstanceOf ::ATWF::Controller::Request::Request $request]} {
        return -code error "Request object not set yet"
   }
    
    set controller [expr {$controller eq "" ? [$request getControllerName] : $controller}]
    set module [expr {$module eq "" ? [$request getModuleName] : $module}]

    set newRequest [uplevel #0 ::ATWF::Controller::Request::Simple #auto [list $action $controller $module $params]]

    return [pushStack $newRequest]
}

  #============================ direct =========================================
  # Perform helper when called as $this->_helper->actionStack() from an action controller
  #







|







 







|
|
|


|






|













|


|









|






|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::Helpers::ActionStack {
    inherit ::ATWF::Controllers::Actions::Helpers::Helper

     # @variable ::ATWF::Controllers::Plugins::ActionStack
    protected variable _actionStack [list]

    constructor {} {}

    public method pushStack {next}
    public method actionToStack {action {controller {}} {module {}} {params {}}}
    public method direct {action {controller {}} {module {}} {params {}}}
................................................................................
  #============================ constructor ====================================
  # Constructor
  #
  # Register action stack plugin
  # 
  # @return void
::itcl::body Controllers::Actions::Helpers::ActionStack::constructor {} {
    set front [::ATWF::Controllers::Front::getInstance]
    if {![$front hasPlugin ::ATWF::Controllers::Plugins::ActionStack]}{
        set _actionStack [uplevel #0 ::ATWF::Controllers::Plugins::ActionStack #auto]
        $front registerPlugin $_actionStack 97]
    } else {
        set _actionStack [$front getPlugin ::ATWF::Controllers::Plugins::ActionStack]
    }
}

  #============================ pushStack ======================================
  # Push onto the stack 
  # 
  # @param  ::ATWF::Controllers::Requests::Abstract $next 
  # @return ::ATWF::Controllers::Actions::Helpers::ActionStack Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ActionStack::pushStack {next} {
    $_actionStack pushStack $next
    return $this
}

  #============================ actionToStack ==================================
  # Push a new action onto the stack
  # 
  # @param  string $action 
  # @param  string $controller 
  # @param  string $module 
  # @param  array  $params
  # @throws ::ATWF::Controllers::Actions::Exception 
  # @return ::ATWF::Controllers::Actions::Helpers::ActionStack
::itcl::body Controllers::Actions::Helpers::ActionStack::actionToStack {action {controller {}} {module {}} {params {}}} {
    if {[isInstanceOf ::ATWF::Controllers::Requests::Request $action[} {
        return [pushStack $action]
    } else {
        if {[::itcl::is object $action]} {
            return -code error "ActionStack requires either a request object or minimally a string action"
        }
    }

    set request [getRequest]

    if {![isInstanceOf ::ATWF::Controllers::Requests::Request $request]} {
        return -code error "Request object not set yet"
   }
    
    set controller [expr {$controller eq "" ? [$request getControllerName] : $controller}]
    set module [expr {$module eq "" ? [$request getModuleName] : $module}]

    set newRequest [uplevel #0 ::ATWF::Controllers::Requests::Simple #auto [list $action $controller $module $params]]

    return [pushStack $newRequest]
}

  #============================ direct =========================================
  # Perform helper when called as $this->_helper->actionStack() from an action controller
  #

Changes to library/ATWF/Controllers/Actions/Helpers/AutoCompleteDojo.tcl.

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        foreach {key value} $data {
            lappend items [dict create label $value name $value]
        }
        set data [uplevel #0 ::ATWF::Dojo_Data #auto [list name $items]]
    }

    if {!$keepLayouts} {
        [::ATWF::Controller::Action::HelperBroker::getStaticHelper viewRenderer] setNoRender true

        set layout [::ATWF::Layout::getMvcInstance]
        if {[isInstanceOf ::ATWF::Layout $layout]} {
            $layout disableLayout
        }
    }

    set response [[::ATWF::Controller::Front::getInstance] getResponse]
    $response setHeader "Content-Type" "application/json"

    return [$data toJson]
}

} ; # END ::ATWF







|







|






56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        foreach {key value} $data {
            lappend items [dict create label $value name $value]
        }
        set data [uplevel #0 ::ATWF::Dojo_Data #auto [list name $items]]
    }

    if {!$keepLayouts} {
        [::ATWF::Controllers::Actions::HelperBroker::getStaticHelper viewRenderer] setNoRender true

        set layout [::ATWF::Layout::getMvcInstance]
        if {[isInstanceOf ::ATWF::Layout $layout]} {
            $layout disableLayout
        }
    }

    set response [[::ATWF::Controllers::Front::getInstance] getResponse]
    $response setHeader "Content-Type" "application/json"

    return [$data toJson]
}

} ; # END ::ATWF

Changes to library/ATWF/Controllers/Actions/Helpers/AutoCompleteScriptaculous.tcl.

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
}

  #============================ prepareAutoCompletion ==========================
  # Prepare data for autocompletion
  # 
  # @param  mixed   $data 
  # @param  boolean $keepLayouts 
  # @throws ::ATWF::Controller::Action::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::AutoCompleteScriptaculous::prepareAutoCompletion {data {keepLayouts false}} {
    if {![validateData $data]} {
        return -code erro "Invalid data passed for autocompletion"
    }

    set data "<ul><li>[join $data {</li><li>}]</li></ul>"







|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
}

  #============================ prepareAutoCompletion ==========================
  # Prepare data for autocompletion
  # 
  # @param  mixed   $data 
  # @param  boolean $keepLayouts 
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::AutoCompleteScriptaculous::prepareAutoCompletion {data {keepLayouts false}} {
    if {![validateData $data]} {
        return -code erro "Invalid data passed for autocompletion"
    }

    set data "<ul><li>[join $data {</li><li>}]</li></ul>"

Changes to library/ATWF/Controllers/Actions/Helpers/AutoCompletes/AutoComplete.tcl.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::Helpers::AutoCompletes::AutoComplete {
    inherit ::ATWF::Controller::Action::Helper::Helper

     # Suppress exit when sendJson() called
     #
     # @var boolean
    public variable suppressExit false

    public method validateData {data}
................................................................................
  # 
  # @return Controllers::Actions::Helpers::AutoCompletes::AutoComplete Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::AutoCompletes::AutoComplete::disableLayouts {} {
    if {[set $layout [::ATWF::Layout::getMvcInstance]] ne ""} {
        $layout disableLayout(
    }

    [[::ATWF::Controller::Action::HelperBroker::getStaticHelper viewRenderer] setNoRender true

    return $this
}

  #============================ encodeJson =====================================
  # Encode data to JSON
  # 
  # @param  mixed $data 
  # @param  bool  $keepLayouts 
  # @throws ::ATWF::Controller::Action::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::AutoCompletes::AutoComplete::encodeJson {data {keepLayouts false}} {
    if {[validateData $data]} {
        return [[::ATWF::Controller::Action::HelperBroker::getStaticHelper Json] encodeJson $data $keepLayouts]
    }

    return -code error "Invalid data passed for autocompletion"
}

  #============================ sendAutoCompletion =============================
  # Send autocompletion data







|







 







|









|



|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Actions::Helpers::AutoCompletes::AutoComplete {
    inherit ::ATWF::Controllers::Actions::Helpers::Helper

     # Suppress exit when sendJson() called
     #
     # @var boolean
    public variable suppressExit false

    public method validateData {data}
................................................................................
  # 
  # @return Controllers::Actions::Helpers::AutoCompletes::AutoComplete Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::AutoCompletes::AutoComplete::disableLayouts {} {
    if {[set $layout [::ATWF::Layout::getMvcInstance]] ne ""} {
        $layout disableLayout(
    }

    [[::ATWF::Controllers::Actions::HelperBroker::getStaticHelper viewRenderer] setNoRender true

    return $this
}

  #============================ encodeJson =====================================
  # Encode data to JSON
  # 
  # @param  mixed $data 
  # @param  bool  $keepLayouts 
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::AutoCompletes::AutoComplete::encodeJson {data {keepLayouts false}} {
    if {[validateData $data]} {
        return [[::ATWF::Controllers::Actions::HelperBroker::getStaticHelper Json] encodeJson $data $keepLayouts]
    }

    return -code error "Invalid data passed for autocompletion"
}

  #============================ sendAutoCompletion =============================
  # Send autocompletion data

Changes to library/ATWF/Controllers/Actions/Helpers/ContextSwitch.tcl.

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
...
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
...
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
....
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
....
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
    return $this
}

  #============================ initContext ====================================
  # Initialize context detection and switching
  #
  # @param  mixed format
  # @throws ::ATWF::Controller::Action::Exception
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::initContext {{format {}}} {
    set _currentContext [list]

    set controller [getActionController]
    set request [getRequest]
    set action [$request getActionName]
................................................................................
  #
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::initJsonContext {} {
    if {![getAutoJsonSerialization]} {
        return
    }

    set viewRenderer [::ATWF::Controller::Action::HelperBroker::getStaticHelper viewRenderer]
    set view [$viewRenderer view]
    if {[isInstanceOf ::ATWF::View $view]} {
        $viewRenderer setNoRender true
    }
}

  #============================ setAutoJsonSerialization =======================
................................................................................
  #
  # Passing an empty suffix value to the setters disables the view script
  # suffix change.
  #
  # @param  string  $context                   Context type for which to set suffix
  # @param  string  $suffix                    Suffix to use
  # @param  boolean $prependViewRendererSuffix Whether or not to prepend the new suffix to the viewrenderer suffix
  # @throws ::ATWF::Controller::Action::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setSuffix {context suffix {prependViewRendererSuffix true}} {
    if {![dict exists $_contexts $context]} {
        return -code error "Cannot set suffix invalid context type $context"
    }

    if {$suffix eq ""} {
................................................................................
    return $this
}

  #============================ getSuffix ======================================
  # Retrieve suffix for given context type
  #
  # @param  string $type Context type
  # @throws ::ATWF::Controller::Action::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::ContextSwitch::getSuffix {type} {
    if {![dict exists $_contexts $type]} {
        return -code error "Cannot retrieve suffix invalid context type $type"
    }

    return [dict get $_contexts $type suffix]
................................................................................
}

  #============================ hasContext =====================================
  # Does the given context exist?
  #
  # @param  string  $context
  # @param  boolean $throwException
  # @throws ::ATWF::Controller::Action::Exception if context does not exist and throwException is true
  # @return bool
::itcl::body Controllers::Actions::Helpers::ContextSwitch::hasContext {context {throwException false}} {
    if {![::itcl::is object $context] && ([llength $context] < 2)} {
        if {[dict exists $_contexts $context]} {
            return true
        }
    } else {
................................................................................

  #============================ addHeader ======================================
  # Add header to context
  #
  # @param  string $context
  # @param  string $header
  # @param  string $content
  # @throws ::ATWF::Controller::Action::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::addHeader {context header content} {
    hasContext $context true

    if {[dict exists $_contexts $context headers $header]} {
        return -code error "Cannot add \"$header\" header to context \"$context\": already exists"
    }
................................................................................
    return $this
}

  #============================ _validateTrigger ===============================
  # Validate trigger and return in normalized form
  #
  # @param  string $trigger
  # @throws ::ATWF::Controller::Action::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::ContextSwitch::_validateTrigger {trigger} {
    set trigger [string toupper $trigger]
    if {[string range $trigger 0 7] ne "TRIGGER_"} {
        set trigger "TRIGGER_$trigger"
    }

................................................................................

  #============================ setCallback ====================================
  # Set a callback for a given context and trigger
  #
  # @param  string       $context
  # @param  string       $trigger
  # @param  string|array $callback
  # @throws ::ATWF::Controller::Action::Exception
  # @return Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setCallback {context trigger callback} {
    hasContext $context true
    set trigger [_validateTrigger $trigger]

    if {![::itcl::is object $callback] && ([llength $callback] > 1)} {
        if {[llength $callback] > 2} {
................................................................................
    return $_contextParam
}

  #============================ setDefaultContext ==============================
  # Indicate default context to use when no context format provided
  #
  # @param  string type
  # @throws ::ATWF::Controller::Action::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setDefaultContext {type} {
    if {![dict exists $_contexts $type]} {
        return -code error "Cannot set default context invalid context type \"$type\""
    }

    set _defaultContext $type
................................................................................
}

  #============================ addContext =====================================
  # Add new context
  #
  # @param  string $context Context type
  # @param  array  $spec    Context specification
  # @throws ::ATWF::Controller::Action::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::addContext {context spec} {
    if {[hasContext $context]} {
        return -code error "Cannot add context \"$context\"; already exists"
    }
    dict set _contexts $context [list]

................................................................................
}

  #============================ postDispatch ===================================
  # Post dispatch processing
  #
  # Execute postDispatch callback for current context, if available
  #
  # @throws ::ATWF::Controller::Action::Exception
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::postDispatch {} {
    set context [getCurrentContext]
    if {$context ne ""} {
        if {[set callback [getCallback $context TRIGGER_POST]] ne ""} {
            if {![::itcl::is object $callback] && ([llength $callback] == 1) && [method Exists $this $callback]} {
                $callback
................................................................................
  #
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::postJsonContext {} {
    if {![getAutoJsonSerialization]} {
        return
    }

    set viewRenderer [::ATWF::Controller::Action::HelperBroker::getStaticHelper viewRenderer]
    set view [$viewRenderer view]
    if {[isInstanceOf ::ATWF::View $view]} {
        if{[methodExistsxi ($view getVars]} {
            set vars [::ATWF::Json::encode [$view getVars]
            [getResponse] setBody $vars
        } else {
            return -code error "View does not implement the getVars() method needed to encode the view into JSON"
................................................................................
}

  #============================ hasActionContext ===========================================
  # Does a particular controller action have the given context(s)?
  #
  # @param  string       $action
  # @param  string|array $context
  # @throws ::ATWF::Controller::Action::Exception
  # @return boolean
::itcl::body Controllers::Actions::Helpers::ContextSwitch::hasActionContext {action context} {
    hasContext $context true
    set controller [getActionController]
    if {$controller eq ""} {
        return false
    }







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
...
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
...
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
...
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
....
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
....
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
    return $this
}

  #============================ initContext ====================================
  # Initialize context detection and switching
  #
  # @param  mixed format
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::initContext {{format {}}} {
    set _currentContext [list]

    set controller [getActionController]
    set request [getRequest]
    set action [$request getActionName]
................................................................................
  #
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::initJsonContext {} {
    if {![getAutoJsonSerialization]} {
        return
    }

    set viewRenderer [::ATWF::Controllers::Actions::HelperBroker::getStaticHelper viewRenderer]
    set view [$viewRenderer view]
    if {[isInstanceOf ::ATWF::View $view]} {
        $viewRenderer setNoRender true
    }
}

  #============================ setAutoJsonSerialization =======================
................................................................................
  #
  # Passing an empty suffix value to the setters disables the view script
  # suffix change.
  #
  # @param  string  $context                   Context type for which to set suffix
  # @param  string  $suffix                    Suffix to use
  # @param  boolean $prependViewRendererSuffix Whether or not to prepend the new suffix to the viewrenderer suffix
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setSuffix {context suffix {prependViewRendererSuffix true}} {
    if {![dict exists $_contexts $context]} {
        return -code error "Cannot set suffix invalid context type $context"
    }

    if {$suffix eq ""} {
................................................................................
    return $this
}

  #============================ getSuffix ======================================
  # Retrieve suffix for given context type
  #
  # @param  string $type Context type
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::ContextSwitch::getSuffix {type} {
    if {![dict exists $_contexts $type]} {
        return -code error "Cannot retrieve suffix invalid context type $type"
    }

    return [dict get $_contexts $type suffix]
................................................................................
}

  #============================ hasContext =====================================
  # Does the given context exist?
  #
  # @param  string  $context
  # @param  boolean $throwException
  # @throws ::ATWF::Controllers::Actions::Exception if context does not exist and throwException is true
  # @return bool
::itcl::body Controllers::Actions::Helpers::ContextSwitch::hasContext {context {throwException false}} {
    if {![::itcl::is object $context] && ([llength $context] < 2)} {
        if {[dict exists $_contexts $context]} {
            return true
        }
    } else {
................................................................................

  #============================ addHeader ======================================
  # Add header to context
  #
  # @param  string $context
  # @param  string $header
  # @param  string $content
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::addHeader {context header content} {
    hasContext $context true

    if {[dict exists $_contexts $context headers $header]} {
        return -code error "Cannot add \"$header\" header to context \"$context\": already exists"
    }
................................................................................
    return $this
}

  #============================ _validateTrigger ===============================
  # Validate trigger and return in normalized form
  #
  # @param  string $trigger
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return string
::itcl::body Controllers::Actions::Helpers::ContextSwitch::_validateTrigger {trigger} {
    set trigger [string toupper $trigger]
    if {[string range $trigger 0 7] ne "TRIGGER_"} {
        set trigger "TRIGGER_$trigger"
    }

................................................................................

  #============================ setCallback ====================================
  # Set a callback for a given context and trigger
  #
  # @param  string       $context
  # @param  string       $trigger
  # @param  string|array $callback
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setCallback {context trigger callback} {
    hasContext $context true
    set trigger [_validateTrigger $trigger]

    if {![::itcl::is object $callback] && ([llength $callback] > 1)} {
        if {[llength $callback] > 2} {
................................................................................
    return $_contextParam
}

  #============================ setDefaultContext ==============================
  # Indicate default context to use when no context format provided
  #
  # @param  string type
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::setDefaultContext {type} {
    if {![dict exists $_contexts $type]} {
        return -code error "Cannot set default context invalid context type \"$type\""
    }

    set _defaultContext $type
................................................................................
}

  #============================ addContext =====================================
  # Add new context
  #
  # @param  string $context Context type
  # @param  array  $spec    Context specification
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return ::ATWF::Controllers::Actions::Helpers::ContextSwitch Provides a fluent interface
::itcl::body Controllers::Actions::Helpers::ContextSwitch::addContext {context spec} {
    if {[hasContext $context]} {
        return -code error "Cannot add context \"$context\"; already exists"
    }
    dict set _contexts $context [list]

................................................................................
}

  #============================ postDispatch ===================================
  # Post dispatch processing
  #
  # Execute postDispatch callback for current context, if available
  #
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::postDispatch {} {
    set context [getCurrentContext]
    if {$context ne ""} {
        if {[set callback [getCallback $context TRIGGER_POST]] ne ""} {
            if {![::itcl::is object $callback] && ([llength $callback] == 1) && [method Exists $this $callback]} {
                $callback
................................................................................
  #
  # @return void
::itcl::body Controllers::Actions::Helpers::ContextSwitch::postJsonContext {} {
    if {![getAutoJsonSerialization]} {
        return
    }

    set viewRenderer [::ATWF::Controllers::Actions::HelperBroker::getStaticHelper viewRenderer]
    set view [$viewRenderer view]
    if {[isInstanceOf ::ATWF::View $view]} {
        if{[methodExistsxi ($view getVars]} {
            set vars [::ATWF::Json::encode [$view getVars]
            [getResponse] setBody $vars
        } else {
            return -code error "View does not implement the getVars() method needed to encode the view into JSON"
................................................................................
}

  #============================ hasActionContext ===========================================
  # Does a particular controller action have the given context(s)?
  #
  # @param  string       $action
  # @param  string|array $context
  # @throws ::ATWF::Controllers::Actions::Exception
  # @return boolean
::itcl::body Controllers::Actions::Helpers::ContextSwitch::hasActionContext {action context} {
    hasContext $context true
    set controller [getActionController]
    if {$controller eq ""} {
        return false
    }

Changes to library/ATWF/Controllers/Actions/Helpers/Json.tcl.

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  # @throws Controllers::Actions::Helpers::Json
  # @return string
::itcl::body Controllers::Actions::Helpers::Json::encodeJson {data {keepLayouts false}} {
    set jsonHelper [::ATWF::View::Helper::Json]
    set data [$jsonHelper json $data $keepLayouts]

    if {!$keepLayouts} {
        [::ATWF::Controller::Action::HelperBroker::getStaticHelper viewRenderer] setNoRender true
    }

    return $data
}

  #============================ sendJson =======================================
  # Encode JSON response and immediately send







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  # @throws Controllers::Actions::Helpers::Json
  # @return string
::itcl::body Controllers::Actions::Helpers::Json::encodeJson {data {keepLayouts false}} {
    set jsonHelper [::ATWF::View::Helper::Json]
    set data [$jsonHelper json $data $keepLayouts]

    if {!$keepLayouts} {
        [::ATWF::Controllers::Actions::HelperBroker::getStaticHelper viewRenderer] setNoRender true
    }

    return $data
}

  #============================ sendJson =======================================
  # Encode JSON response and immediately send

Changes to library/ATWF/Controllers/Actions/Helpers/Redirector.tcl.

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
    return $_code
}

  #============================ _checkCode =====================================
  # Validate HTTP status redirect code
  #
  # @param  int $code
  # @throws ::ATWF::Controller::Action::Exception on invalid HTTP status code
  # @return true
::itcl::body Controllers::Actions::Helpers::Redirector::_checkCode {code} {
    if {(300 > $code) || (307 < $code) || (304 == $code) || (306 == $code)} {
        return -code error "Invalid redirect HTTP status code ($code)"
    }

    return true
................................................................................
  # Determine if the baseUrl should be prepended, and prepend if necessary
  #
  # @param  string $url
  # @return string
::itcl::body Controllers::Actions::Helpers::Redirector::_prependBase {url} {
    if {[getPrependBase]} {
        set request [getRequest]
        if {[isInstanceOf ::ATWF::Controller::Request::Http $request]} {
            set base [string trimright [$request getBaseUrl] {/}]
            if {($base ne "") && ($base ne "/")} {
                set url "${base}/[string trimleft $url {/}]"
            } else {
                set url "/[string trimleft $url {/}]"
            }
        }
................................................................................
  # Overloading
  #
  # Overloading for old 'goto', 'setGoto', and 'gotoAndExit' methods
  #
  # @param  string $method
  # @param  array $args
  # @return mixed
  # @throws ::ATWF::Controller::Action::Exception for invalid methods
::itcl::body Controllers::Actions::Helpers::Redirector::__call {method args} {
    set method [string tolower $method]
    if { $method eq "goto"} {
        return [call_user_func_array [dict create $this gotoSimple] $args]
    }
    if {$method eq "setgoto"} {
        return [call_user_func_array [dict create $this setGotoSimple] $args]







|







 







|







 







|







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
    return $_code
}

  #============================ _checkCode =====================================
  # Validate HTTP status redirect code
  #
  # @param  int $code
  # @throws ::ATWF::Controllers::Actions::Exception on invalid HTTP status code
  # @return true
::itcl::body Controllers::Actions::Helpers::Redirector::_checkCode {code} {
    if {(300 > $code) || (307 < $code) || (304 == $code) || (306 == $code)} {
        return -code error "Invalid redirect HTTP status code ($code)"
    }

    return true
................................................................................
  # Determine if the baseUrl should be prepended, and prepend if necessary
  #
  # @param  string $url
  # @return string
::itcl::body Controllers::Actions::Helpers::Redirector::_prependBase {url} {
    if {[getPrependBase]} {
        set request [getRequest]
        if {[isInstanceOf ::ATWF::Controllers::Requests::Http $request]} {
            set base [string trimright [$request getBaseUrl] {/}]
            if {($base ne "") && ($base ne "/")} {
                set url "${base}/[string trimleft $url {/}]"
            } else {
                set url "/[string trimleft $url {/}]"
            }
        }
................................................................................
  # Overloading
  #
  # Overloading for old 'goto', 'setGoto', and 'gotoAndExit' methods
  #
  # @param  string $method
  # @param  array $args
  # @return mixed
  # @throws ::ATWF::Controllers::Actions::Exception for invalid methods
::itcl::body Controllers::Actions::Helpers::Redirector::__call {method args} {
    set method [string tolower $method]
    if { $method eq "goto"} {
        return [call_user_func_array [dict create $this gotoSimple] $args]
    }
    if {$method eq "setgoto"} {
        return [call_user_func_array [dict create $this setGotoSimple] $args]

Changes to library/ATWF/Controllers/Dispatchers/Dispatcher.tcl.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    protected variable _defaultController index

     # Default module
     # @variable string
    protected variable _defaultModule default

     # Front Controller instance
     # @variable ::ATWF::Controller::Front
    protected variable _frontController [list]

     # Array of invocation parameters to use when instantiating action
     # controllers
     # @variable array
    protected variable _invokeParams [list]

     # Path delimiter character
     # @variable string
    protected variable _pathDelimiter "_"

     # Response object to pass to action controllers, if any
     # @variable ::ATWF::Controller::Response|[list]
    protected variable _response [list]

     # Word delimiter characters
     # @variable list
    protected variable _wordDelimiter [list {-} {.}]

    constructor {{params {}}} {}
................................................................................
  # @return void
::itcl::body Controllers::Dispatchers::Dispatcher::constructor {{params {}}} {
    setParams $params
}

  #============================ formatControllerName ===========================
  # Formats a string into a controller name.  This is used to take a raw
  # controller name, such as one stored inside a ::ATWF::Controller::Request
  # object, and reformat it to a proper class name that a class extending
  # ::ATWF::Controller::Action would use.
  #
  # @param string $unformatted
  # @return string
::itcl::body Controllers::Dispatchers::Dispatcher::formatControllerName {unformatted} {
    return "[string totitle [_formatName $unformatted]]Controller"
}

  #============================ formatActionName ===============================
  # Formats a string into an action name.  This is used to take a raw
  # action name, such as one that would be stored inside a ::ATWF::Controller::Request
  # object, and reformat into a proper method name that would be found
  # inside a class extending ::ATWF::Controller::Action.
  #
  # @param string $unformatted
  # @return string
::itcl::body Controllers::Dispatchers::Dispatcher::formatActionName {unformatted} {
    set formatted [_formatName $unformatted true]
    set ret "[string tolower [string range $formatted 0 0]][string range $formatted 1 end]Action"
    return $ret
................................................................................

    return [join $new_segments {::}]
}

  #============================ getFrontContoller ==============================
  # Retrieve front controller instance
  #
  # @return ::ATWF::Controller::Front
::itcl::body Controllers::Dispatchers::Dispatcher::getFrontController {} {
    if {$_frontController eq ""} {
        set _frontController [::ATWF::Controller::Front::getInstance]
    }

    return $_frontController
}

  #============================ setFrontController =============================
  # Set front controller instance
  #
  # @param ::ATWF::Controller::Front controller
  # @return ::ATWF::Controllers::Dispatchers::Dispatcher
::itcl::body Controllers::Dispatchers::Dispatcher::setFrontController {controller} {
    set _frontController $controller
    return $this
}

  #============================ setParam =======================================
................................................................................

    return $this
}

  #============================ setResponse ====================================
  # Set response object to pass to action controllers
  #
  # @param ::ATWF::Controller::Response|[list] $response
  # @return ::ATWF::Controllers::Dispatchers::Dispatcher
::itcl::body Controllers::Dispatchers::Dispatcher::setResponse {{response {}}} {
    set _response $response
    return $this
}

  #============================ getResponse ====================================
  # Return the registered response object
  #
  # @return ::ATWF::Controller::Response|[list]
::itcl::body Controllers::Dispatchers::Dispatcher::getResponse {} {
    return $_response
}

  #============================ setDefautControllerName ========================
  # Set the default controller (minus any formatting)
  #







|












|







 







|

|









|

|







 







|


|








|







 







|









|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
    protected variable _defaultController index

     # Default module
     # @variable string
    protected variable _defaultModule default

     # Front Controller instance
     # @variable ::ATWF::Controllers::Front
    protected variable _frontController [list]

     # Array of invocation parameters to use when instantiating action
     # controllers
     # @variable array
    protected variable _invokeParams [list]

     # Path delimiter character
     # @variable string
    protected variable _pathDelimiter "_"

     # Response object to pass to action controllers, if any
     # @variable ::ATWF::Controllers::Response|[list]
    protected variable _response [list]

     # Word delimiter characters
     # @variable list
    protected variable _wordDelimiter [list {-} {.}]

    constructor {{params {}}} {}
................................................................................
  # @return void
::itcl::body Controllers::Dispatchers::Dispatcher::constructor {{params {}}} {
    setParams $params
}

  #============================ formatControllerName ===========================
  # Formats a string into a controller name.  This is used to take a raw
  # controller name, such as one stored inside a ::ATWF::Controllers::Request
  # object, and reformat it to a proper class name that a class extending
  # ::ATWF::Controllers::Action would use.
  #
  # @param string $unformatted
  # @return string
::itcl::body Controllers::Dispatchers::Dispatcher::formatControllerName {unformatted} {
    return "[string totitle [_formatName $unformatted]]Controller"
}

  #============================ formatActionName ===============================
  # Formats a string into an action name.  This is used to take a raw
  # action name, such as one that would be stored inside a ::ATWF::Controllers::Request
  # object, and reformat into a proper method name that would be found
  # inside a class extending ::ATWF::Controllers::Action.
  #
  # @param string $unformatted
  # @return string
::itcl::body Controllers::Dispatchers::Dispatcher::formatActionName {unformatted} {
    set formatted [_formatName $unformatted true]
    set ret "[string tolower [string range $formatted 0 0]][string range $formatted 1 end]Action"
    return $ret
................................................................................

    return [join $new_segments {::}]
}

  #============================ getFrontContoller ==============================
  # Retrieve front controller instance
  #
  # @return ::ATWF::Controllers::Front
::itcl::body Controllers::Dispatchers::Dispatcher::getFrontController {} {
    if {$_frontController eq ""} {
        set _frontController [::ATWF::Controllers::Front::getInstance]
    }

    return $_frontController
}

  #============================ setFrontController =============================
  # Set front controller instance
  #
  # @param ::ATWF::Controllers::Front controller
  # @return ::ATWF::Controllers::Dispatchers::Dispatcher
::itcl::body Controllers::Dispatchers::Dispatcher::setFrontController {controller} {
    set _frontController $controller
    return $this
}

  #============================ setParam =======================================
................................................................................

    return $this
}

  #============================ setResponse ====================================
  # Set response object to pass to action controllers
  #
  # @param ::ATWF::Controllers::Response|[list] $response
  # @return ::ATWF::Controllers::Dispatchers::Dispatcher
::itcl::body Controllers::Dispatchers::Dispatcher::setResponse {{response {}}} {
    set _response $response
    return $this
}

  #============================ getResponse ====================================
  # Return the registered response object
  #
  # @return ::ATWF::Controllers::Response|[list]
::itcl::body Controllers::Dispatchers::Dispatcher::getResponse {} {
    return $_response
}

  #============================ setDefautControllerName ========================
  # Set the default controller (minus any formatting)
  #

Changes to library/ATWF/Controllers/Dispatchers/Standard.tcl.

251
252
253
254
255
256
257

258

259
260
261
262
263
264
265
    set disableOb [getParam disableOutputBuffering]
    set obLevel [::ATWF::Output::ob_get_level]
    if {$disableOb eq ""} {
        ::ATWF::Output::ob_start
    }

    try {

        $controller dispatch $action

    } trap error [list msg opts] {
puts "MSG![self class]:[self method]!$msg!$opts!"
        # Clean output buffer on error
        set curObLevel [::ATWF::Output::ob_get_level]
        if ($curObLevel > $obLevel) {
            while {1} {
                ::ATWF::Output::ob_get_clean







>

>







251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
    set disableOb [getParam disableOutputBuffering]
    set obLevel [::ATWF::Output::ob_get_level]
    if {$disableOb eq ""} {
        ::ATWF::Output::ob_start
    }

    try {
puts stderr "controller!$controller!dispatch!$action!"
        $controller dispatch $action
puts stderr "controller2!$controller!dispatch!$action!"
    } trap error [list msg opts] {
puts "MSG![self class]:[self method]!$msg!$opts!"
        # Clean output buffer on error
        set curObLevel [::ATWF::Output::ob_get_level]
        if ($curObLevel > $obLevel) {
            while {1} {
                ::ATWF::Output::ob_get_clean

Changes to library/ATWF/Controllers/Front.tcl.

853
854
855
856
857
858
859

860
861
862
863
864
865
866
#        if {[throwExceptions]} {
#            throw $e
#        }
#
#        $_response setException $e
    }


     # Notify plugins of dispatch loop completion
    try {
        $_plugins dispatchLoopShutdown
    } trap error [list msg opts] {
puts "MSG![self class]:[self method]!$msg!$opts!"
#        if {[throwExceptions]} {
#            throw $e







>







853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
#        if {[throwExceptions]} {
#            throw $e
#        }
#
#        $_response setException $e
    }

puts stderr "dispatch loop completion!"
     # Notify plugins of dispatch loop completion
    try {
        $_plugins dispatchLoopShutdown
    } trap error [list msg opts] {
puts "MSG![self class]:[self method]!$msg!$opts!"
#        if {[throwExceptions]} {
#            throw $e

Changes to library/ATWF/Controllers/Plugins/ActionStack.tcl.

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    dict set registry [$getRegistryKey] $stack
    return $this
}

  #============================ pushStack ======================================
  # Push an item onto the stack
  # 
  # @param  ::ATWF::Controller::Request::Request $next 
  # @return ::ATWF::Controllers::Plugins::ActionStack
::itcl::body Controllers::Plugins::ActionStack::pushStack {next} {
    set stack [getStack]
    array_push $stack $next
    return [_saveStack $stack]
}

  #============================ popStack =======================================
  # Pop an item off the action stack
  # 
  # @return false|::ATWF::Controller::Request::Request
::itcl::body Controllers::Plugins::ActionStack::popStack {} {
    set stack [getStack]
    if {$stack eq ""} {
        return false
    }

    set next [array_pop $stack]
    _saveStack $stack

    if {![isInstanceOf ::ATWF::Controller::Request::Request $next]} {
        return -code error "ArrayStack should only contain request objects"
    }
    set action [$next getActionName]
    if {$action eq ""} {
        return [popStack $stack]
    }

................................................................................

    return $next
}

  #============================ postDispatch ===================================
  # postDispatch() plugin hook -- check for actions in stack, and dispatch if any found
  #
  # @param  ::ATWF::Controller::Request::Request request
  # @return void
::itcl::body Controllers::Plugins::ActionStack::postDispatch {request} {
    # Don't move on to next request if this is already an attempt to 
    # forward
    if {![$request isDispatched]} {
        return
    }







|










|









|







 







|







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    dict set registry [$getRegistryKey] $stack
    return $this
}

  #============================ pushStack ======================================
  # Push an item onto the stack
  # 
  # @param  ::ATWF::Controllers::Requests::Request $next 
  # @return ::ATWF::Controllers::Plugins::ActionStack
::itcl::body Controllers::Plugins::ActionStack::pushStack {next} {
    set stack [getStack]
    array_push $stack $next
    return [_saveStack $stack]
}

  #============================ popStack =======================================
  # Pop an item off the action stack
  # 
  # @return false|::ATWF::Controllers::Requests::Request
::itcl::body Controllers::Plugins::ActionStack::popStack {} {
    set stack [getStack]
    if {$stack eq ""} {
        return false
    }

    set next [array_pop $stack]
    _saveStack $stack

    if {![isInstanceOf ::ATWF::Controllers::Requests::Request $next]} {
        return -code error "ArrayStack should only contain request objects"
    }
    set action [$next getActionName]
    if {$action eq ""} {
        return [popStack $stack]
    }

................................................................................

    return $next
}

  #============================ postDispatch ===================================
  # postDispatch() plugin hook -- check for actions in stack, and dispatch if any found
  #
  # @param  ::ATWF::Controllers::Requests::Request request
  # @return void
::itcl::body Controllers::Plugins::ActionStack::postDispatch {request} {
    # Don't move on to next request if this is already an attempt to 
    # forward
    if {![$request isDispatched]} {
        return
    }

Changes to library/ATWF/Controllers/Plugins/Plugin.tcl.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Plugins::Plugin {
    inherit ::ATWF::Base

     # @variable ::ATWF::Controller::Request
    protected variable _request [list]

     # @variable ::ATWF::Controller::Response
    protected variable _response [list]


    public method setRequest {request}
    public method getRequest {}
    public method setResponse {response}
    public method getResponse {}
................................................................................
    public method postDispatch {request}
    public method dispatchLoopShutdown {}
}

  #============================ setRequest =====================================
  # Set request object
  #
  # @param ::ATWF::Controller::Request request
  # @return ::ATWF::Controllers::Plugins::Plugin
::itcl::body Controllers::Plugins::Plugin::setRequest {request} {
    set _request  $request
    return $this
}

  #============================ getRequest =====================================
  # Get request object
  #
  # @return ::ATWF::Controller::Request request
::itcl::body Controllers::Plugins::Plugin::getRequest {} {
    return $_request
}

  #============================ setResponse ====================================
  # Set response object
  #
  # @param ::ATWF::Controller::Response response
  # @return ::ATWF::Controllers::Plugins::Plugin
::itcl::body Controllers::Plugins::Plugin::setResponse {response} {
    set _response $response
    return $this
}

  #============================ getResponse ====================================
  # Get response object
  #
  # @return ::ATWF::Controller::Response response
::itcl::body Controllers::Plugins::Plugin::getResponse {} {
    return $_response
}

  #============================ init ===========================================
  # Called before ::ATWF::Controller::Front begins evaluating the
  # request against its routes.
  #
  # @param ::ATWF::Controller::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::routeStartup {request} {
}

  #============================ routeShutdown ==================================
  # Called after ::ATWF::Controller::Router exits.
  #
  # Called after ::ATWF::Controller::Front exits from the router.
  #
  # @param  ::ATWF::Controller::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::routeShutdown {request} {
}

  #============================ dispatchLoopStart ==============================
  # Called before ::ATWF::Controller::Front enters its dispatch loop.
  #
  # @param  ::ATWF::Controller::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::dispatchLoopStartup {request} {
}

  #============================ preDispatch ====================================
  # Called before an action is dispatched by ::ATWF::Controller::Dispatcher.
  #
  # This callback allows for proxy or filter behavior.  By altering the
  # request and resetting its dispatched flag (via
  # {@link ::ATWF::Controller::Request::setDispatched setDispatched false}),
  # the current action may be skipped.
  #
  # @param  ::ATWF::Controller::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::preDispatch {request} {
}

  #============================ postDispatch ===================================
  # Called after an action is dispatched by ::ATWF::Controller::Dispatcher.
  #
  # This callback allows for proxy or filter behavior. By altering the
  # request and resetting its dispatched flag (via
  # {@link ::ATWF::Controller::Request::setDispatched setDispatched false}),
  # a new action may be specified for dispatching.
  #
  # @param  ::ATWF::Controller::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::postDispatch {request} {
}

  #============================ dispatchLoopShutdown ===========================
  # Called before ::ATWF::Controller::Front exits its dispatch loop.
  #
  # @return void
::itcl::body Controllers::Plugins::Plugin::dispatchLoopShutdown {} {
}

} ; # END ::ATWF







|


|







 







|









|







|









|





|


|





|

|

|





|

|





|



|


|





|



|


|





|






25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Plugins::Plugin {
    inherit ::ATWF::Base

     # @variable ::ATWF::Controllers::Request
    protected variable _request [list]

     # @variable ::ATWF::Controllers::Response
    protected variable _response [list]


    public method setRequest {request}
    public method getRequest {}
    public method setResponse {response}
    public method getResponse {}
................................................................................
    public method postDispatch {request}
    public method dispatchLoopShutdown {}
}

  #============================ setRequest =====================================
  # Set request object
  #
  # @param ::ATWF::Controllers::Request request
  # @return ::ATWF::Controllers::Plugins::Plugin
::itcl::body Controllers::Plugins::Plugin::setRequest {request} {
    set _request  $request
    return $this
}

  #============================ getRequest =====================================
  # Get request object
  #
  # @return ::ATWF::Controllers::Request request
::itcl::body Controllers::Plugins::Plugin::getRequest {} {
    return $_request
}

  #============================ setResponse ====================================
  # Set response object
  #
  # @param ::ATWF::Controllers::Response response
  # @return ::ATWF::Controllers::Plugins::Plugin
::itcl::body Controllers::Plugins::Plugin::setResponse {response} {
    set _response $response
    return $this
}

  #============================ getResponse ====================================
  # Get response object
  #
  # @return ::ATWF::Controllers::Response response
::itcl::body Controllers::Plugins::Plugin::getResponse {} {
    return $_response
}

  #============================ init ===========================================
  # Called before ::ATWF::Controllers::Front begins evaluating the
  # request against its routes.
  #
  # @param ::ATWF::Controllers::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::routeStartup {request} {
}

  #============================ routeShutdown ==================================
  # Called after ::ATWF::Controllers::Router exits.
  #
  # Called after ::ATWF::Controllers::Front exits from the router.
  #
  # @param  ::ATWF::Controllers::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::routeShutdown {request} {
}

  #============================ dispatchLoopStart ==============================
  # Called before ::ATWF::Controllers::Front enters its dispatch loop.
  #
  # @param  ::ATWF::Controllers::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::dispatchLoopStartup {request} {
}

  #============================ preDispatch ====================================
  # Called before an action is dispatched by ::ATWF::Controllers::Dispatcher.
  #
  # This callback allows for proxy or filter behavior.  By altering the
  # request and resetting its dispatched flag (via
  # {@link ::ATWF::Controllers::Request::setDispatched setDispatched false}),
  # the current action may be skipped.
  #
  # @param  ::ATWF::Controllers::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::preDispatch {request} {
}

  #============================ postDispatch ===================================
  # Called after an action is dispatched by ::ATWF::Controllers::Dispatcher.
  #
  # This callback allows for proxy or filter behavior. By altering the
  # request and resetting its dispatched flag (via
  # {@link ::ATWF::Controllers::Request::setDispatched setDispatched false}),
  # a new action may be specified for dispatching.
  #
  # @param  ::ATWF::Controllers::Request request
  # @return void
::itcl::body Controllers::Plugins::Plugin::postDispatch {request} {
}

  #============================ dispatchLoopShutdown ===========================
  # Called before ::ATWF::Controllers::Front exits its dispatch loop.
  #
  # @return void
::itcl::body Controllers::Plugins::Plugin::dispatchLoopShutdown {} {
}

} ; # END ::ATWF

Changes to library/ATWF/Controllers/Plugins/PutHandler.tcl.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Plugins::PutHandler {
    inherit ::ATWF::Controller::Request::Request

    public method preDispatch {request}
}

  #============================ preDispatch ====================================
  # Before dispatching, digest PUT request body and set params
  #
  # @param ::ATWF::Controller::Request::Request request
::itcl::body Controllers::Plugins::PutHandler::preDispatch {request} {
     if {![isInstanceOf ::ATWF::Controller::Request::Http $request]} {
        return
    }

    if {[$_request isPut]} {
        set putParams [list]
        parse_str [$_request getRawBody] $putParams
        $request setParams $putParams
    }
}

} ; # END ::ATWF







|







|

|











23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Plugins::PutHandler {
    inherit ::ATWF::Controllers::Requests::Request

    public method preDispatch {request}
}

  #============================ preDispatch ====================================
  # Before dispatching, digest PUT request body and set params
  #
  # @param ::ATWF::Controllers::Requests::Request request
::itcl::body Controllers::Plugins::PutHandler::preDispatch {request} {
     if {![isInstanceOf ::ATWF::Controllers::Requests::Http $request]} {
        return
    }

    if {[$_request isPut]} {
        set putParams [list]
        parse_str [$_request getRawBody] $putParams
        $request setParams $putParams
    }
}

} ; # END ::ATWF

Changes to library/ATWF/Controllers/Routers/Rewrite.tcl.

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
}

  #============================ route ==========================================
  # Find a matching route to the current PATH_INFO and inject
  # returning values to the Request object.
  #
  # @throws ::ATWF::Controllers::Routers::Exception
  # @return ::ATWF::Controller::Request::Request Request object
::itcl::body Controllers::Routers::Rewrite::route {request} {
    if {![::itcl::is object -class ::ATWF::Controllers::Requests::Http $request]} {
        return -code error "::ATWF::Controllers::Routers::Rewrite requires a ::ATWF::Controllers::Requests::Http-based request object"
    }

    if {$_useDefaultRoutes} {
        addDefaultRoutes







|







325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
}

  #============================ route ==========================================
  # Find a matching route to the current PATH_INFO and inject
  # returning values to the Request object.
  #
  # @throws ::ATWF::Controllers::Routers::Exception
  # @return ::ATWF::Controllers::Requests::Request Request object
::itcl::body Controllers::Routers::Rewrite::route {request} {
    if {![::itcl::is object -class ::ATWF::Controllers::Requests::Http $request]} {
        return -code error "::ATWF::Controllers::Routers::Rewrite requires a ::ATWF::Controllers::Requests::Http-based request object"
    }

    if {$_useDefaultRoutes} {
        addDefaultRoutes

Changes to library/ATWF/Controllers/Routers/Routings/Chain.tcl.

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    set defs [expr {[isInstanceOf ::ATWF::Config [$config dictGet defaults]] ? [[$config dictGet defaults] toList] : [list]}]
    return [uplevel #0 [$config dictGet route] #auto [list $defs]]
}
    
  #============================ routeChain =====================================
  # Add a route to this chain
  # 
  # @param  ::ATWF::Controller::Router::Route::Route route
  # @param  string                        separator
  # @return Controllers::Routers::Routings::Chain
::itcl::body Controllers::Routers::Routings::Chain::routeChain {route {separator /}} {
    lappend _routes $route
    lappend _separators $separator

    return $this
................................................................................

}

  #============================ match ==========================================
  # Matches a user submitted path with a previously defined route.
  # Assigns and returns an array of defaults on a successful match.
  #
  # @param  ::ATWF::Controller::Request::Http request Request to get the path info from
  # @return list|false An list of assigned values or a false on a mismatch
::itcl::body Controllers::Routers::Routings::Chain::match {request {partial {}}} {
    set path [string trim [$request getPathInfo] /]
    set subPath $path
    set values [list]

    foreach {key route} $_routes {
................................................................................

    return $value
}

  #============================ setRequest =====================================
  # Set the request object for this and the child routes
  # 
  # @param  ::ATWF::Controller::Request::Route|[list] $request
  # @return void
::itcl::body Controllers::Routers::Routings::Chain::setRequest {{request {}}} {
    set _request $request

    foreach {idx route} $_routes {
        if {[methodExists $route setRequest]} {
            $route setRequest $request
        }
    }
}

} ; # END ::ATWF







|







 







|







 







|












48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    set defs [expr {[isInstanceOf ::ATWF::Config [$config dictGet defaults]] ? [[$config dictGet defaults] toList] : [list]}]
    return [uplevel #0 [$config dictGet route] #auto [list $defs]]
}
    
  #============================ routeChain =====================================
  # Add a route to this chain
  # 
  # @param  ::ATWF::Controllers::Routers::Routings::Route route
  # @param  string                        separator
  # @return Controllers::Routers::Routings::Chain
::itcl::body Controllers::Routers::Routings::Chain::routeChain {route {separator /}} {
    lappend _routes $route
    lappend _separators $separator

    return $this
................................................................................

}

  #============================ match ==========================================
  # Matches a user submitted path with a previously defined route.
  # Assigns and returns an array of defaults on a successful match.
  #
  # @param  ::ATWF::Controllers::Requests::Http request Request to get the path info from
  # @return list|false An list of assigned values or a false on a mismatch
::itcl::body Controllers::Routers::Routings::Chain::match {request {partial {}}} {
    set path [string trim [$request getPathInfo] /]
    set subPath $path
    set values [list]

    foreach {key route} $_routes {
................................................................................

    return $value
}

  #============================ setRequest =====================================
  # Set the request object for this and the child routes
  # 
  # @param  ::ATWF::Controllers::Requests::Route|[list] $request
  # @return void
::itcl::body Controllers::Routers::Routings::Chain::setRequest {{request {}}} {
    set _request $request

    foreach {idx route} $_routes {
        if {[methodExists $route setRequest]} {
            $route setRequest $request
        }
    }
}

} ; # END ::ATWF

Changes to library/ATWF/Controllers/Routers/Routings/Hostname.tcl.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# @subpackage  Controllers::Routers::Routings
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Routers::Routing::Hostname {
    inherit ::ATWF::Controllers::Routers::Routing::Route

    protected variable _hostVariable ":"
    protected variable _regexDelimiter "#"
    protected variable _defaultRegex [list]

     # Holds names of all route's pattern variable names. Array index holds a position in host.
     # @variable list
................................................................................
     # Associative list filled on match() that holds matched path values
     # for given variable names.
     # @variable list
    protected variable _values [list]

     # Current request object
     #
     # @variable ::ATWF::Controller::Request::Request
    protected variable _request [list]

     # Helper var that holds a count of route pattern's static parts
     # for validation
     # @variable int
    private variable _staticCount 0

................................................................................
    public method getDefaults {}
    public method getVariables {}
}

  #============================ setRequest =====================================
  # Set the request object
  #
  # @param  ::ATWF::Controller::Request::Request|[list] request
  # @return void
::itcl::body Controllers::Routers::Routing::Hostname::setRequest {{request {}}} {
    set _request $request
}

  #============================ getRequest =========================================
  # Get the request object
  #
  # @return ::ATWF::Controller::Request::Request request
::itcl::body Controllers::Routers::Routing::Hostname::getRequest {} {
    if {$_request eq ""} {
        set request [[::ATWF::Controller::Front::getInstance] getRequest]
    }

    return $_request
}

  #============================ getInstance ====================================
  # Instantiates route based on passed Config structure
  #
  # @param Config config Configuration object
::itcl::body Controllers::Routers::Routing::Hostname::getInstance {config} {
    set reqs [expr {[isInstanceOf ::ATWF::Config [$config dictGet reqs]] ? [$config dictGet reqs] toList : [list]}]
    set defs [expr {[isInstanceOf ::ATWF::Config [$config dictGet defaults]] ? [$config dictGet defaults] toList : [list]}]
    set scheme [expr {[dict exists [$config dictGet scheme]] ? [$config dictGet scheme] : [list]}]
    return [uplevel #0 ::ATWF::Controllers::Routers::Routing::Hostname #auto [list [$config dictGet route] $defs $reqs $scheme]]
}

  #============================ constructor ====================================
  # Prepares the route for mapping by splitting (exploding) it
  # to a corresponding atomic parts. These parts are assigned
  # a position which is later used for matching and preparing values.
  #
  # @param string $route Map used to match with later submitted hostname
  # @param array  $defaults Defaults for map variables with keys as variable names
  # @param array  $reqs Regular expression requirements for variables (keys as variable names)
  # @param string $scheme
::itcl::body Controllers::Routers::Routing::Hostname::constructor {route {defaults {}} {reqs {}} {scheme {}}} {
    set route [string trim $route .]
    set _defaults $defaults
    set _requirements $reqs
    set _scheme $scheme

    if {$route ne ""} {
        foreach {pos part} [split $route .] {
................................................................................
    }
}

  #============================ match ==========================================
  # Matches a user submitted path with parts defined by a map. Assigns and
  # returns an array of variables on a successful match.
  #
  # @param ::ATWF::Controller::Request::Http request Request to get the host from
  # @return dict|false A dict of assigned values or a false on a mismatch
::itcl::body Controllers::Routers::Routing::Hostname::match {request} {
    # Check the scheme if required
    if {$_scheme eq ""} {
        set scheme [$request getScheme]

        if {$scheme ne $_scheme} {
            return false
        }
................................................................................

  #============================ assemble =======================================
  # Assembles user submitted parameters forming a hostname defined by this route
  #
  # @param  array $data An array of variable and value pairs used as parameters
  # @param  boolean $reset Whether or not to set route defaults with those provided in $data
  # @return string Route path with user submitted parameters
::itcl::body Controllers::Routers::Routing::Hostname::assemble {{data {}} {reset false} {encode false} {partial false}} {
    set host [list]
    set flag false

    foreach {key part} $_parts {
        set name [expr {[dict exists $_variables $key] ? [dict get $_variables$key] : [list]}]

        set useDefault false
................................................................................

    set url [string trim $ret .]

    if {$_scheme ne ""} {
        set scheme $_scheme
    } else {
        set request [getRequest]
        if {[isInstanceOf ::ATWF::Controller::Request::Http $request]} {
            set scheme [$request getScheme]
        } else {
            set scheme http
        }
    }

    set hostname [join $host .]
................................................................................
}

  #============================ getDefault =====================================
  # Return a single parameter of route's defaults
  #
  # @param string $name Array key of the parameter
  # @return string Previously set default
::itcl::body Controllers::Routers::Routing::Hostname::getDefault {name} {
    if {[dict exists $_defaults $name]} {
        return [dict get $_defaults $name]
    }
    return [list]
}

  #============================ getDefaults ====================================
  # Return an array of defaults
  #
  # @return array Route defaults
::itcl::body Controllers::Routers::Routing::Hostname::getDefaults {} {
    return $_defaults
}

  #============================ getVariables ===================================
  # Get all variables which are used by the route
  #
  # @return array
::itcl::body Controllers::Routers::Routing::Hostname::getVariables {} {
    return $_variables
}

} ; # END ::ATWF







|
|







 







|







 







|

|






|
|

|









|



|











|







 







|

|







 







|







 







|







 







|










|







|




22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# @subpackage  Controllers::Routers::Routings
# @license     BSD License (see file license.terms in the source top drectory)
# @version     $Id$
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Controllers::Routers::Routings::Hostname {
    inherit ::ATWF::Controllers::Routers::Routings::Route

    protected variable _hostVariable ":"
    protected variable _regexDelimiter "#"
    protected variable _defaultRegex [list]

     # Holds names of all route's pattern variable names. Array index holds a position in host.
     # @variable list
................................................................................
     # Associative list filled on match() that holds matched path values
     # for given variable names.
     # @variable list
    protected variable _values [list]

     # Current request object
     #
     # @variable ::ATWF::Controllers::Requests::Request
    protected variable _request [list]

     # Helper var that holds a count of route pattern's static parts
     # for validation
     # @variable int
    private variable _staticCount 0

................................................................................
    public method getDefaults {}
    public method getVariables {}
}

  #============================ setRequest =====================================
  # Set the request object
  #
  # @param  ::ATWF::Controllers::Requests::Request|[list] request
  # @return void
::itcl::body Controllers::Routers::Routings::Hostname::setRequest {{request {}}} {
    set _request $request
}

  #============================ getRequest =========================================
  # Get the request object
  #
  # @return ::ATWF::Controllers::Requests::Request request
::itcl::body Controllers::Routers::Routings::Hostname::getRequest {} {
    if {$_request eq ""} {
        set request [[::ATWF::Controllers::Front::getInstance] getRequest]
    }

    return $_request
}

  #============================ getInstance ====================================
  # Instantiates route based on passed Config structure
  #
  # @param Config config Configuration object
::itcl::body Controllers::Routers::Routings::Hostname::getInstance {config} {
    set reqs [expr {[isInstanceOf ::ATWF::Config [$config dictGet reqs]] ? [$config dictGet reqs] toList : [list]}]
    set defs [expr {[isInstanceOf ::ATWF::Config [$config dictGet defaults]] ? [$config dictGet defaults] toList : [list]}]
    set scheme [expr {[dict exists [$config dictGet scheme]] ? [$config dictGet scheme] : [list]}]
    return [uplevel #0 ::ATWF::Controllers::Routers::Routings::Hostname #auto [list [$config dictGet route] $defs $reqs $scheme]]
}

  #============================ constructor ====================================
  # Prepares the route for mapping by splitting (exploding) it
  # to a corresponding atomic parts. These parts are assigned
  # a position which is later used for matching and preparing values.
  #
  # @param string $route Map used to match with later submitted hostname
  # @param array  $defaults Defaults for map variables with keys as variable names
  # @param array  $reqs Regular expression requirements for variables (keys as variable names)
  # @param string $scheme
::itcl::body Controllers::Routers::Routings::Hostname::constructor {route {defaults {}} {reqs {}} {scheme {}}} {
    set route [string trim $route .]
    set _defaults $defaults
    set _requirements $reqs
    set _scheme $scheme

    if {$route ne ""} {
        foreach {pos part} [split $route .] {
................................................................................
    }
}

  #============================ match ==========================================
  # Matches a user submitted path with parts defined by a map. Assigns and
  # returns an array of variables on a successful match.
  #
  # @param ::ATWF::Controllers::Requests::Http request Request to get the host from
  # @return dict|false A dict of assigned values or a false on a mismatch
::itcl::body Controllers::Routers::Routings::Hostname::match {request} {
    # Check the scheme if required
    if {$_scheme eq ""} {
        set scheme [$request getScheme]

        if {$scheme ne $_scheme} {
            return false
        }
................................................................................

  #============================ assemble =======================================
  # Assembles user submitted parameters forming a hostname defined by this route
  #
  # @param  array $data An array of variable and value pairs used as parameters
  # @param  boolean $reset Whether or not to set route defaults with those provided in $data
  # @return string Route path with user submitted parameters
::itcl::body Controllers::Routers::Routings::Hostname::assemble {{data {}} {reset false} {encode false} {partial false}} {
    set host [list]
    set flag false

    foreach {key part} $_parts {
        set name [expr {[dict exists $_variables $key] ? [dict get $_variables$key] : [list]}]

        set useDefault false
................................................................................

    set url [string trim $ret .]

    if {$_scheme ne ""} {
        set scheme $_scheme
    } else {
        set request [getRequest]
        if {[isInstanceOf ::ATWF::Controllers::Requests::Http $request]} {
            set scheme [$request getScheme]
        } else {
            set scheme http
        }
    }

    set hostname [join $host .]
................................................................................
}

  #============================ getDefault =====================================
  # Return a single parameter of route's defaults
  #
  # @param string $name Array key of the parameter
  # @return string Previously set default
::itcl::body Controllers::Routers::Routings::Hostname::getDefault {name} {
    if {[dict exists $_defaults $name]} {
        return [dict get $_defaults $name]
    }
    return [list]
}

  #============================ getDefaults ====================================
  # Return an array of defaults
  #
  # @return array Route defaults
::itcl::body Controllers::Routers::Routings::Hostname::getDefaults {} {
    return $_defaults
}

  #============================ getVariables ===================================
  # Get all variables which are used by the route
  #
  # @return array
::itcl::body Controllers::Routers::Routings::Hostname::getVariables {} {
    return $_variables
}

} ; # END ::ATWF

Changes to library/ATWF/Controllers/Routers/Routings/Module.tcl.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
::itcl::body Controllers::Routers::Routings::Module::getVersion {} {
    return 1
}

  #============================ getInstance ====================================
  # Instantiates route based on passed Config structure
::itcl::body Controllers::Routers::Routings::Module::getInstance {config} {
    $frontController = ::ATWF::Controller::Front::getInstance()
    
    $defs       = ($config->defaults instanceof Config) ? $config->defaults->toArray() : array()
    $dispatcher = $frontController->getDispatcher()
    $request    = $frontController->getRequest()
    
    return new self($defs, $dispatcher, $request)
}







|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
::itcl::body Controllers::Routers::Routings::Module::getVersion {} {
    return 1
}

  #============================ getInstance ====================================
  # Instantiates route based on passed Config structure
::itcl::body Controllers::Routers::Routings::Module::getInstance {config} {
    $frontController = ::ATWF::Controllers::Front::getInstance()
    
    $defs       = ($config->defaults instanceof Config) ? $config->defaults->toArray() : array()
    $dispatcher = $frontController->getDispatcher()
    $request    = $frontController->getRequest()
    
    return new self($defs, $dispatcher, $request)
}

Changes to library/ATWF/Layouts/Controllers/Actions/Helpers/Layout.tcl.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Layouts::Controllers::Actions::Helpers::Layout {
    inherit ::ATWF::Controllers::Actions::Helpers::Helper

     # @variable ::ATWF::Controller::Front
    protected variable _frontController [list]

     # @variable Layout
    protected variable _layout

     # @variable bool
    protected variable _isActionControllerSuccessful false
................................................................................
::itcl::body Layouts::Controllers::Actions::Helpers::Layout::init {} {
    set _isActionControllerSuccessful false
}

  #============================ getFrontController =============================
  # Get front controller instance
  # 
  # @return ::ATWF::Controller::Front
::itcl::body Layouts::Controllers::Actions::Helpers::Layout::getFrontController {} {
    if {$_frontController eq ""} {
         # @see ::ATWF::Controllers::Front
        set _frontController [::ATWF::Controllers::Front::getInstance]
    }

    return $_frontController







|







 







|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#************************************************************************/

namespace eval ::ATWF {

::itcl::extendedclass Layouts::Controllers::Actions::Helpers::Layout {
    inherit ::ATWF::Controllers::Actions::Helpers::Helper

     # @variable ::ATWF::Controllers::Front
    protected variable _frontController [list]

     # @variable Layout
    protected variable _layout

     # @variable bool
    protected variable _isActionControllerSuccessful false
................................................................................
::itcl::body Layouts::Controllers::Actions::Helpers::Layout::init {} {
    set _isActionControllerSuccessful false
}

  #============================ getFrontController =============================
  # Get front controller instance
  # 
  # @return ::ATWF::Controllers::Front
::itcl::body Layouts::Controllers::Actions::Helpers::Layout::getFrontController {} {
    if {$_frontController eq ""} {
         # @see ::ATWF::Controllers::Front
        set _frontController [::ATWF::Controllers::Front::getInstance]
    }

    return $_frontController

Changes to library/ATWF/Layouts/Controllers/Plugins/Layout.tcl.

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    set _layout $layout
    return $this
}

  #============================ setLayoutActionHelper ==========================
  # Set layout action helper
  # 
  # @param  ::ATWF::Layout::Controller::Action::Helper::Layout layoutActionHelper 
  # @return Layouts::Controllers::Plugins::Layout
::itcl::body Layouts::Controllers::Plugins::Layout::setLayoutActionHelper {layoutActionHelper} {
    set _layoutActionHelper $layoutActionHelper
    return $this
}

  #============================ getLayoutActionHelper ==========================
  # Retrieve layout action helper
  # 
  # @return ::ATWF::Layout::Controller::Action::Helper::Layout
::itcl::body Layouts::Controllers::Plugins::Layout::getLayoutActionHelper {} {
    return $_layoutActionHelper
}
    
  #============================ postDispatch ===================================
  # postDispatch() plugin hook -- render layout
  #
  # @param  ::ATWF::Controller::Request::Request request
  # @return void
::itcl::body Layouts::Controllers::Plugins::Layout::postDispatch {request} {
    set layout [getLayout]
    set helper [getLayoutActionHelper]

    # Return early if forward detected
    if {![$request isDispatched]







|









|







|







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    set _layout $layout
    return $this
}

  #============================ setLayoutActionHelper ==========================
  # Set layout action helper
  # 
  # @param  ::ATWF::Layout::Controllers::Actions::Helpers::Layout layoutActionHelper 
  # @return Layouts::Controllers::Plugins::Layout
::itcl::body Layouts::Controllers::Plugins::Layout::setLayoutActionHelper {layoutActionHelper} {
    set _layoutActionHelper $layoutActionHelper
    return $this
}

  #============================ getLayoutActionHelper ==========================
  # Retrieve layout action helper
  # 
  # @return ::ATWF::Layout::Controllers::Actions::Helpers::Layout
::itcl::body Layouts::Controllers::Plugins::Layout::getLayoutActionHelper {} {
    return $_layoutActionHelper
}
    
  #============================ postDispatch ===================================
  # postDispatch() plugin hook -- render layout
  #
  # @param  ::ATWF::Controllers::Requests::Request request
  # @return void
::itcl::body Layouts::Controllers::Plugins::Layout::postDispatch {request} {
    set layout [getLayout]
    set helper [getLayoutActionHelper]

    # Return early if forward detected
    if {![$request isDispatched]