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 "SaxAttributes.h"
25 @implementation SaxAttributes
28 Class c = [NSMutableArray class];
30 self->names = [[c alloc] init];
31 self->uris = [[c alloc] init];
32 self->rawNames = [[c alloc] init];
33 self->types = [[c alloc] init];
34 self->values = [[c alloc] init];
37 - (id)initWithAttributes:(id<SaxAttributes>)_attrs {
38 if ((self = [self init])) {
41 for (i = 0, c = [_attrs count]; i < c; i++) {
42 [self addAttribute:[_attrs nameAtIndex:i]
43 uri:[_attrs uriAtIndex:i]
44 rawName:[_attrs rawNameAtIndex:i]
45 type:[_attrs typeAtIndex:i]
46 value:[_attrs valueAtIndex:i]];
52 - (id)initWithAttributeList:(id<SaxAttributeList>)_attrList {
53 if ((self = [self init])) {
56 for (i = 0; i < [_attrList count]; i++) {
57 [self addAttribute:[_attrList nameAtIndex:i] uri:@""
58 rawName:[_attrList nameAtIndex:i]
59 type:[_attrList typeAtIndex:i]
60 value:[_attrList valueAtIndex:i]];
65 - (id)initWithDictionary:(NSDictionary *)_dict {
66 if ((self = [self init])) {
70 keys = [_dict keyEnumerator];
71 while ((key = [keys nextObject])) {
72 [self addAttribute:key uri:nil rawName:key
74 value:[_dict objectForKey:key]];
81 [self->names release];
83 [self->rawNames release];
84 [self->types release];
85 [self->values release];
91 - (void)addAttribute:(NSString *)_localName uri:(NSString *)_uri
92 rawName:(NSString *)_rawName
93 type:(NSString *)_type
94 value:(NSString *)_value
96 [self->names addObject:_localName ? _localName : _rawName];
97 [self->uris addObject:_uri ? _uri : (NSString *)@""];
98 [self->rawNames addObject:_rawName ? _rawName : (NSString *)@""];
99 [self->types addObject:_type ? _type : (NSString *)@"CDATA"];
100 [self->values addObject:_value];
104 [self->names removeAllObjects];
105 [self->uris removeAllObjects];
106 [self->rawNames removeAllObjects];
107 [self->types removeAllObjects];
108 [self->values removeAllObjects];
113 - (unsigned int)indexOfRawName:(NSString *)_rawName {
114 return [self->rawNames indexOfObject:_rawName];
116 - (unsigned int)indexOfName:(NSString *)_localPart uri:(NSString *)_uri
120 for (i = 0, c = [self count]; i < c; i++) {
123 name = [self nameAtIndex:i];
125 if ([name isEqualToString:_localPart]) {
128 auri = [self uriAtIndex:i];
130 //NSLog(@"found name %@", name);
132 if (([auri length] == 0) && ([_uri length] == 0))
135 if ([_uri isEqualToString:auri])
142 /* lookup data by index */
144 - (NSString *)nameAtIndex:(unsigned int)_idx {
145 return [self->names objectAtIndex:_idx];
147 - (NSString *)rawNameAtIndex:(unsigned int)_idx {
148 return [self->rawNames objectAtIndex:_idx];
150 - (NSString *)typeAtIndex:(unsigned int)_idx {
151 return [self->types objectAtIndex:_idx];
153 - (NSString *)uriAtIndex:(unsigned int)_idx {
154 return [self->uris objectAtIndex:_idx];
156 - (NSString *)valueAtIndex:(unsigned int)_idx {
157 return [self->values objectAtIndex:_idx];
160 /* lookup data by name */
162 - (NSString *)typeForRawName:(NSString *)_rawName {
165 if ((i = [self indexOfRawName:_rawName]) == NSNotFound)
168 return [self typeAtIndex:i];
170 - (NSString *)typeForName:(NSString *)_localName uri:(NSString *)_uri {
173 if ((i = [self indexOfName:_localName uri:_uri]) == NSNotFound)
176 return [self typeAtIndex:i];
179 - (NSString *)valueForRawName:(NSString *)_rawName {
182 if ((i = [self indexOfRawName:_rawName]) == NSNotFound)
185 return [self valueAtIndex:i];
187 - (NSString *)valueForName:(NSString *)_localName uri:(NSString *)_uri {
190 if ((i = [self indexOfName:_localName uri:_uri]) == NSNotFound)
193 return [self valueAtIndex:i];
198 - (unsigned int)count {
199 return [self->names count];
204 - (id)copyWithZone:(NSZone *)_zone {
205 return [(SaxAttributes *)[[self class] alloc] initWithAttributes:self];
210 - (NSString *)description {
215 s = [[NSMutableString alloc] init];
216 [s appendFormat:@"<%08X[%@]:", self, NSStringFromClass([self class])];
218 for (i = 0, c = [self count]; i < c; i++) {
221 [s appendString:@" "];
222 [s appendString:[self nameAtIndex:i]];
223 [s appendString:@"='"];
224 [s appendString:[self valueAtIndex:i]];
225 [s appendString:@"'"];
227 type = [self typeAtIndex:i];
228 if (![type isEqualToString:@"CDATA"]) {
229 [s appendString:@"["];
230 [s appendString:type];
231 [s appendString:@"]"];
234 [s appendString:@">"];
238 return [is autorelease];
241 @end /* SaxAttributes */