]> err.no Git - sope/blob - Recycler/NGObjDOM/ODREmbedComponent.m
fixed a warning in resource manager
[sope] / Recycler / NGObjDOM / ODREmbedComponent.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 #include <NGObjDOM/ODREmbedComponent.h>
24 #include <NGObjDOM/ODNamespaces.h>
25 #include "common.h"
26
27 @interface WOComponent(PrivateMethods)
28 - (WOComponent *)childComponentWithName:(NSString *)_cname;
29 @end
30
31 @interface NSObject(DOMPrivates)
32 - (id)attributeNode:(NSString *)_key namespaceURI:(NSString *)_ns;
33 @end
34
35 extern void WOContext_enterComponent
36 (WOContext *_ctx, WOComponent *_component, WOElement *element);
37 extern void WOContext_leaveComponent(WOContext *_ctx, WOComponent *_component);
38
39 @implementation ODREmbedComponent
40
41 - (NSString *)_keyForNode:(id)_domNode inContext:(WOContext *)_ctx {
42   NSString *key;
43   id attrNode;
44   
45   attrNode = [_domNode attributeNode:@"id" namespaceURI:XMLNS_OD_BIND];
46   key      = [attrNode textValue];
47   
48   if ([key length] == 0) {
49     attrNode = [_domNode attributeNode:@"name" namespaceURI:XMLNS_OD_BIND];
50     key      = [attrNode textValue];
51   }
52   
53   if ([key length] == 0)
54     key = [NSString stringWithFormat:@"key0%08X", _domNode];
55   
56   return key;
57 }
58
59 - (void)takeValuesForNode:(id)_domNode
60   fromRequest:(WORequest *)_request
61   inContext:(WOContext *)_ctx
62 {
63   WOComponent *parent, *child;
64   NSString    *key;
65   
66   key = [self _keyForNode:_domNode inContext:_ctx];
67   
68   if ((parent = [_ctx component]) == nil) {
69     [[_ctx session]
70            logWithFormat:@"WARNING: did not find parent component of child %@",
71              key];
72     return;
73   }
74   if ((child = [parent childComponentWithName:key]) == nil) {
75     [[_ctx session]
76            logWithFormat:
77              @"WARNING: did not find child component %@ of parent %@",
78              key, [parent name]];
79     return;
80   }
81   
82   WOContext_enterComponent(_ctx, child, nil /*self->template*/);
83   [child takeValuesFromRequest:_request inContext:_ctx];
84   WOContext_leaveComponent(_ctx, child);
85 }
86
87 - (id)invokeActionForNode:(id)_domNode
88   fromRequest:(WORequest *)_request
89   inContext:(WOContext *)_ctx
90 {
91   id          result = nil;
92   WOComponent *parent, *child;
93   NSString    *key;
94   
95   key = [self _keyForNode:_domNode inContext:_ctx];
96   
97   if ((parent = [_ctx component]) == nil) {
98     [[_ctx session]
99            logWithFormat:@"WARNING: did not find parent component of child %@",
100              key];
101     return nil;
102   }
103   if ((child = [parent childComponentWithName:key]) == nil) {
104     [[_ctx session]
105            logWithFormat:
106              @"WARNING: did not find child component %@ of parent %@",
107              key, [parent name]];
108     return nil;
109   }
110   
111   WOContext_enterComponent(_ctx, child, nil /*self->template*/);
112   result = [child invokeActionForRequest:_request inContext:_ctx];
113   WOContext_leaveComponent(_ctx, child);
114   
115   return result;
116 }
117
118 - (void)appendNode:(id)_domNode
119   toResponse:(WOResponse *)_response
120   inContext:(WOContext *)_ctx
121 {
122   WOComponent *parent, *child;
123   NSString    *key;
124   
125   if ([_domNode nodeType] != DOM_ELEMENT_NODE) {
126     [super appendNode:_domNode toResponse:_response inContext:_ctx];
127     return;
128   }
129   
130   key = [self _keyForNode:_domNode inContext:_ctx];
131   
132   if ((parent = [_ctx component]) == nil) {
133     [[_ctx session]
134            logWithFormat:@"WARNING: did not find parent component of child %@",
135              key];
136     return;
137   }
138   
139   if ((child = [parent childComponentWithName:key]) == nil) {
140     [[_ctx session]
141            logWithFormat:
142              @"WARNING: did not find child component %@ of parent %@",
143              key, [parent name]];
144     [_response appendContentString:@"<pre>[missing component: "];
145     [_response appendContentHTMLString:key];
146     [_response appendContentString:@"]</pre>"];
147     return;
148   }
149   
150   WOContext_enterComponent(_ctx, child, nil /*self->template*/);
151   [child appendToResponse:_response inContext:_ctx];
152   WOContext_leaveComponent(_ctx, child);
153 }
154
155 @end /* ODREmbedComponent */