2 Copyright (C) 2000-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 "_WOStringTable.h"
25 @implementation _WOStringTable
27 static NSStringEncoding stringFilesEncoding = NSUTF8StringEncoding;
29 - (id)initWithPath:(NSString *)_path {
30 if ((self = [super init])) {
31 self->path = [_path copyWithZone:[self zone]];
36 return [self initWithPath:nil];
41 [self->lastRead release];
48 - (NSException *)_handlePropertyListParseException:(NSException *)_exception {
49 [self logWithFormat:@"could not load strings file file '%@': %@",
50 self->path, _exception];
60 if (self->data != nil)
64 #if Cocoa_FOUNDATION_LIBRARY /* potentially effects OGo ;-) */
66 For WO4.5 compatibility, we need first to try to open .strings file as a
68 Dictionary must be either in UTF-8 or UTF-16 encoding.
69 If we don't do that, then a dict in UTF-8 encoding will be opened as a
70 dict using defaultCString encoding
72 plist = [NSDictionary dictionaryWithContentsOfFile:self->path];
74 self->data = [plist copy];
80 /* If file was not a dictionary, then it's a standard strings file */
82 if ((sdata = [[NSData alloc] initWithContentsOfFile:self->path]) == nil) {
83 [self errorWithFormat:@"could not read strings file: %@", self->path];
88 tmp = [[NSString alloc] initWithData:sdata encoding:stringFilesEncoding];
89 [sdata release]; sdata = nil;
91 [self errorWithFormat:@"file is not in required encoding (%d): %@",
92 stringFilesEncoding, self->path];
98 if ((plist = [tmp propertyListFromStringsFileFormat]) == nil) {
99 [self errorWithFormat:@"%s: could not load strings file '%@'",
103 [tmp release]; tmp = nil;
104 self->data = [plist copy];
107 [tmp release]; tmp = nil;
108 [[self _handlePropertyListParseException:localException] raise];
115 - (NSString *)stringForKey:(NSString *)_key withDefaultValue:(NSString *)_def {
119 value = [self->data objectForKey:_key];
120 return value != nil ? value : _def;
125 - (NSString *)description {
128 ms = [NSMutableString stringWithCapacity:128];
129 [ms appendFormat:@"<0x%08X[%@]: ", self, NSStringFromClass([self class])];
131 if (self->path) [ms appendFormat:@" path='%@'", self->path];
132 if (self->data) [ms appendFormat:@" strings=#%d", [self->data count]];
133 if (self->lastRead) [ms appendFormat:@" loaddate=%@", self->lastRead];
135 [ms appendString:@">"];
139 @end /* _WOStringTable */