My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
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
148
149
150
151
/**
* e4xd javascript server-side - openmocha reduced to the max
*
* Copyright 2008 Chris Zumbrunn <chris@zumbrunn.com> http://zumbrunn.com
* version 0.9, March 4, 2008
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/**
* Resolves url path to child element with matching name
*/
function getChildElement(name) {
var obj = this.get(name);

// only resolve to the object if a renderPage method is implemented
if (obj && obj.renderPage)
return obj;
}


/**
* Resolves requests to soft-coded actions before hard-coded ones are invoked
*/
function onRequest() {

// sets the actually resolved action, as it is also set by notfound
req.data.action = req.action;

if (req.action != 'notfound') {
// let soft-coded actions override
var idempotentAction = req.action +'_'+ req.method.toLowerCase();
var action = (this.actions[idempotentAction] || this.actions[req.action]);

if (action) {
action.call(this);
res.stop();
}
}
}


/**
* Resolve requests with no automatic match
*/
function notfound_action(){

res.status = 200;

var action, output, name;

// setup path names to look through
var names = req.path.split('/');

// resolve path names against the object hierarchy
var obj = root;
do {
if (obj.get(names[0]))
obj = obj.get(names[0]);
else
break;
}
while (names.shift());

if (!obj.render)
res.redirect(obj._parent.href());

req.data.action = names[0] || 'main';

// handle idempotent requests as such
idempotentAction = req.data.action +'_'+ req.method.toLowerCase();

// call a softcoded idempotent action
if (obj.actions[idempotentAction])
obj.actions[idempotentAction].call(obj,names);

// call a softcoded standard action
else if (obj.actions[req.data.action])
obj.actions[req.data.action].call(obj,names);

// render auto-action-enabled views
else if (obj.actionviews_json
&& obj.actionviews_json[req.data.action]
&& obj.access[req.data.action])
obj.renderPage();

// if the main action was denied, redirect to the login
else if (req.data.action == 'main')
res.redirect(obj.href('login'));

// otherwise redirect to the main action
else
res.redirect(obj.href());
}


/**
* Serialize otherwise unpersisted objects with matching suffixes
*/
function onPersist(){
for (var i in this) {
if (i.endsWith('_json'))
this[i+'_'] = this[i].toJSON();
else if (i.endsWith('_e4x'))
this[i+'_'] = this[i].toXMLString();
else if (i.endsWith('_action')
|| i.endsWith('_action_get')
|| i.endsWith('_action_post')
|| i.endsWith('_action_put')
|| i.endsWith('_action_delete')
|| i.endsWith('_macro')
|| i.endsWith('_fetchlet')
|| i.endsWith('_control'))
this[i+'_'] = this[i].toSource()
.slice(this[i].toSource().indexOf('{')+1,
this[i].toSource().lastIndexOf('}'))
}
}


/**
* Unserialize specially persisted objects with matching suffixes
*/
function onInit() {
for (var i in this) {
if (i.endsWith('_json_'))
this[i.slice(0,-1)] = this[i].parseJSON();
else if (i.endsWith('_e4x_'))
this[i.slice(0,-1)] = new XML(this[i]);
else if (i.endsWith('_action_')
|| i.endsWith('_action_get_')
|| i.endsWith('_action_post_')
|| i.endsWith('_action_put_')
|| i.endsWith('_action_delete_')
|| i.endsWith('_macro_')
|| i.endsWith('_fetchlet_')
|| i.endsWith('_control_'))
this[i.slice(0,-1)] = new Function(this[i]);
}
}

Change log

r75 by chris.zumbrunn on Apr 28, 2008   Diff
removed call of root.onInit() since Helma
bug #598 was fixed, making this workaround
redundant.
Go to: 
Project members, sign in to write a code review

Older revisions

r68 by chris.zumbrunn on Mar 4, 2008   Diff
changed version date
r65 by chris.zumbrunn on Mar 3, 2008   Diff
updated version information
r63 by chris.zumbrunn on Mar 2, 2008   Diff
changed code so that access properties
resolve to directly check the access
status for the current user and moved
the check, include, exclude and remove
methods to use a syntax like
...
All revisions of this file

File info

Size: 4460 bytes, 151 lines
Powered by Google Project Hosting