Improve +[XMPPStanza stanzaWithElement:].
This commit is contained in:
parent
f651384d81
commit
1ffd66aa92
2 changed files with 20 additions and 33 deletions
|
@ -90,10 +90,10 @@
|
||||||
/**
|
/**
|
||||||
* Creates a new autoreleased XMPPStanza from an OFXMLElement.
|
* Creates a new autoreleased XMPPStanza from an OFXMLElement.
|
||||||
*
|
*
|
||||||
* \param elem The element to base the XMPPStanza on
|
* \param element The element to base the XMPPStanza on
|
||||||
* \return A new autoreleased XMPPStanza
|
* \return A new autoreleased XMPPStanza
|
||||||
*/
|
*/
|
||||||
+ stanzaWithElement: (OFXMLElement*)elem;
|
+ stanzaWithElement: (OFXMLElement*)element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes an already allocated XMPPStanza with the specified name.
|
* Initializes an already allocated XMPPStanza with the specified name.
|
||||||
|
@ -139,10 +139,10 @@
|
||||||
/**
|
/**
|
||||||
* Initializes an already allocated XMPPStanza based on a OFXMLElement
|
* Initializes an already allocated XMPPStanza based on a OFXMLElement
|
||||||
*
|
*
|
||||||
* \param elem The element to base the XMPPStanza on
|
* \param element The element to base the XMPPStanza on
|
||||||
* \return A initialized XMPPStanza
|
* \return A initialized XMPPStanza
|
||||||
*/
|
*/
|
||||||
- initWithElement: (OFXMLElement*)elem;
|
- initWithElement: (OFXMLElement*)element;
|
||||||
|
|
||||||
- (void)setFrom: (XMPPJID*)from;
|
- (void)setFrom: (XMPPJID*)from;
|
||||||
- (XMPPJID*)from;
|
- (XMPPJID*)from;
|
||||||
|
|
|
@ -54,9 +54,9 @@
|
||||||
ID: ID_] autorelease];
|
ID: ID_] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ stanzaWithElement: (OFXMLElement*)elem
|
+ stanzaWithElement: (OFXMLElement*)element
|
||||||
{
|
{
|
||||||
return [[[self alloc] initWithElement: elem] autorelease];
|
return [[[self alloc] initWithElement: element] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithName: (OFString*)name_
|
- initWithName: (OFString*)name_
|
||||||
|
@ -111,39 +111,26 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithElement: (OFXMLElement*)elem
|
- initWithElement: (OFXMLElement*)element
|
||||||
{
|
{
|
||||||
self = [super initWithName: [elem name]
|
self = [super initWithElement: element];
|
||||||
namespace: [elem namespace]];
|
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
OFEnumerator *enumerator;
|
OFXMLAttribute *attribute;
|
||||||
OFXMLAttribute *attr;
|
|
||||||
OFXMLElement *el;
|
|
||||||
|
|
||||||
enumerator = [[elem attributes] objectEnumerator];
|
if ((attribute = [element attributeForName: @"from"]))
|
||||||
while ((attr = [enumerator nextObject]) != nil) {
|
[self setFrom:
|
||||||
if ([[attr name] isEqual: @"from"])
|
[XMPPJID JIDWithString: [attribute stringValue]]];
|
||||||
[self setFrom: [XMPPJID JIDWithString:
|
|
||||||
[attr stringValue]]];
|
|
||||||
else if ([[attr name] isEqual: @"to"])
|
|
||||||
[self setTo: [XMPPJID JIDWithString:
|
|
||||||
[attr stringValue]]];
|
|
||||||
else if ([[attr name] isEqual: @"type"])
|
|
||||||
[self setType: [attr stringValue]];
|
|
||||||
else if ([[attr name] isEqual: @"id"])
|
|
||||||
[self setID: [attr stringValue]];
|
|
||||||
else
|
|
||||||
[self addAttribute: attr];
|
|
||||||
}
|
|
||||||
|
|
||||||
enumerator = [[elem children] objectEnumerator];
|
if ((attribute = [element attributeForName: @"to"]))
|
||||||
while ((el = [enumerator nextObject]) != nil)
|
[self setTo:
|
||||||
[self addChild: el];
|
[XMPPJID JIDWithString: [attribute stringValue]]];
|
||||||
|
|
||||||
[self setDefaultNamespace: XMPP_NS_CLIENT];
|
if ((attribute = [element attributeForName: @"type"]))
|
||||||
[self setPrefix: @"stream"
|
[self setType: [attribute stringValue]];
|
||||||
forNamespace: XMPP_NS_STREAM];
|
|
||||||
|
if ((attribute = [element attributeForName: @"id"]))
|
||||||
|
[self setID: [attribute stringValue]];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue