2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of SOPE.
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
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.
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
22 #include "WOLabelAssociation.h"
23 #include <NGObjWeb/WOApplication.h>
24 #include <NGObjWeb/WOComponent.h>
25 #include <NGObjWeb/WOContext.h>
26 #include <NGObjWeb/WORequest.h>
27 #include <NGObjWeb/WOResourceManager.h>
28 #include <NGObjWeb/WOSession.h>
31 @implementation WOLabelAssociation
34 return [super version] /* v2 */;
37 NSAssert2([super version] == 2,
38 @"invalid superclass (%@) version %i !",
39 NSStringFromClass([self superclass]), [super version]);
42 - (id)initWithKey:(NSString *)_key inTable:(NSString *)_table
43 withDefaultValue:(NSString *)_default
45 if ([_key length] == 0) {
46 [self warnWithFormat:@"missing label key!"];
50 if ((self = [super init])) {
51 if ([_key hasPrefix:@"$"]) {
52 self->flags.isKeyKeyPath = 1;
53 _key = [_key substringFromIndex:1];
55 if ([_table hasPrefix:@"$"]) {
56 self->flags.isTableKeyPath = 1;
57 _table = [_table substringFromIndex:1];
59 if ([_default hasPrefix:@"$"]) {
60 self->flags.isValueKeyPath = 1;
61 _default = [_default substringFromIndex:1];
64 self->key = [_key copy];
65 self->table = [_table copy];
66 self->defaultValue = [_default copy];
71 return [self initWithKey:nil inTable:nil withDefaultValue:nil];
74 - (id)initWithString:(NSString *)_str {
75 NSString *lKey, *lTable, *lVal;
78 if ([_str length] == 0) {
83 r = [_str rangeOfString:@"/"];
85 lTable = [_str substringToIndex:r.location];
86 lKey = [_str substringFromIndex:(r.location + r.length)];
94 return [self initWithKey:lKey inTable:lTable withDefaultValue:lVal];
98 [self->table release];
99 [self->defaultValue release];
106 - (void)setValue:(id)_value inComponent:(WOComponent *)_component {
108 [NSException raise:@"AssociationException"
109 format:@"association value is not settable !"];
111 - (id)valueInComponent:(WOComponent *)_component {
112 WOResourceManager *rm;
116 NSString *lKey, *lTable, *lVal;
118 /* lookup languages */
120 ctx = [_component context];
121 languages = [ctx resourceLookupLanguages];
123 /* find resource manager */
125 if ((rm = [_component resourceManager]) == nil)
126 rm = [[WOApplication application] resourceManager];
128 [self warnWithFormat:@"missing resource manager!"];
133 lTable = self->table;
134 lVal = self->defaultValue;
135 if (self->flags.isKeyKeyPath) lKey = [_component valueForKeyPath:lKey];
136 if (self->flags.isTableKeyPath) lTable = [_component valueForKeyPath:lTable];
137 if (self->flags.isValueKeyPath) lVal = [_component valueForKeyPath:lVal];
141 label = [rm stringForKey:lKey inTableNamed:lTable withDefaultValue:lVal
142 languages:languages];
146 - (BOOL)isValueConstant {
149 - (BOOL)isValueSettable {
155 - (id)copyWithZone:(NSZone *)_zone {
156 return [self retain];
161 - (NSString *)description {
162 NSMutableString *str;
164 str = [NSMutableString stringWithCapacity:64];
165 [str appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
167 if (self->flags.isKeyKeyPath)
168 [str appendFormat:@" key=%@", self->key];
170 [str appendFormat:@" key='%@'", self->key];
172 if (self->flags.isTableKeyPath)
173 [str appendFormat:@" table=%@", self->table];
175 [str appendFormat:@" table='%@'", self->table];
177 if (self->flags.isValueKeyPath)
178 [str appendFormat:@" def=%@", self->defaultValue];
180 [str appendFormat:@" def='%@'", self->defaultValue];
182 [str appendString:@">"];
186 @end /* WOLabelAssociation */