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 "_WOStringTable.h"
26 @implementation _WOStringTable
28 - (id)initWithPath:(NSString *)_path {
29 if ((self = [super init])) {
30 self->path = [_path copyWithZone:[self zone]];
35 return [self initWithPath:nil];
40 [self->lastRead release];
47 - (NSException *)_handlePropertyListParseException:(NSException *)_exception {
48 [self logWithFormat:@"could not load strings file file '%@': %@",
49 self->path, _exception];
58 if (self->data != nil)
61 #if !LIB_FOUNDATION_LIBRARY /* potentially effects OGo ;-) */
63 For WO4.5 compatibility, we need first to try to open .strings file as a
65 Dictionary must be either in UTF-8 or UTF-16 encoding.
66 If we don't do that, then a dict in UTF-8 encoding will be opened as a
67 dict using defaultCString encoding
69 plist = [NSDictionary dictionaryWithContentsOfFile:self->path];
71 self->data = [plist copy];
76 /* If file was not a dictionary, then it's a standard strings file */
78 if ((tmp = [NSString stringWithContentsOfFile:self->path]) == nil) {
84 if ((plist = [tmp propertyListFromStringsFileFormat]) == nil) {
85 NSLog(@"%s: could not load strings file '%@'",
89 self->data = [plist copy];
92 [[self _handlePropertyListParseException:localException] raise];
98 - (NSString *)stringForKey:(NSString *)_key withDefaultValue:(NSString *)_def {
102 value = [self->data objectForKey:_key];
103 return value != nil ? value : _def;
108 - (NSString *)description {
111 ms = [NSMutableString stringWithCapacity:128];
112 [ms appendFormat:@"<0x%08X[%@]: ", self, NSStringFromClass([self class])];
114 if (self->path) [ms appendFormat:@" path='%@'", self->path];
115 if (self->data) [ms appendFormat:@" strings=#%d", [self->data count]];
116 if (self->lastRead) [ms appendFormat:@" loaddate=%@", self->lastRead];
118 [ms appendString:@">"];
122 @end /* _WOStringTable */