2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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 "WEStringTable.h"
25 @implementation WEStringTable
27 static BOOL debugOn = NO;
28 static BOOL useLatin1Strings = NO;
31 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
33 debugOn = [ud boolForKey:@"WEStringTableDebugEnabled"];
34 useLatin1Strings = [ud boolForKey:@"WEStringTableUseLatin1"];
37 + (id)stringTableWithPath:(NSString *)_path {
38 return [[(WEStringTable *)[self alloc] initWithPath:_path] autorelease];
41 - (id)initWithPath:(NSString *)_path {
42 self->path = [_path copyWithZone:[self zone]];
48 [self->lastRead release];
55 - (NSException *)reportParsingError:(NSException *)_error {
56 [self logWithFormat:@"%s: could not load strings file '%@': %@",
57 __PRETTY_FUNCTION__, self->path, _error];
61 - (NSStringEncoding)stringsFileEncoding {
62 return useLatin1Strings ? NSISOLatin1StringEncoding : NSUTF8StringEncoding;
66 NSString *plistString;
70 if (self->data != nil)
73 rawData = [[NSData alloc] initWithContentsOfMappedFile:self->path];
75 [self logWithFormat:@"ERROR: could not load strings file: %@", self->path];
80 [self debugWithFormat:@"read strings file %@, len: %d",
81 self->path, [rawData length]];
84 plistString = [[NSString alloc] initWithData:rawData
85 encoding:[self stringsFileEncoding]];
86 [rawData release]; rawData = nil;
87 if (plistString == nil) {
88 [self logWithFormat:@"ERROR: could not decode strings file charset: %@",
94 [self debugWithFormat:@" string len %d, class %@",
95 [plistString length], NSStringFromClass([plistString class])];
99 if ((plist = [plistString propertyListFromStringsFileFormat]) == nil) {
100 NSLog(@"%s: could not load strings file '%@'",
104 self->data = [plist copy];
105 self->lastRead = [[NSDate date] retain];
108 [[self reportParsingError:localException] raise];
112 [self debugWithFormat:@" parsed entries: %d", [self->data count]];
114 [plistString release];
119 - (NSString *)stringForKey:(NSString *)_key withDefaultValue:(NSString *)_def {
123 value = [self->data objectForKey:_key];
124 return value ? value : _def;
129 - (BOOL)isDebuggingEnabled {
133 @end /* WEStringTable */