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 "SaxAttributeList.h"
24 #include "SaxAttributes.h"
27 @implementation SaxAttributeList
30 self->names = [[NSMutableArray alloc] init];
31 self->types = [[NSMutableArray alloc] init];
32 self->values = [[NSMutableArray alloc] init];
35 - (id)initWithAttributeList:(id<SaxAttributeList>)_attrList {
36 if ((self = [self init])) {
39 for (i = 0; i < [_attrList count]; i++) {
40 [self->names addObject:[_attrList nameAtIndex:i]];
41 [self->types addObject:[_attrList typeAtIndex:i]];
42 [self->values addObject:[_attrList valueAtIndex:i]];
48 - (id)initWithAttributes:(id<SaxAttributes>)_attrList {
49 if ((self = [self init])) {
52 for (i = 0, c = [_attrList count]; i < c; i++) {
53 [self->names addObject:[_attrList rawNameAtIndex:i]];
54 [self->types addObject:[_attrList typeAtIndex:i]];
55 [self->values addObject:[_attrList valueAtIndex:i]];
62 [self->names release];
63 [self->types release];
64 [self->values release];
68 /* modify operations */
70 - (void)setAttributeList:(id<SaxAttributeList>)_attrList {
75 for (i = 0; i < [_attrList count]; i++) {
76 [self->names addObject:[_attrList nameAtIndex:i]];
77 [self->types addObject:[_attrList typeAtIndex:i]];
78 [self->values addObject:[_attrList valueAtIndex:i]];
82 [self->names removeAllObjects];
83 [self->types removeAllObjects];
84 [self->values removeAllObjects];
87 - (void)addAttribute:(NSString *)_name
88 type:(NSString *)_type
89 value:(NSString *)_value
91 if (_type == nil) _type = @"CDATA";
92 if (_value == nil) _value = @"";
93 [self->names addObject:_name];
94 [self->types addObject:_type];
95 [self->values addObject:_value];
98 - (void)removeAttribute:(NSString *)_name {
101 if ((idx = [self->names indexOfObject:_name]) == NSNotFound)
104 [self->names removeObjectAtIndex:idx];
105 [self->types removeObjectAtIndex:idx];
106 [self->values removeObjectAtIndex:idx];
109 /* protocol implementation */
111 - (NSString *)nameAtIndex:(unsigned int)_idx {
112 return [self->names objectAtIndex:_idx];
114 - (NSString *)typeAtIndex:(unsigned int)_idx {
115 return [self->types objectAtIndex:_idx];
117 - (NSString *)valueAtIndex:(unsigned int)_idx {
118 return [self->values objectAtIndex:_idx];
121 - (NSString *)typeForName:(NSString *)_name {
124 if ((i = [self->names indexOfObject:_name]) == NSNotFound)
127 return [self typeAtIndex:i];
129 - (NSString *)valueForName:(NSString *)_name {
132 if ((i = [self->names indexOfObject:_name]) == NSNotFound)
135 return [self valueAtIndex:i];
138 - (unsigned int)count {
139 return [self->names count];
144 - (id)copyWithZone:(NSZone *)_zone {
145 return [[[self class] allocWithZone:_zone] initWithAttributeList:self];
152 objs[0] = self->names; keys[0] = @"names";
153 objs[1] = self->types; keys[1] = @"types";
154 objs[2] = self->values; keys[2] = @"values";
155 return [NSDictionary dictionaryWithObjects:objs forKeys:keys count:3];
158 - (NSString *)description {
163 s = [[NSMutableString alloc] init];
164 [s appendFormat:@"<%08X[%@]:", self, NSStringFromClass([self class])];
166 for (i = 0, c = [self count]; i < c; i++) {
169 [s appendString:@" "];
170 [s appendString:[self nameAtIndex:i]];
171 [s appendString:@"='"];
172 [s appendString:[self valueAtIndex:i]];
173 [s appendString:@"'"];
175 type = [self typeAtIndex:i];
176 if (![type isEqualToString:@"CDATA"]) {
177 [s appendString:@"["];
178 [s appendString:type];
179 [s appendString:@"]"];
182 [s appendString:@">"];
186 return [is autorelease];
189 @end /* SaxAttributeList */