]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOEntity.m
started TAL element builder
[sope] / sope-appserver / NGObjWeb / DynamicElements / WOEntity.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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
22 #include "WOHTMLDynamicElement.h"
23 #include "WOElement+private.h"
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOApplication.h>
26 #include <NGObjWeb/WOxElemBuilder.h>
27 #include <DOM/DOMProtocols.h>
28 #include "decommon.h"
29
30 @interface WOEntity : WOHTMLDynamicElement
31 {
32   // WODynamicElement: extraAttributes
33   // WODynamicElement: otherTagString
34 @protected
35   WOAssociation *name;
36 }
37
38 @end /* WOEntity */
39
40 @implementation WOEntity
41
42 - (id)initWithElement:(id<DOMElement>)_element
43   templateBuilder:(WOxElemBuilder *)_builder
44 {
45   NSString            *tname;
46   NSMutableDictionary *assocs;
47   id<NSObject,DOMNamedNodeMap> attrs;
48   unsigned count;
49   
50   tname = [_element tagName];
51   
52   /* construct associations */
53   
54   assocs = nil;
55   attrs = [_element attributes];
56   if ((count = [attrs length]) > 0)
57     assocs = [_builder associationsForAttributes:attrs];
58
59   if ([tname isEqualToString:@"nbsp"]) {
60     WOAssociation *a;
61
62     a = [_builder associationForValue:@"nbsp"];
63     if (assocs)
64       [assocs setObject:a forKey:@"name"];
65     else
66       assocs = [NSMutableDictionary dictionaryWithObject:a forKey:@"name"];
67   }
68   
69   /* construct child elements */
70   
71   if ([_element hasChildNodes]) {
72     [_builder logWithFormat:@"WARNING: element %@ has child-nodes (ignored)",
73                 _element];
74   }
75   
76   /* construct self ... */
77   self = [self initWithName:tname
78                associations:assocs 
79                contentElements:nil];
80   [(id)self setExtraAttributes:assocs];
81   return self;
82 }
83
84 - (id)initWithName:(NSString *)_name
85   associations:(NSDictionary *)_config
86   template:(WOElement *)_tmpl
87 {
88   if ((self = [super initWithName:_name associations:_config template:_tmpl])) {
89     if ((self->name = OWGetProperty(_config, @"name")) == nil) {
90       NSLog(@"%s: missing 'name' binding for entity element %@ (assocs=%@)...",
91             __PRETTY_FUNCTION__, _name, _config);
92       RELEASE(self);
93       return nil;
94     }
95   }
96   return self;
97 }
98
99 #if !LIB_FOUNDATION_BOEHM_GC
100 - (void)dealloc {
101   RELEASE(self->name);
102   [super dealloc];
103 }
104 #endif
105
106 // ******************** responder ********************
107
108 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
109   NSString *s;
110   
111   if ([[_ctx request] isFromClientComponent])
112     return;
113
114   s = [self->name stringValueInComponent:[_ctx component]];
115   if ([s length] == 0)
116     return;
117
118   WOResponse_AddChar(_response, '&');
119   WOResponse_AddString(_response, s);
120   WOResponse_AddChar(_response, ';');
121 }
122
123 /* description */
124
125 - (NSString *)associationDescription {
126   return [NSString stringWithFormat:@" name=%@",  self->name];
127 }
128
129 @end /* WOEntity */