-
Notifications
You must be signed in to change notification settings - Fork 7
/
XMPPSearchResult.m
80 lines (72 loc) · 2.7 KB
/
XMPPSearchResult.m
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
//
// XMPPSearchResault.m
// SOP2p
//
// Created by zrz on 12-8-18.
// Copyright (c) 2012年 Sctab. All rights reserved.
//
#import "XMPPSearchResult.h"
@implementation XMPPSearchResult
@synthesize singleFields = _singleFields, tableFields = _tableFields;
@synthesize singleInstructions = _singleInstructions;
@synthesize tableInstructions = _tableInstructions;
- (id)initWithElement:(NSXMLElement *)element
{
self = [super init];
if (self) {
NSXMLElement *query = [[element elementsForName:@"query"] lastObject];
NSString *type = [[element attributeForName:@"type"] stringValue];
_singleInstructions = [[[query elementsForName:@"instructions"] lastObject] stringValue];
if ([type isEqualToString:@"result"]) {
NSArray *queryChildren = [query children];
NSMutableArray *nFields = [NSMutableArray array];
NSMutableArray *tFields = [NSMutableArray array];
for (NSXMLElement *el in queryChildren) {
if (![el.name isEqualToString:@"instructions"]) {
if ([el.name isEqualToString:@"x"]) {
//table fields
NSArray *namespaces = [el namespaces];
for (NSXMLNode *node in namespaces) {
if ([node.stringValue isEqualToString:@"jabber:x:data"]) {
//this is right
NSArray *tableChildren = [el elementsForName:@"field"];
for (NSXMLElement *tel in tableChildren) {
[tFields addObject:[XMPPSearchNode nodeWithElement:tel]];
}
break;
}
}
}else {
[nFields addObject:[XMPPSearchNode nodeWithElement:el]];
}
}else {
_tableInstructions = [el stringValue];
}
}
_singleFields = [nFields copy];
_tableFields = [tFields copy];
}
}
return self;
}
+ (id)resaultWithElement:(DDXMLElement *)element
{
return [[self alloc] initWithElement:element];
}
- (NSArray *)copyForSingleFields
{
NSMutableArray *fields = [NSMutableArray arrayWithCapacity:_singleFields.count];
for (XMPPSearchNode *node in _singleFields) {
[fields addObject:[node copy]];
}
return [fields copy];
}
- (NSArray *)copyForTableFields
{
NSMutableArray *fields = [NSMutableArray arrayWithCapacity:_tableFields.count];
for (XMPPSearchNode *node in _tableFields) {
[fields addObject:[node copy]];
}
return [fields copy];
}
@end