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 "SaxAttributes.h"
26 @implementation SaxAttributes
29 Class c = [NSMutableArray class];
31 self->names = [[c alloc] init];
32 self->uris = [[c alloc] init];
33 self->rawNames = [[c alloc] init];
34 self->types = [[c alloc] init];
35 self->values = [[c alloc] init];
38 - (id)initWithAttributes:(id<SaxAttributes>)_attrs {
39 if ((self = [self init])) {
42 for (i = 0, c = [_attrs count]; i < c; i++) {
43 [self addAttribute:[_attrs nameAtIndex:i]
44 uri:[_attrs uriAtIndex:i]
45 rawName:[_attrs rawNameAtIndex:i]
46 type:[_attrs typeAtIndex:i]
47 value:[_attrs valueAtIndex:i]];
53 - (id)initWithAttributeList:(id<SaxAttributeList>)_attrList {
54 if ((self = [self init])) {
57 for (i = 0; i < [_attrList count]; i++) {
58 [self addAttribute:[_attrList nameAtIndex:i] uri:@""
59 rawName:[_attrList nameAtIndex:i]
60 type:[_attrList typeAtIndex:i]
61 value:[_attrList valueAtIndex:i]];
66 - (id)initWithDictionary:(NSDictionary *)_dict {
67 if ((self = [self init])) {
71 keys = [_dict keyEnumerator];
72 while ((key = [keys nextObject])) {
73 [self addAttribute:key uri:nil rawName:key
75 value:[_dict objectForKey:key]];
82 [self->names release];
84 [self->rawNames release];
85 [self->types release];
86 [self->values release];
92 - (void)addAttribute:(NSString *)_localName uri:(NSString *)_uri
93 rawName:(NSString *)_rawName
94 type:(NSString *)_type
95 value:(NSString *)_value
97 [self->names addObject:_localName ? _localName : _rawName];
98 [self->uris addObject:_uri ? _uri : @""];
99 [self->rawNames addObject:_rawName ? _rawName : @""];
100 [self->types addObject:_type ? _type : @"CDATA"];
101 [self->values addObject:_value];
105 [self->names removeAllObjects];
106 [self->uris removeAllObjects];
107 [self->rawNames removeAllObjects];
108 [self->types removeAllObjects];
109 [self->values removeAllObjects];
114 - (unsigned int)indexOfRawName:(NSString *)_rawName {
115 return [self->rawNames indexOfObject:_rawName];
117 - (unsigned int)indexOfName:(NSString *)_localPart uri:(NSString *)_uri
121 for (i = 0, c = [self count]; i < c; i++) {
124 name = [self nameAtIndex:i];
126 if ([name isEqualToString:_localPart]) {
129 auri = [self uriAtIndex:i];
131 //NSLog(@"found name %@", name);
133 if (([auri length] == 0) && ([_uri length] == 0))
136 if ([_uri isEqualToString:auri])
143 /* lookup data by index */
145 - (NSString *)nameAtIndex:(unsigned int)_idx {
146 return [self->names objectAtIndex:_idx];
148 - (NSString *)rawNameAtIndex:(unsigned int)_idx {
149 return [self->rawNames objectAtIndex:_idx];
151 - (NSString *)typeAtIndex:(unsigned int)_idx {
152 return [self->types objectAtIndex:_idx];
154 - (NSString *)uriAtIndex:(unsigned int)_idx {
155 return [self->uris objectAtIndex:_idx];
157 - (NSString *)valueAtIndex:(unsigned int)_idx {
158 return [self->values objectAtIndex:_idx];
161 /* lookup data by name */
163 - (NSString *)typeForRawName:(NSString *)_rawName {
166 if ((i = [self indexOfRawName:_rawName]) == NSNotFound)
169 return [self typeAtIndex:i];
171 - (NSString *)typeForName:(NSString *)_localName uri:(NSString *)_uri {
174 if ((i = [self indexOfName:_localName uri:_uri]) == NSNotFound)
177 return [self typeAtIndex:i];
180 - (NSString *)valueForRawName:(NSString *)_rawName {
183 if ((i = [self indexOfRawName:_rawName]) == NSNotFound)
186 return [self valueAtIndex:i];
188 - (NSString *)valueForName:(NSString *)_localName uri:(NSString *)_uri {
191 if ((i = [self indexOfName:_localName uri:_uri]) == NSNotFound)
194 return [self valueAtIndex:i];
199 - (unsigned int)count {
200 return [self->names count];
205 - (id)copyWithZone:(NSZone *)_zone {
206 return [(SaxAttributes *)[[self class] alloc] initWithAttributes:self];
211 - (NSString *)description {
216 s = [[NSMutableString alloc] init];
217 [s appendFormat:@"<%08X[%@]:", self, NSStringFromClass([self class])];
219 for (i = 0, c = [self count]; i < c; i++) {
222 [s appendString:@" "];
223 [s appendString:[self nameAtIndex:i]];
224 [s appendString:@"='"];
225 [s appendString:[self valueAtIndex:i]];
226 [s appendString:@"'"];
228 type = [self typeAtIndex:i];
229 if (![type isEqualToString:@"CDATA"]) {
230 [s appendString:@"["];
231 [s appendString:type];
232 [s appendString:@"]"];
235 [s appendString:@">"];
239 return [is autorelease];
242 @end /* SaxAttributes */