2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #include <NGObjDOM/ODREmbedComponent.h>
24 #include <NGObjDOM/ODNamespaces.h>
27 @interface WOComponent(PrivateMethods)
28 - (WOComponent *)childComponentWithName:(NSString *)_cname;
31 @interface NSObject(DOMPrivates)
32 - (id)attributeNode:(NSString *)_key namespaceURI:(NSString *)_ns;
35 extern void WOContext_enterComponent
36 (WOContext *_ctx, WOComponent *_component, WOElement *element);
37 extern void WOContext_leaveComponent(WOContext *_ctx, WOComponent *_component);
39 @implementation ODREmbedComponent
41 - (NSString *)_keyForNode:(id)_domNode inContext:(WOContext *)_ctx {
45 attrNode = [_domNode attributeNode:@"id" namespaceURI:XMLNS_OD_BIND];
46 key = [attrNode textValue];
48 if ([key length] == 0) {
49 attrNode = [_domNode attributeNode:@"name" namespaceURI:XMLNS_OD_BIND];
50 key = [attrNode textValue];
53 if ([key length] == 0)
54 key = [NSString stringWithFormat:@"key0%08X", _domNode];
59 - (void)takeValuesForNode:(id)_domNode
60 fromRequest:(WORequest *)_request
61 inContext:(WOContext *)_ctx
63 WOComponent *parent, *child;
66 key = [self _keyForNode:_domNode inContext:_ctx];
68 if ((parent = [_ctx component]) == nil) {
70 logWithFormat:@"WARNING: did not find parent component of child %@",
74 if ((child = [parent childComponentWithName:key]) == nil) {
77 @"WARNING: did not find child component %@ of parent %@",
82 WOContext_enterComponent(_ctx, child, nil /*self->template*/);
83 [child takeValuesFromRequest:_request inContext:_ctx];
84 WOContext_leaveComponent(_ctx, child);
87 - (id)invokeActionForNode:(id)_domNode
88 fromRequest:(WORequest *)_request
89 inContext:(WOContext *)_ctx
92 WOComponent *parent, *child;
95 key = [self _keyForNode:_domNode inContext:_ctx];
97 if ((parent = [_ctx component]) == nil) {
99 logWithFormat:@"WARNING: did not find parent component of child %@",
103 if ((child = [parent childComponentWithName:key]) == nil) {
106 @"WARNING: did not find child component %@ of parent %@",
111 WOContext_enterComponent(_ctx, child, nil /*self->template*/);
112 result = [child invokeActionForRequest:_request inContext:_ctx];
113 WOContext_leaveComponent(_ctx, child);
118 - (void)appendNode:(id)_domNode
119 toResponse:(WOResponse *)_response
120 inContext:(WOContext *)_ctx
122 WOComponent *parent, *child;
125 if ([_domNode nodeType] != DOM_ELEMENT_NODE) {
126 [super appendNode:_domNode toResponse:_response inContext:_ctx];
130 key = [self _keyForNode:_domNode inContext:_ctx];
132 if ((parent = [_ctx component]) == nil) {
134 logWithFormat:@"WARNING: did not find parent component of child %@",
139 if ((child = [parent childComponentWithName:key]) == nil) {
142 @"WARNING: did not find child component %@ of parent %@",
144 [_response appendContentString:@"<pre>[missing component: "];
145 [_response appendContentHTMLString:key];
146 [_response appendContentString:@"]</pre>"];
150 WOContext_enterComponent(_ctx, child, nil /*self->template*/);
151 [child appendToResponse:_response inContext:_ctx];
152 WOContext_leaveComponent(_ctx, child);
155 @end /* ODREmbedComponent */