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/ODNodeRenderer.h>
28 value - value to be generated
29 nilValue - value to be generated if value is nil
30 dateformat - a date formatting spec
32 escapehtml - bool (default: true)
33 insertbr - bool (default: false)
36 <var:string value="name"/>
39 @interface ODR_bind_string : ODNodeRenderer
43 #import <Foundation/NSDateFormatter.h>
45 @implementation ODR_bind_string
47 - (NSFormatter *)_formatterForNode:(id)_node inContext:(WOContext *)_ctx {
48 NSFormatter *formatter;
51 if ((fmt = [self stringFor:@"dateformat" node:_node ctx:_ctx])) {
52 formatter = [[NSDateFormatter alloc]
53 initWithDateFormat:fmt
54 allowNaturalLanguage:NO];
55 AUTORELEASE(formatter);
57 else if ((fmt = [self stringFor:@"numberformat" node:_node ctx:_ctx])) {
58 formatter = [[NSNumberFormatter alloc] init];
59 AUTORELEASE(formatter);
60 [(NSNumberFormatter *)formatter setFormat:fmt];
68 - (void)appendNode:(id)_node
69 toResponse:(WOResponse *)_response
70 inContext:(WOContext *)_ctx
73 NSString *string = nil;
76 NSFormatter *formatter;
78 if ((value = [self valueFor:@"value" node:_node ctx:_ctx]) == nil)
79 value = [self valueFor:@"nilValue" node:_node ctx:_ctx];
81 formatter = [self _formatterForNode:_node inContext:_ctx];
84 ? [formatter stringForObjectValue:value]
85 : [value stringValue];
90 string = [string stringValue];
92 insertBR = [self boolFor:@"insertbr" node:_node ctx:_ctx];
94 selector = ![self hasAttribute:@"escapehtml" node:_node ctx:_ctx]
95 ? @selector(appendContentHTMLString:)
96 : ([self boolFor:@"escapehtml" node:_node ctx:_ctx]
97 ? @selector(appendContentHTMLString:)
98 : @selector(appendContentString:));
101 [_response performSelector:selector withObject:string];
107 lines = [string componentsSeparatedByString:@"\n"];
108 count = [lines count];
110 for (i = 0; i < count; i++) {
111 NSString *line = [lines objectAtIndex:i];
114 [_response appendContentString:@"<br />"];
116 [_response performSelector:selector withObject:line];
121 @end /* ODR_bind_string */