1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*
Copyright (C) 2000-2005 SKYRIX Software AG
This file is part of SOPE.
SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOPE 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "DOMAttribute.h"
#include "DOMDocument.h"
#include "common.h"
@implementation NGDOMAttribute
- (id)initWithName:(NSString *)_name namespaceURI:(NSString *)_uri {
if ((self = [super init])) {
self->name = [_name copy];
self->namespaceURI = [_uri copy];
}
return self;
}
- (id)initWithName:(NSString *)_name {
return [self initWithName:_name namespaceURI:nil];
}
- (void)dealloc {
[self->prefix release];
[self->name release];
[self->namespaceURI release];
[super dealloc];
}
/* element tracking */
- (void)_domNodeRegisterParentNode:(id)_element {
self->element = _element;
}
- (void)_domNodeForgetParentNode:(id)_element {
if (_element == self->element)
self->element = nil;
}
/* attributes */
- (IDOMElement)ownerElement {
return self->element;
}
- (IDOMDocument)ownerDocument {
return [[self ownerElement] ownerDocument];
}
- (BOOL)specified {
return self->isSpecified;
}
- (NSString *)name {
return self->name;
}
- (NSString *)namespaceURI {
return self->namespaceURI;
}
- (void)setPrefix:(NSString *)_prefix {
id old = self->prefix;
self->prefix = [_prefix copy];
[old release];
}
- (NSString *)prefix {
return self->prefix;
}
- (void)setValue:(NSString *)_value {
id child;
self->isSpecified = YES;
/* remove all existing children */
while ((child = [self lastChild]))
[self removeChild:child];
child = [[self ownerDocument] createTextNode:_value];
NSAssert1(child, @"couldn't create text-node child for value '%@' !", _value);
[self appendChild:child];
}
- (NSString *)_stringValueOfChildNode:(id)_node {
return [_node nodeValue];
}
- (NSString *)value {
id children;
unsigned count;
if (![self hasChildNodes])
return nil;
children = [self childNodes];
if ((count = [children count]) == 0)
return nil;
if (count == 1) {
return [self _stringValueOfChildNode:[children objectAtIndex:0]];
}
else {
unsigned i;
NSMutableString *s;
s = [NSMutableString stringWithCapacity:256];
for (i = 0; i < count; i++) {
[s appendString:
[self _stringValueOfChildNode:[children objectAtIndex:i]]];
}
return [[s copy] autorelease];
}
}
/* node */
- (BOOL)_isValidChildNode:(id)_node {
switch ([_node nodeType]) {
case DOM_TEXT_NODE:
case DOM_ENTITY_REFERENCE_NODE:
return YES;
default:
return NO;
}
}
- (DOMNodeType)nodeType {
return DOM_ATTRIBUTE_NODE;
}
- (id<NSObject,DOMNamedNodeMap>)attributes {
return nil;
}
- (id<NSObject,DOMNode>)parentNode {
return nil;
}
- (id<NSObject,DOMNode>)nextSibling {
return nil;
}
- (id<NSObject,DOMNode>)previousSibling {
return nil;
}
/* description */
- (NSString *)description {
return [NSString stringWithFormat:@"<0x%p[%@]: {%@}%@%s '%@'>",
self, NSStringFromClass([self class]),
self->namespaceURI,
[self name],
[self specified] ? " specified" : "",
[self stringValue]];
}
/* ObjCValues */
- (NSString *)stringValue {
return [self value];
}
- (int)intValue {
return [[self stringValue] intValue];
}
- (double)doubleValue {
return [[self stringValue] doubleValue];
}
/* QPValues */
- (NSException *)setQueryPathValue:(id)_value {
[self setValue:[_value stringValue]];
return nil;
}
- (id)queryPathValue {
return [self value];
}
@end /* NGDOMAttribute */
|