]> err.no Git - sope/blob - Recycler/NGObjDOM/Dynamic.subproj/ODR_bind_with.m
more directory hierarchy reorganisations,
[sope] / Recycler / NGObjDOM / Dynamic.subproj / ODR_bind_with.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 /*
24   attributes:
25
26     object // object to focus on
27
28   Special objects (strings):
29   
30     #  - component
31     #A - application
32     #S - session
33   
34   example:
35     
36     <var:with js:object="FileManager().loadDocument('/blah.gif')">
37       Title: <var:string value="name"/>
38     </var:with>
39     
40     <var:with const:object="#">
41       <var:string value="name"/>
42     </var:with>
43 */
44
45 #include <NGObjDOM/ODNodeRenderer.h>
46
47 @interface ODR_bind_with : ODNodeRenderer
48 @end
49
50 #include "WOContext+Cursor.h"
51 #include <DOM/DOM.h>
52 #include "common.h"
53
54 @implementation ODR_bind_with
55
56 - (id)_objectFromNode:(id)_node inContext:(WOContext *)_ctx {
57   id obj;
58   
59   if (_node == nil)
60     return nil;
61   
62   obj = [self valueFor:@"object" node:_node ctx:_ctx];
63   
64   if ([obj isKindOfClass:[NSString class]]) {
65     if ([(NSString *)obj hasPrefix:@"#"]) {
66       if ([obj isEqualToString:@"#"])
67         obj = [_ctx component];
68       else if ([obj isEqualToString:@"#A"])
69         obj = [WOApplication application];
70       else if ([obj isEqualToString:@"#S"])
71         obj = [[_ctx component] session];
72     }
73   }
74   
75   return obj;
76 }
77
78 - (void)takeValuesForNode:(id)_node
79   fromRequest:(WORequest *)_req
80   inContext:(WOContext *)_ctx
81 {
82   if ([_node hasChildNodes]) {
83     [_ctx pushCursor:[self _objectFromNode:_node inContext:_ctx]];
84     
85     [self takeValuesForChildNodes:[_node childNodes]
86           fromRequest:_req
87           inContext:_ctx];
88     
89     [_ctx popCursor];
90   }
91 }
92
93 - (id)invokeActionForNode:(id)_domNode
94   fromRequest:(WORequest *)_request
95   inContext:(WOContext *)_ctx
96 {
97   if ([_domNode hasChildNodes]) {
98     id result;
99
100     [_ctx pushCursor:[self _objectFromNode:_domNode inContext:_ctx]];
101     
102     result = [self invokeActionForChildNodes:[_domNode childNodes]
103                    fromRequest:_request
104                    inContext:_ctx];
105     
106     [_ctx popCursor];
107     
108     return result;
109   }
110   else
111     return nil;
112 }
113
114 - (void)appendNode:(id)_domNode
115   toResponse:(WOResponse *)_response
116   inContext:(WOContext *)_ctx
117 {
118   if ([_domNode hasChildNodes]) {
119     id obj;
120     
121     obj = [self _objectFromNode:_domNode inContext:_ctx];
122 #if DEBUG
123     if (obj == nil)
124       NSLog(@"WARNING(%s): missing cursor object ...", __PRETTY_FUNCTION__);
125
126     //NSLog(@"%s: using cursor %@", __PRETTY_FUNCTION__, obj);
127 #endif
128     
129     [_ctx pushCursor:obj];
130 #if DEBUG && 0
131     NSAssert([_ctx cursor] == obj, @"cursor push failed !!");
132 #endif
133
134     [self appendChildNodes:[_domNode childNodes]
135           toResponse:_response
136           inContext:_ctx];
137     
138     [_ctx popCursor];
139   }
140 }
141
142 @end /* ODR_bind_with */