~ubuntu-branches/ubuntu/oneiric/haxe/oneiric

« back to all changes in this revision

Viewing changes to haxe/std/mtwin/web/Handler.hx

  • Committer: Bazaar Package Importer
  • Author(s): Jens Peter Secher
  • Date: 2008-06-15 11:04:09 UTC
  • mfrom: (2.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080615110409-7pyykgwmk5v0cues
Tags: 1:1.19-3
* Remove bashism in script.
  (Closes: #484390)
* Upgrade to Policy 3.8.0 by including a README.source explaining how to
  use dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
/**
41
41
        Generic class to handle web actions.
42
42
 
43
 
        Add to your .htaccess :
 
43
        Add to your .htaccess : [
44
44
 
45
45
        <FilesMatch "^(actionName|actionName|...)$">
46
46
        RewriteEngine On
47
47
        RewriteRule (.*) /index.n
48
48
        </FilesMatch>
 
49
        ]
49
50
**/
50
51
class Handler<T> {
51
52
 
66
67
                ReadOnly = false;
67
68
        }
68
69
 
 
70
        function initialize() {
 
71
        }
 
72
 
 
73
        function getObjectId( part:String ) : Int {
 
74
                if (~/^[0-9]+$/.match(part))
 
75
                        return Std.parseInt(part);
 
76
                return null;
 
77
        }
 
78
 
69
79
        public function execute( request:Request, ?pathLevel:Int ){
70
80
                if (pathLevel == null)
71
81
                        pathLevel = 0;
72
82
 
73
83
                var part = request.getPathInfoPart(pathLevel);
74
 
                if (~/^[0-9]+$/.match(part)){
75
 
                        id = Std.parseInt(part);
 
84
                this.id = getObjectId(part);
 
85
                if( id != null ){
76
86
                        part = request.getPathInfoPart(++pathLevel);
77
87
                        if (part == "")
78
88
                                part = OBJECT_DEFAULT;
83
93
 
84
94
                if (part == "")
85
95
                        part = STATIC_DEFAULT;
 
96
 
 
97
                initialize();
86
98
                if (actions.exists(part)){
87
99
                        actions.get(part)();
88
100
                        return;
100
112
                throw "not implemented";
101
113
                return false;
102
114
        }
103
 
        
 
115
 
104
116
        function isAdmin() : Bool {
105
117
                throw "not implemented";
106
118
                return false;
107
119
        }
108
 
        
 
120
 
109
121
        function isModerator() : Bool {
110
122
                throw "not implemented";
111
123
                return false;
122
134
        }
123
135
 
124
136
        // callback wrappers
125
 
        
 
137
 
126
138
        function object( cb:T->Void, ?lock:Bool ) : Void->Void {
127
139
                if (lock == null) lock = ReadWrite;
128
140
                var me = this;
136
148
                }
137
149
        }
138
150
 
139
 
        function owner( cb:T->Void ) : T->Void {
 
151
        function owner<K>( cb:T->K ) : T->K {
140
152
                var me = this;
141
153
                return function(u:T){
142
154
                        if (!me.isOwner(u))
143
155
                                throw ActionReservedToObjectOwner;
144
 
                        cb(u);
 
156
                        return cb(u);
145
157
                }
146
158
        }
147
159
 
152
164
                }
153
165
        }
154
166
 
 
167
        function objectHandler( cb : T -> Handler<Dynamic>, ?lock : Bool ) {
 
168
                var me = this;
 
169
                return object(function(u:T) {
 
170
                        me.handler(cb(u))();
 
171
                },lock);
 
172
        }
 
173
 
 
174
 
 
175
        function instance<T>( h : T -> Void, get : Int -> Bool -> T, lock : Bool ) : Void -> Void {
 
176
                var me = this;
 
177
                return function() {
 
178
                        var id = Std.parseInt(me.request.getPathInfoPart(me.level+1));
 
179
                        var inst = get(id,lock);
 
180
                        if( inst == null ) throw ObjectNotFound(id);
 
181
                        h(inst);
 
182
                };
 
183
        }
 
184
 
155
185
        // action declarators
156
186
 
157
187
        function free( n:String, ?t:String, ?cb:Void->Void ){