mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
* Source/NSXMLPrivate.h: Move private method declarations for
NSXMLNode to here. * Source/NSXMLDocument.m * Source/NSXMLDTD.m * Source/NSXMLDTDNode.m * Source/NSXMLElement.m * Source/NSXMLNode.m: Clean up and add comments about missing code. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34877 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bff55a090d
commit
4e4bf5a00c
7 changed files with 93 additions and 117 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2012-03-04 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSXMLPrivate.h: Move private method declarations for
|
||||
NSXMLNode to here.
|
||||
* Source/NSXMLDocument.m
|
||||
* Source/NSXMLDTD.m
|
||||
* Source/NSXMLDTDNode.m
|
||||
* Source/NSXMLElement.m
|
||||
* Source/NSXMLNode.m: Clean up and add comments about missing code.
|
||||
|
||||
2012-03-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSXMLNode.m: Remove all the extra reference handling code
|
||||
|
|
|
@ -94,7 +94,7 @@ GS_PRIVATE_INTERNAL(NSXMLDTD)
|
|||
|
||||
data = [NSData dataWithContentsOfURL: url];
|
||||
doc = [self initWithData: data options: 0 error: 0];
|
||||
[doc setURI: [url absoluteString]];
|
||||
[doc setURI: [url absoluteString]];
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -110,12 +110,14 @@ GS_PRIVATE_INTERNAL(NSXMLDTD)
|
|||
{
|
||||
if (NSXMLDTDKind == kind)
|
||||
{
|
||||
/* Create holder for internal instance variables so that we'll have
|
||||
* all our ivars available rather than just those of the superclass.
|
||||
*/
|
||||
GS_CREATE_INTERNAL(NSXMLDTD)
|
||||
return [super initWithKind: kind options: theOptions];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return [[NSXMLNode alloc] initWithKind: kind
|
||||
options: theOptions];
|
||||
}
|
||||
return [super initWithKind: kind options: theOptions];
|
||||
}
|
||||
|
||||
- (void) insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index
|
||||
|
|
|
@ -44,18 +44,25 @@ GS_PRIVATE_INTERNAL(NSXMLDTDNode)
|
|||
return internal->DTDKind;
|
||||
}
|
||||
|
||||
- (void) _createInternal
|
||||
{
|
||||
GS_CREATE_INTERNAL(NSXMLDTDNode);
|
||||
}
|
||||
|
||||
- (id) initWithKind: (NSXMLNodeKind)kind options: (NSUInteger)theOptions
|
||||
{
|
||||
if (NSXMLEntityDeclarationKind == kind
|
||||
|| NSXMLElementDeclarationKind == kind
|
||||
|| NSXMLNotationDeclarationKind == kind)
|
||||
|| NSXMLElementDeclarationKind == kind
|
||||
|| NSXMLNotationDeclarationKind == kind)
|
||||
{
|
||||
/* Create holder for internal instance variables so that we'll have
|
||||
* all our ivars available rather than just those of the superclass.
|
||||
*/
|
||||
GS_CREATE_INTERNAL(NSXMLDTDNode)
|
||||
return [super initWithKind: kind options: theOptions];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self release];
|
||||
return [[NSXMLNode alloc] initWithKind: kind
|
||||
options: theOptions];
|
||||
}
|
||||
return [super initWithKind: kind options: theOptions];
|
||||
}
|
||||
|
||||
- (id) initWithXMLString: (NSString*)string
|
||||
|
|
|
@ -29,13 +29,6 @@
|
|||
#import "NSXMLPrivate.h"
|
||||
#import "GSInternal.h"
|
||||
|
||||
#ifdef HAVE_LIBXSLT
|
||||
#import <libxslt/xslt.h>
|
||||
#import <libxslt/xsltInternals.h>
|
||||
#import <libxslt/transform.h>
|
||||
#import <libxslt/xsltutils.h>
|
||||
#endif
|
||||
|
||||
GS_PRIVATE_INTERNAL(NSXMLDocument)
|
||||
|
||||
//#import <Foundation/NSXMLParser.h>
|
||||
|
@ -43,17 +36,6 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
|
||||
#if defined(HAVE_LIBXML)
|
||||
|
||||
// Private methods to manage libxml pointers...
|
||||
@interface NSXMLNode (Private)
|
||||
- (void *) _node;
|
||||
- (void) _setNode: (void *)_anode;
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
|
||||
- (void) _addSubNode:(NSXMLNode *)subNode;
|
||||
- (void) _removeSubNode:(NSXMLNode *)subNode;
|
||||
- (void) _insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index;
|
||||
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind;
|
||||
@end
|
||||
|
||||
@implementation NSXMLDocument
|
||||
|
||||
+ (Class) replacementClassForClass: (Class)cls
|
||||
|
@ -112,7 +94,6 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
return doc;
|
||||
}
|
||||
|
||||
|
||||
- (id) initWithData: (NSData*)data
|
||||
options: (NSUInteger)mask
|
||||
error: (NSError**)error
|
||||
|
@ -157,6 +138,7 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
userInfo: nil];
|
||||
}
|
||||
}
|
||||
// FIXME: Free old node
|
||||
[self _setNode: doc];
|
||||
}
|
||||
return self;
|
||||
|
@ -172,7 +154,7 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
{
|
||||
[self release];
|
||||
return [[NSXMLNode alloc] initWithKind: kind
|
||||
options: theOptions];
|
||||
options: theOptions];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,6 +245,8 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
self];
|
||||
}
|
||||
|
||||
// FIXME: Should remove all sub nodes
|
||||
|
||||
xmlDocSetRootElement(MY_DOC, [root _node]);
|
||||
|
||||
// Do our subNode housekeeping...
|
||||
|
|
|
@ -31,20 +31,6 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
#if defined(HAVE_LIBXML)
|
||||
|
||||
|
||||
// Private methods to manage libxml pointers...
|
||||
@interface NSXMLNode (Private)
|
||||
- (void *) _node;
|
||||
- (void) _setNode: (void *)_anode;
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
|
||||
- (void) _addSubNode:(NSXMLNode *)subNode;
|
||||
- (void) _removeSubNode:(NSXMLNode *)subNode;
|
||||
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind;
|
||||
- (void) _insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index;
|
||||
- (void) _updateExternalRetains;
|
||||
- (void) _invalidate;
|
||||
@end
|
||||
|
||||
@implementation NSXMLElement
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -75,7 +61,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
{
|
||||
if (NSXMLElementKind == kind)
|
||||
{
|
||||
if ((self = [super initWithKind:kind options:theOptions]))
|
||||
if ((self = [super initWithKind: kind options: theOptions]))
|
||||
{
|
||||
internal->objectValue = @"";
|
||||
}
|
||||
|
@ -85,7 +71,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
{
|
||||
[self release];
|
||||
return [[NSXMLNode alloc] initWithKind: kind
|
||||
options: theOptions];
|
||||
options: theOptions];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,26 +82,26 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (id) initWithName: (NSString*)name URI: (NSString*)URI
|
||||
{
|
||||
if ((self = [super initWithKind: NSXMLElementKind]) != nil)
|
||||
if ((self = [self initWithKind: NSXMLElementKind]) != nil)
|
||||
{
|
||||
[self setName:name];
|
||||
ASSIGNCOPY(internal->URI, URI);
|
||||
internal->objectValue = @"";
|
||||
[self setName: name];
|
||||
[self setURI: URI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithName: (NSString*)name stringValue: (NSString*)string
|
||||
{
|
||||
if ([self initWithName: name URI: nil] != nil)
|
||||
if ((self = [self initWithName: name URI: nil]) != nil)
|
||||
{
|
||||
NSXMLNode *t;
|
||||
|
||||
t = [[NSXMLNode alloc] initWithKind: NSXMLTextKind];
|
||||
[t setStringValue: string];
|
||||
[self addChild: t];
|
||||
[t release];
|
||||
}
|
||||
return nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithXMLString: (NSString*)string
|
||||
|
@ -132,6 +118,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
[result detach]; // detach from document.
|
||||
}
|
||||
[tempDoc release];
|
||||
[self release];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -146,7 +133,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
NSString *n = StringFromXMLStringPtr(cur->name);
|
||||
if ([n isEqualToString: name])
|
||||
{
|
||||
NSXMLNode *node = (NSXMLNode *)(cur->_private);
|
||||
NSXMLNode *node = [NSXMLNode _objectForNode: cur];
|
||||
[results addObject: node];
|
||||
}
|
||||
}
|
||||
|
@ -162,9 +149,10 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) addAttribute: (NSXMLNode*)attribute
|
||||
{
|
||||
xmlNodePtr node = (xmlNodePtr)(internal->node);
|
||||
xmlNodePtr node = MY_NODE;
|
||||
xmlAttrPtr attr = (xmlAttrPtr)[attribute _node];
|
||||
xmlAttrPtr oldAttr = xmlHasProp(node, attr->name);
|
||||
|
||||
if (nil != [attribute parent])
|
||||
{
|
||||
[NSException raise: @"NSInvalidArgumentException"
|
||||
|
@ -196,14 +184,13 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
}
|
||||
}
|
||||
xmlAddChild(node, (xmlNodePtr)attr);
|
||||
[self _addSubNode:attribute];
|
||||
[self _addSubNode: attribute];
|
||||
}
|
||||
|
||||
- (void) removeAttributeForName: (NSString*)name
|
||||
{
|
||||
xmlNodePtr node = (xmlNodePtr)(internal->node);
|
||||
xmlAttrPtr attr = xmlHasProp(node, (xmlChar *)[name UTF8String]);
|
||||
xmlAttrPtr newAttr = NULL;
|
||||
xmlNodePtr node = MY_NODE;
|
||||
xmlAttrPtr attr = xmlHasProp(node, XMLSTRING(name));
|
||||
NSXMLNode *attrNode = nil;
|
||||
|
||||
if (NULL == attr)
|
||||
|
@ -211,21 +198,8 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
return;
|
||||
}
|
||||
|
||||
// We need a copy of the node because xmlRemoveProp() frees attr:
|
||||
newAttr = xmlCopyProp(NULL, attr);
|
||||
attrNode = [NSXMLNode _objectForNode: (xmlNodePtr)attr];
|
||||
|
||||
// This is supposed to return failure for DTD defined attributes
|
||||
if (0 == xmlRemoveProp(attr))
|
||||
{
|
||||
[attrNode _setNode: newAttr];
|
||||
[self _removeSubNode: attrNode];
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this case we throw away our copy again.
|
||||
xmlFreeProp(newAttr);
|
||||
}
|
||||
[attrNode detach];
|
||||
}
|
||||
|
||||
- (void) setAttributes: (NSArray*)attributes
|
||||
|
@ -233,6 +207,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
NSEnumerator *enumerator = [attributes objectEnumerator];
|
||||
NSXMLNode *attribute;
|
||||
|
||||
// FIXME: Remove all previous attributes
|
||||
while ((attribute = [enumerator nextObject]) != nil)
|
||||
{
|
||||
[self addAttribute: attribute];
|
||||
|
@ -249,7 +224,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
NSEnumerator *en = [attributes keyEnumerator];
|
||||
NSString *key;
|
||||
|
||||
// [internal->attributes removeAllObjects];
|
||||
// FIXME: Remove all previous attributes
|
||||
while ((key = [en nextObject]) != nil)
|
||||
{
|
||||
NSString *val = [[attributes objectForKey: key] stringValue];
|
||||
|
@ -261,15 +236,16 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (NSArray*) attributes
|
||||
{
|
||||
NSMutableArray *attributes = [NSMutableArray array];
|
||||
xmlNodePtr node = MY_NODE;
|
||||
struct _xmlAttr *attributeNode = node->properties;
|
||||
NSMutableArray *attributes = [NSMutableArray array];
|
||||
xmlNodePtr node = MY_NODE;
|
||||
xmlAttrPtr attributeNode = node->properties;
|
||||
|
||||
while (attributeNode)
|
||||
{
|
||||
NSXMLNode *attribute;
|
||||
attribute = [NSXMLNode _objectForNode:(xmlNodePtr)attributeNode];
|
||||
[attributes addObject:attribute];
|
||||
|
||||
attribute = [NSXMLNode _objectForNode: (xmlNodePtr)attributeNode];
|
||||
[attributes addObject: attribute];
|
||||
attributeNode = attributeNode->next;
|
||||
}
|
||||
return attributes;
|
||||
|
@ -278,16 +254,14 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
- (NSXMLNode*) attributeForName: (NSString*)name
|
||||
{
|
||||
NSXMLNode *result = nil;
|
||||
xmlChar *xmlName = xmlCharStrdup([name UTF8String]);
|
||||
xmlAttrPtr attributeNode = xmlHasProp(MY_NODE, xmlName);
|
||||
xmlAttrPtr attributeNode = xmlHasProp(MY_NODE, XMLSTRING(name));
|
||||
|
||||
if (NULL != attributeNode)
|
||||
{
|
||||
result = [NSXMLNode _objectForNode:(xmlNodePtr)attributeNode];
|
||||
result = [NSXMLNode _objectForNode: (xmlNodePtr)attributeNode];
|
||||
}
|
||||
free(xmlName); // Free the name string since it's no longer needed.
|
||||
xmlName = NULL;
|
||||
return result; // [internal->attributes objectForKey: name];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSXMLNode*) attributeForLocalName: (NSString*)localName
|
||||
|
@ -463,7 +437,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
if (index >= [self childCount])
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"index too large"];
|
||||
format: @"index too large"];
|
||||
}
|
||||
|
||||
child = [self childAtIndex: index];
|
||||
|
@ -496,7 +470,8 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
static void
|
||||
joinTextNodes(xmlNodePtr nodeA, xmlNodePtr nodeB, NSMutableArray *nodesToDelete)
|
||||
{
|
||||
NSXMLNode *objA = (nodeA->_private), *objB = (nodeB->_private);
|
||||
NSXMLNode *objA = (nodeA->_private);
|
||||
NSXMLNode *objB = (nodeB->_private);
|
||||
|
||||
xmlTextMerge(nodeA, nodeB); // merge nodeB into nodeA
|
||||
|
||||
|
@ -508,12 +483,12 @@ joinTextNodes(xmlNodePtr nodeA, xmlNodePtr nodeB, NSMutableArray *nodesToDelete)
|
|||
* pointing to a freed node
|
||||
*/
|
||||
[objB _invalidate];
|
||||
[nodesToDelete addObject:objB];
|
||||
[nodesToDelete addObject: objB];
|
||||
}
|
||||
}
|
||||
else if (objB != nil) // there is no objA -- objB gets the merged node
|
||||
{
|
||||
[objB _setNode:nodeA]; // nodeA is the remaining (merged) node
|
||||
[objB _setNode: nodeA]; // nodeA is the remaining (merged) node
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,6 +503,7 @@ joinTextNodes(xmlNodePtr nodeA, xmlNodePtr nodeB, NSMutableArray *nodesToDelete)
|
|||
xmlNodePtr node = [subNode _node];
|
||||
xmlNodePtr prev = node->prev;
|
||||
xmlNodePtr next = node->next;
|
||||
|
||||
if (node->type == XML_ELEMENT_NODE)
|
||||
{
|
||||
[(NSXMLElement *)subNode
|
||||
|
@ -568,7 +544,6 @@ joinTextNodes(xmlNodePtr nodeA, xmlNodePtr nodeB, NSMutableArray *nodesToDelete)
|
|||
{
|
||||
[self _removeSubNode:subNode];
|
||||
}
|
||||
[self _updateExternalRetains];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,19 +206,6 @@ isEqualTree(xmlNodePtr nodeA, xmlNodePtr nodeB)
|
|||
return NO;
|
||||
}
|
||||
|
||||
// Private methods to manage libxml pointers...
|
||||
@interface NSXMLNode (Private)
|
||||
- (void *) _node;
|
||||
- (void) _setNode: (void *)_anode;
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
|
||||
- (void) _addSubNode: (NSXMLNode *)subNode;
|
||||
- (void) _removeSubNode: (NSXMLNode *)subNode;
|
||||
- (id) _initWithNode: (xmlNodePtr)node kind: (NSXMLNodeKind)kind;
|
||||
- (xmlNodePtr) _childNodeAtIndex: (NSUInteger)index;
|
||||
- (void) _insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index;
|
||||
- (void) _invalidate;
|
||||
@end
|
||||
|
||||
@implementation NSXMLNode (Private)
|
||||
- (void *) _node
|
||||
{
|
||||
|
@ -227,10 +214,12 @@ isEqualTree(xmlNodePtr nodeA, xmlNodePtr nodeB)
|
|||
|
||||
- (void) _setNode: (void *)_anode
|
||||
{
|
||||
if (_anode)
|
||||
((xmlNodePtr)_anode)->_private = self;
|
||||
internal->node = _anode;
|
||||
DESTROY(internal->subNodes);
|
||||
if (_anode)
|
||||
{
|
||||
((xmlNodePtr)_anode)->_private = self;
|
||||
}
|
||||
internal->node = _anode;
|
||||
}
|
||||
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node
|
||||
|
@ -318,7 +307,8 @@ isEqualTree(xmlNodePtr nodeA, xmlNodePtr nodeB)
|
|||
// retain temporarily so we can safely remove from our subNodes list first
|
||||
[subNode retain];
|
||||
[internal->subNodes removeObjectIdenticalTo: subNode];
|
||||
[subNode release]; // release temporary hold
|
||||
// release temporary hold. Apple seems to do an autorelease here.
|
||||
[subNode autorelease];
|
||||
}
|
||||
|
||||
- (void) _createInternal
|
||||
|
|
|
@ -103,16 +103,11 @@ StringFromXMLString(const unsigned char *bytes, unsigned length)
|
|||
*/
|
||||
#define GS_NSXMLNode_IVARS \
|
||||
NSUInteger kind; \
|
||||
NSXMLNode *parent; \
|
||||
void *node; \
|
||||
NSUInteger options; \
|
||||
id objectValue; \
|
||||
NSString *URI; \
|
||||
NSXMLNode *previousSibling; \
|
||||
NSXMLNode *nextSibling;\
|
||||
NSUInteger options; \
|
||||
void *node; \
|
||||
NSMutableArray *subNodes; \
|
||||
int externalRetains; \
|
||||
int retainedSelf; \
|
||||
NSMutableArray *subNodes;
|
||||
|
||||
|
||||
/* When using the non-fragile ABI, the instance variables are exposed to the
|
||||
|
@ -208,6 +203,19 @@ StringFromXMLString(const unsigned char *bytes, unsigned length)
|
|||
|
||||
#undef id
|
||||
|
||||
// Private methods to manage libxml pointers...
|
||||
@interface NSXMLNode (Private)
|
||||
- (void *) _node;
|
||||
- (void) _setNode: (void *)_anode;
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
|
||||
- (void) _addSubNode:(NSXMLNode *)subNode;
|
||||
- (void) _removeSubNode:(NSXMLNode *)subNode;
|
||||
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind;
|
||||
- (xmlNodePtr) _childNodeAtIndex: (NSUInteger)index;
|
||||
- (void) _insertChild: (NSXMLNode*)child atIndex: (NSUInteger)index;
|
||||
- (void) _invalidate;
|
||||
@end
|
||||
|
||||
#endif /* HAVE_LIBXML */
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue