2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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/ODRWebObject.h>
24 #include <NGObjDOM/ODNamespaces.h>
25 #include <NGObjWeb/WODynamicElement.h>
28 @interface NSObject(WOPrivates)
29 + (BOOL)isDynamicElement;
30 - (BOOL)isDynamicElement;
33 @interface _WODRTemplateElement : WODynamicElement
36 /* both non-retained */
37 ODNodeRenderer *renderer;
42 @implementation ODRWebObject
44 - (NSMutableDictionary *)associationsForNodeAttributes:(id)_domNode {
45 NSMutableDictionary *md;
49 md = [NSMutableDictionary dictionaryWithCapacity:16];
51 attrs = [(id)[_domNode attributes] objectEnumerator];
52 while ((attrNode = [attrs nextObject])) {
55 nsuri = [attrNode namespaceURI];
57 if ([nsuri isEqualToString:XMLNS_OD_BIND]) {
58 [md setObject:[WOAssociation associationWithKeyPath:[attrNode textValue]]
59 forKey:[(id<DOMAttr>)attrNode name]];
62 [md setObject:[WOAssociation associationWithValue:[attrNode textValue]]
63 forKey:[(id<DOMAttr>)attrNode name]];
70 - (WOElement *)constructElementForElementNode:(id)_domNode {
73 clazz = NSClassFromString([_domNode tagName]);
76 NSLog(@"%s: Can't find class for node %@",
77 __PRETTY_FUNCTION__, _domNode);
80 else if ([clazz isDynamicElement]) {
81 WODynamicElement *elem;
83 NSMutableDictionary *assocs;
84 _WODRTemplateElement *template;
86 elemName = [[[_domNode attributes] namedItem:@"id"] textValue];
87 assocs = [self associationsForNodeAttributes:_domNode];
90 if ([_domNode hasChildNodes]) {
91 template = [[_WODRTemplateElement alloc] init];
92 template->renderer = self;
93 template->domNode = _domNode;
94 AUTORELEASE(template);
98 elem = [elem initWithName:elemName
102 if ([assocs count] > 0)
103 [elem setExtraAttributes:assocs];
105 [assocs removeAllObjects];
107 return AUTORELEASE(elem);
110 NSLog(@"%s: Can't handle element class %@ for node %@",
117 - (void)takeValuesForNode:(id)_domNode
118 fromRequest:(WORequest *)_request
119 inContext:(WOContext *)_context
123 e = [self constructElementForElementNode:_domNode];
124 [e takeValuesFromRequest:_request inContext:_context];
127 - (id)invokeActionForNode:(id)_domNode
128 fromRequest:(WORequest *)_request
129 inContext:(WOContext *)_context
134 e = [self constructElementForElementNode:_domNode];
135 result = [e invokeActionForRequest:_request inContext:_context];
140 - (void)appendNode:(id)_domNode
141 toResponse:(WOResponse *)_response
142 inContext:(WOContext *)_context
146 if ([_domNode nodeType] != DOM_ELEMENT_NODE) {
147 [super appendNode:_domNode toResponse:_response inContext:_context];
151 e = [self constructElementForElementNode:_domNode];
152 [e appendToResponse:_response inContext:_context];
155 @end /* ODRWebObject */
157 @implementation _WODRTemplateElement
159 - (id)_childRendererForNode:(id)_node {
160 static id childRenderer = nil;
161 if (childRenderer == nil)
162 childRenderer = [[NSClassFromString(@"WODRChildNodes") alloc] init];
163 return childRenderer;
166 - (void)takeValuesFromRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
167 if (![self->domNode hasChildNodes])
170 [self->renderer takeValuesForChildNodes:[self->domNode childNodes]
175 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
176 if (![self->domNode hasChildNodes])
179 return [self->renderer invokeActionForChildNodes:[self->domNode childNodes]
184 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
185 if ([self->domNode hasChildNodes]) {
186 //NSLog(@"%s: %@ ..", __PRETTY_FUNCTION__, self->domNode);
188 [self->renderer appendChildNodes:[self->domNode childNodes]
194 @end /* _WODRTemplateElement */