2007-01-31 18:11:29 +01:00
|
|
|
/* CardElement.m - this file is part of SOPE
|
|
|
|
*
|
2014-09-12 14:34:15 +02:00
|
|
|
* Copyright (C) 2006-2014 Inverse inc.
|
2007-01-31 18:11:29 +01:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-02-08 17:25:48 +01:00
|
|
|
#import <Foundation/NSRange.h>
|
2007-01-31 18:11:29 +01:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2007-10-29 16:33:51 +01:00
|
|
|
#import <NGExtensions/NGBase64Coding.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NGQuotedPrintableCoding.h>
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
#import "NSArray+NGCards.h"
|
|
|
|
#import "NSDictionary+NGCards.h"
|
|
|
|
#import "CardVersitRenderer.h"
|
|
|
|
|
|
|
|
#import "CardElement.h"
|
|
|
|
#import "CardGroup.h"
|
|
|
|
|
|
|
|
@implementation CardElement
|
|
|
|
|
|
|
|
+ (id) elementWithTag: (NSString *) aTag
|
|
|
|
{
|
|
|
|
id newElement;
|
|
|
|
|
|
|
|
newElement = [self new];
|
|
|
|
[newElement autorelease];
|
|
|
|
[newElement setTag: aTag];
|
|
|
|
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id) simpleElementWithTag: (NSString *) aTag
|
|
|
|
value: (NSString *) aValue
|
|
|
|
{
|
|
|
|
id newElement;
|
|
|
|
|
|
|
|
newElement = [self elementWithTag: aTag];
|
2011-11-14 17:07:04 +01:00
|
|
|
[newElement setSingleValue: aValue forKey: @""];
|
2007-01-31 18:11:29 +01:00
|
|
|
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id) simpleElementWithTag: (NSString *) aTag
|
|
|
|
singleType: (NSString *) aType
|
|
|
|
value: (NSString *) aValue
|
|
|
|
{
|
|
|
|
id newElement;
|
|
|
|
|
|
|
|
newElement = [self simpleElementWithTag: aTag
|
|
|
|
value: aValue];
|
|
|
|
[newElement addType: aType];
|
|
|
|
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
parent = nil;
|
|
|
|
tag = nil;
|
|
|
|
group = nil;
|
2011-11-14 17:07:04 +01:00
|
|
|
values = [NSMutableDictionary new];
|
2007-01-31 18:11:29 +01:00
|
|
|
attributes = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-12-15 23:26:50 +01:00
|
|
|
[tag release];
|
|
|
|
[group release];
|
2007-01-31 18:11:29 +01:00
|
|
|
[attributes release];
|
2008-12-15 23:26:50 +01:00
|
|
|
[values release];
|
2007-01-31 18:11:29 +01:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setParent: (CardGroup *) aParent
|
|
|
|
{
|
2009-02-06 21:15:41 +01:00
|
|
|
parent = aParent;
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
2007-11-18 10:43:52 +01:00
|
|
|
- (id) parent
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTag: (NSString *) aTag
|
|
|
|
{
|
2008-07-07 17:50:50 +02:00
|
|
|
ASSIGN (tag, aTag);
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
2008-12-15 23:26:50 +01:00
|
|
|
- (NSString *) tag
|
|
|
|
{
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
- (void) setGroup: (NSString *) aGroup
|
|
|
|
{
|
2008-07-07 17:50:50 +02:00
|
|
|
ASSIGN (group, aGroup);
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) group
|
|
|
|
{
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
/* values */
|
|
|
|
- (void) setValues: (NSMutableDictionary *) newValues
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
ASSIGN (values, newValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) values
|
|
|
|
{
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setValues: (NSMutableArray *) newValues
|
|
|
|
atIndex: (NSUInteger) idx
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
NSMutableArray *oldValues, *subValues;
|
|
|
|
|
|
|
|
oldValues = [self valuesForKey: key];
|
|
|
|
if (!oldValues)
|
|
|
|
{
|
|
|
|
oldValues = [NSMutableArray new];
|
|
|
|
[values setObject: oldValues forKey: key];
|
|
|
|
[oldValues release];
|
|
|
|
}
|
|
|
|
|
|
|
|
while ([oldValues count] < (idx + 1))
|
|
|
|
{
|
|
|
|
subValues = [NSMutableArray new];
|
|
|
|
[oldValues addObject: subValues];
|
|
|
|
[subValues release];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newValues)
|
|
|
|
newValues = [NSMutableArray array];
|
|
|
|
[oldValues replaceObjectAtIndex: idx withObject: newValues];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSingleValue: (NSString *) newValue
|
|
|
|
atIndex: (NSUInteger) idx
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
NSMutableArray *subValues;
|
|
|
|
|
|
|
|
if (newValue)
|
|
|
|
{
|
|
|
|
subValues = [NSMutableArray new];
|
|
|
|
[subValues addObject: newValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
subValues = nil;
|
|
|
|
[self setValues: subValues atIndex: idx forKey: key];
|
|
|
|
[subValues release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSingleValue: (NSString *) newValue
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
[self setSingleValue: newValue
|
|
|
|
atIndex: 0 forKey: key];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableArray *) valuesForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
return [values objectForKey: [key lowercaseString]];
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
- (NSMutableArray *) valuesAtIndex: (NSUInteger) idx
|
|
|
|
forKey: (NSString *) key
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [[self valuesForKey: key] objectAtIndex: idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) flattenedValueAtIndex: (NSUInteger) idx
|
|
|
|
forKey: (NSString *) key
|
|
|
|
{
|
|
|
|
NSMutableArray *orderedValues, *sValues;
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSMutableString *flattenedValues;
|
|
|
|
NSString *encoding, *realValue, *value;
|
|
|
|
|
|
|
|
flattenedValues = [NSMutableString string];
|
|
|
|
|
|
|
|
orderedValues = [self valuesForKey: key];
|
|
|
|
max = [orderedValues count];
|
|
|
|
if (max > idx)
|
|
|
|
{
|
|
|
|
encoding = [[self value: 0 ofAttribute: @"encoding"]
|
|
|
|
lowercaseString];
|
|
|
|
sValues = [orderedValues objectAtIndex: idx];
|
|
|
|
max = [sValues count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
if (count > 0)
|
|
|
|
[flattenedValues appendString: @","];
|
|
|
|
realValue = [sValues objectAtIndex: count];
|
|
|
|
if ([encoding isEqualToString: @"quoted-printable"])
|
|
|
|
value = [realValue stringByDecodingQuotedPrintable];
|
|
|
|
else if ([encoding isEqualToString: @"base64"])
|
|
|
|
value = [realValue stringByDecodingBase64];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = realValue;
|
|
|
|
if ([encoding length] && ![encoding isEqualToString: @"8bit"])
|
|
|
|
[self logWithFormat: @"unknown encoding '%@'", encoding];
|
|
|
|
}
|
|
|
|
|
|
|
|
[flattenedValues appendString: value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flattenedValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) flattenedValuesForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
NSMutableArray *orderedValues, *sValues;
|
|
|
|
NSUInteger count, max, sCount, sMax;
|
|
|
|
NSMutableString *flattenedValues;
|
|
|
|
NSString *encoding, *realValue, *value;
|
|
|
|
|
|
|
|
encoding = [[self value: 0 ofAttribute: @"encoding"]
|
|
|
|
lowercaseString];
|
|
|
|
|
|
|
|
flattenedValues = [NSMutableString string];
|
|
|
|
|
|
|
|
orderedValues = [self valuesForKey: key];
|
|
|
|
max = [orderedValues count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
if (count > 0)
|
|
|
|
[flattenedValues appendString: @";"];
|
|
|
|
sValues = [orderedValues objectAtIndex: count];
|
|
|
|
sMax = [sValues count];
|
|
|
|
for (sCount = 0; sCount < sMax; sCount++)
|
|
|
|
{
|
|
|
|
if (sCount > 0)
|
|
|
|
[flattenedValues appendString: @","];
|
|
|
|
realValue = [sValues objectAtIndex: sCount];
|
|
|
|
if ([encoding isEqualToString: @"quoted-printable"])
|
|
|
|
value = [realValue stringByDecodingQuotedPrintable];
|
|
|
|
else if ([encoding isEqualToString: @"base64"])
|
|
|
|
value = [realValue stringByDecodingBase64];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = realValue;
|
|
|
|
if ([encoding length] && ![encoding isEqualToString: @"8bit"])
|
|
|
|
[self logWithFormat: @"unknown encoding '%@'", encoding];
|
|
|
|
}
|
|
|
|
|
|
|
|
[flattenedValues appendString: value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flattenedValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attributes */
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) attributes
|
|
|
|
{
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAttributesAsCopy: (NSMutableDictionary *) someAttributes
|
|
|
|
{
|
|
|
|
ASSIGN (attributes, someAttributes);
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addAttribute: (NSString *) anAttribute
|
2008-07-07 17:50:50 +02:00
|
|
|
value: (NSString *) aValue
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
|
|
|
NSMutableArray *attrValues;
|
|
|
|
|
2008-07-07 17:50:50 +02:00
|
|
|
if (!aValue)
|
|
|
|
aValue = @"";
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
attrValues = [attributes objectForCaseInsensitiveKey: anAttribute];
|
|
|
|
if (!attrValues)
|
|
|
|
{
|
2009-10-13 16:10:17 +02:00
|
|
|
attrValues = [NSMutableArray array];
|
2007-01-31 18:11:29 +01:00
|
|
|
[attributes setObject: attrValues forKey: anAttribute];
|
|
|
|
}
|
|
|
|
|
2008-07-07 17:50:50 +02:00
|
|
|
[attrValues addObject: aValue];
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeValue: (NSString *) aValue
|
|
|
|
fromAttribute: (NSString *) anAttribute
|
|
|
|
{
|
|
|
|
NSMutableArray *attrValues;
|
|
|
|
NSString *currentValue;
|
|
|
|
|
2008-07-07 17:50:50 +02:00
|
|
|
if (!aValue)
|
|
|
|
aValue = @"";
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
attrValues = [attributes objectForCaseInsensitiveKey: anAttribute];
|
|
|
|
if (attrValues)
|
|
|
|
{
|
|
|
|
currentValue = [attrValues valueForCaseInsensitiveString: aValue];
|
|
|
|
while (currentValue)
|
|
|
|
{
|
|
|
|
[attrValues removeObject: currentValue];
|
|
|
|
currentValue = [attrValues valueForCaseInsensitiveString: aValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addAttributes: (NSDictionary *) someAttributes
|
|
|
|
{
|
|
|
|
NSEnumerator *keys;
|
|
|
|
NSString *currentKey;
|
|
|
|
NSMutableArray *oldValues;
|
|
|
|
NSArray *newValues;
|
|
|
|
|
|
|
|
keys = [[someAttributes allKeys] objectEnumerator];
|
|
|
|
currentKey = [keys nextObject];
|
|
|
|
while (currentKey)
|
|
|
|
{
|
|
|
|
oldValues = [attributes objectForCaseInsensitiveKey: currentKey];
|
|
|
|
newValues = [someAttributes objectForKey: currentKey];
|
|
|
|
if (oldValues)
|
|
|
|
[oldValues addObjectsFromArray: newValues];
|
|
|
|
else
|
|
|
|
[attributes setObject: newValues forKey: currentKey];
|
|
|
|
currentKey = [keys nextObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addType: (NSString *) aType
|
|
|
|
{
|
|
|
|
[self addAttribute: @"type" value: aType];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasAttribute: (NSString *) anAttribute
|
|
|
|
havingValue: (NSString *) aValue
|
|
|
|
{
|
|
|
|
NSArray *attribute;
|
|
|
|
|
|
|
|
attribute = [attributes objectForCaseInsensitiveKey: anAttribute];
|
|
|
|
|
|
|
|
return (attribute && [attribute hasCaseInsensitiveString: aValue]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setValue: (unsigned int) anInt
|
|
|
|
ofAttribute: (NSString *) anAttribute
|
|
|
|
to: (NSString *) aValue
|
|
|
|
{
|
|
|
|
NSMutableArray *attrValues;
|
|
|
|
|
2008-07-07 17:50:50 +02:00
|
|
|
if (!aValue)
|
|
|
|
aValue = @"";
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
attrValues = [attributes objectForCaseInsensitiveKey: anAttribute];
|
|
|
|
if (!attrValues)
|
|
|
|
{
|
2009-10-13 16:10:17 +02:00
|
|
|
attrValues = [NSMutableArray array];
|
2007-01-31 18:11:29 +01:00
|
|
|
[attributes setObject: attrValues forKey: anAttribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
while ([attrValues count] <= anInt)
|
|
|
|
[attrValues addObject: @""];
|
|
|
|
[attrValues replaceObjectAtIndex: anInt
|
|
|
|
withObject: aValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) value: (unsigned int) anInt
|
|
|
|
ofAttribute: (NSString *) anAttribute
|
|
|
|
{
|
|
|
|
NSArray *attrValues;
|
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
attrValues = [attributes objectForCaseInsensitiveKey: anAttribute];
|
|
|
|
if (attrValues && [attrValues count] > anInt)
|
|
|
|
value = [attrValues objectAtIndex: anInt];
|
|
|
|
else
|
|
|
|
value = @"";
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
NSMutableString *str;
|
|
|
|
|
|
|
|
str = [NSMutableString stringWithCapacity:64];
|
|
|
|
[str appendFormat:@"<%p[%@]:", self, NSStringFromClass([self class])];
|
|
|
|
if (group)
|
|
|
|
[str appendFormat: @"%@ (group: %@)\n", tag, group];
|
|
|
|
else
|
|
|
|
[str appendFormat: @"%@\n", tag, group];
|
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
[str appendString: [self versitString]];
|
2007-01-31 18:11:29 +01:00
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
return str;
|
|
|
|
}
|
2007-01-31 18:11:29 +01:00
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
static inline BOOL
|
2012-11-17 21:33:07 +01:00
|
|
|
_subValuesAreVoid (id subValues)
|
2011-11-14 17:07:04 +01:00
|
|
|
{
|
|
|
|
BOOL result = YES;
|
|
|
|
NSUInteger count, max;
|
2007-01-31 18:11:29 +01:00
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
result = YES;
|
|
|
|
|
2012-11-17 21:33:07 +01:00
|
|
|
if ([subValues isKindOfClass: [NSArray class]])
|
|
|
|
{
|
|
|
|
max = [subValues count];
|
|
|
|
for (count = 0; result && count < max; count++)
|
|
|
|
result = ([[subValues objectAtIndex: count] length] == 0);
|
|
|
|
}
|
2011-11-14 17:07:04 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL
|
|
|
|
_orderedValuesAreVoid (NSArray *orderedValues)
|
|
|
|
{
|
|
|
|
BOOL result = YES;
|
|
|
|
NSUInteger count, max;
|
|
|
|
|
|
|
|
result = YES;
|
|
|
|
|
|
|
|
max = [orderedValues count];
|
|
|
|
for (count = 0; result && count < max; count++)
|
|
|
|
result = _subValuesAreVoid ([orderedValues objectAtIndex: count]);
|
|
|
|
|
|
|
|
return result;
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isVoid
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
BOOL result = YES;
|
|
|
|
NSArray *keys;
|
|
|
|
NSMutableArray *orderedValues;
|
|
|
|
NSUInteger count, max;
|
2007-01-31 18:11:29 +01:00
|
|
|
|
2011-11-14 17:07:04 +01:00
|
|
|
keys = [values allKeys];
|
|
|
|
max = [keys count];
|
|
|
|
for (count = 0; result && count < max; count++)
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
orderedValues = [values objectForKey: [keys objectAtIndex: count]];
|
|
|
|
result = _orderedValuesAreVoid (orderedValues);
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-19 04:49:25 +02:00
|
|
|
- (NSArray *) orderOfAttributeKeys
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) orderOfValueKeys
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
- (NSString *) versitString
|
|
|
|
{
|
|
|
|
NSString *string;
|
2007-03-07 22:20:16 +01:00
|
|
|
CardVersitRenderer *renderer;
|
2007-01-31 18:11:29 +01:00
|
|
|
|
|
|
|
renderer = [CardVersitRenderer new];
|
|
|
|
string = [renderer render: self];
|
|
|
|
[renderer release];
|
|
|
|
|
2007-07-04 17:59:00 +02:00
|
|
|
if ([string hasSuffix: @"\r\n"])
|
|
|
|
string = [string substringToIndex: [string length] - 2];
|
|
|
|
|
|
|
|
return string;
|
2007-01-31 18:11:29 +01:00
|
|
|
}
|
|
|
|
|
2008-08-05 03:46:41 +02:00
|
|
|
- (id) elementWithClass: (Class) elementClass
|
2007-01-31 18:11:29 +01:00
|
|
|
{
|
|
|
|
CardElement *newElement;
|
|
|
|
|
|
|
|
if ([self isKindOfClass: elementClass])
|
|
|
|
newElement = self;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newElement = [elementClass new];
|
|
|
|
[newElement autorelease];
|
|
|
|
[newElement setTag: tag];
|
2010-10-26 20:21:55 +02:00
|
|
|
[newElement setValues: values];
|
2007-01-31 18:11:29 +01:00
|
|
|
[newElement setAttributesAsCopy: attributes];
|
|
|
|
if (group)
|
|
|
|
[newElement setGroup: group];
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
[newElement setParent: parent];
|
|
|
|
[parent replaceThisElement: self
|
|
|
|
withThisOne: newElement];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CardGroup *) searchParentOfClass: (Class) parentClass
|
|
|
|
{
|
|
|
|
CardGroup *current;
|
|
|
|
CardGroup *found;
|
|
|
|
|
|
|
|
found = nil;
|
|
|
|
current = parent;
|
|
|
|
while (current && !found)
|
|
|
|
if ([current isKindOfClass: parentClass])
|
|
|
|
found = current;
|
|
|
|
else
|
|
|
|
current = [current parent];
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NSCopying */
|
|
|
|
|
2008-08-05 03:46:41 +02:00
|
|
|
- (NSMutableArray *) deepCopyOfArray: (NSArray *) oldArray
|
|
|
|
withZone: (NSZone *) aZone
|
|
|
|
{
|
|
|
|
NSMutableArray *newArray;
|
|
|
|
unsigned int count, max;
|
|
|
|
id newChild;
|
|
|
|
|
|
|
|
newArray = [NSMutableArray array];
|
|
|
|
|
|
|
|
max = [oldArray count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
newChild = [[oldArray objectAtIndex: count] mutableCopyWithZone: aZone];
|
|
|
|
[newArray addObject: newChild];
|
2008-12-15 23:26:50 +01:00
|
|
|
[newChild release];
|
2008-08-05 03:46:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return newArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) deepCopyOfDictionary: (NSDictionary *) oldDictionary
|
|
|
|
withZone: (NSZone *) aZone
|
|
|
|
{
|
|
|
|
NSMutableDictionary *newDict;
|
|
|
|
NSArray *newKeys, *newValues;
|
|
|
|
|
|
|
|
newKeys = [self deepCopyOfArray: [oldDictionary allKeys]
|
|
|
|
withZone: aZone];
|
|
|
|
newValues = [self deepCopyOfArray: [oldDictionary allValues]
|
|
|
|
withZone: aZone];
|
|
|
|
newDict = [NSMutableDictionary dictionaryWithObjects: newValues
|
|
|
|
forKeys: newKeys];
|
|
|
|
|
|
|
|
return newDict;
|
|
|
|
}
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
- (id) copyWithZone: (NSZone *) aZone
|
|
|
|
{
|
|
|
|
CardElement *new;
|
2009-10-10 20:33:37 +02:00
|
|
|
NSString *newTag, *newGroup;
|
2007-01-31 18:11:29 +01:00
|
|
|
|
|
|
|
new = [[self class] new];
|
2009-10-10 20:33:37 +02:00
|
|
|
newTag = [tag copyWithZone: aZone];
|
|
|
|
[new setTag: newTag];
|
|
|
|
[newTag release];
|
|
|
|
newGroup = [group copyWithZone: aZone];
|
|
|
|
[new setGroup: newGroup];
|
|
|
|
[newGroup release];
|
2011-11-14 17:07:04 +01:00
|
|
|
[new setValues: [self deepCopyOfDictionary: values withZone: aZone]];
|
2008-08-05 03:46:41 +02:00
|
|
|
[new setAttributesAsCopy: [self deepCopyOfDictionary: attributes
|
|
|
|
withZone: aZone]];
|
2007-01-31 18:11:29 +01:00
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2007-11-18 10:43:52 +01:00
|
|
|
/* NSMutableCopying */
|
|
|
|
- (id) mutableCopyWithZone: (NSZone *) aZone
|
|
|
|
{
|
2011-11-14 17:07:04 +01:00
|
|
|
return [self copyWithZone: aZone];
|
2007-11-18 10:43:52 +01:00
|
|
|
}
|
|
|
|
|
2007-01-31 18:11:29 +01:00
|
|
|
@end
|