diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/RosterParser.cpp')
| -rw-r--r-- | Swiften/Parser/PayloadParsers/RosterParser.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/Swiften/Parser/PayloadParsers/RosterParser.cpp b/Swiften/Parser/PayloadParsers/RosterParser.cpp index b35c035..c3a35b6 100644 --- a/Swiften/Parser/PayloadParsers/RosterParser.cpp +++ b/Swiften/Parser/PayloadParsers/RosterParser.cpp | |||
| @@ -3,17 +3,18 @@ | |||
| 3 | * Licensed under the GNU General Public License v3. | 3 | * Licensed under the GNU General Public License v3. |
| 4 | * See Documentation/Licenses/GPLv3.txt for more information. | 4 | * See Documentation/Licenses/GPLv3.txt for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include "Swiften/Parser/PayloadParsers/RosterParser.h" | 7 | #include "Swiften/Parser/PayloadParsers/RosterParser.h" |
| 8 | #include "Swiften/Parser/SerializingParser.h" | ||
| 8 | 9 | ||
| 9 | namespace Swift { | 10 | namespace Swift { |
| 10 | 11 | ||
| 11 | RosterParser::RosterParser() : level_(TopLevel) { | 12 | RosterParser::RosterParser() : level_(TopLevel), unknownContentParser_(0) { |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | void RosterParser::handleStartElement(const String& element, const String&, const AttributeMap& attributes) { | 15 | void RosterParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) { |
| 15 | if (level_ == PayloadLevel) { | 16 | if (level_ == PayloadLevel) { |
| 16 | if (element == "item") { | 17 | if (element == "item") { |
| 17 | inItem_ = true; | 18 | inItem_ = true; |
| 18 | currentItem_ = RosterItemPayload(); | 19 | currentItem_ = RosterItemPayload(); |
| 19 | 20 | ||
| @@ -44,29 +45,50 @@ void RosterParser::handleStartElement(const String& element, const String&, cons | |||
| 44 | } | 45 | } |
| 45 | else if (level_ == ItemLevel) { | 46 | else if (level_ == ItemLevel) { |
| 46 | if (element == "group") { | 47 | if (element == "group") { |
| 47 | currentText_ = ""; | 48 | currentText_ = ""; |
| 48 | } | 49 | } |
| 50 | else { | ||
| 51 | assert(!unknownContentParser_); | ||
| 52 | unknownContentParser_ = new SerializingParser(); | ||
| 53 | unknownContentParser_->handleStartElement(element, ns, attributes); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | else if (unknownContentParser_) { | ||
| 57 | unknownContentParser_->handleStartElement(element, ns, attributes); | ||
| 49 | } | 58 | } |
| 50 | ++level_; | 59 | ++level_; |
| 51 | } | 60 | } |
| 52 | 61 | ||
| 53 | void RosterParser::handleEndElement(const String& element, const String&) { | 62 | void RosterParser::handleEndElement(const String& element, const String& ns) { |
| 54 | --level_; | 63 | --level_; |
| 55 | if (level_ == PayloadLevel) { | 64 | if (level_ == PayloadLevel) { |
| 56 | if (inItem_) { | 65 | if (inItem_) { |
| 57 | getPayloadInternal()->addItem(currentItem_); | 66 | getPayloadInternal()->addItem(currentItem_); |
| 58 | inItem_ = false; | 67 | inItem_ = false; |
| 59 | } | 68 | } |
| 60 | } | 69 | } |
| 61 | else if (level_ == ItemLevel) { | 70 | else if (level_ == ItemLevel) { |
| 62 | if (element == "group") { | 71 | if (unknownContentParser_) { |
| 72 | unknownContentParser_->handleEndElement(element, ns); | ||
| 73 | currentItem_.addUnknownContent(unknownContentParser_->getResult()); | ||
| 74 | unknownContentParser_ = NULL; | ||
| 75 | } | ||
| 76 | else if (element == "group") { | ||
| 63 | currentItem_.addGroup(currentText_); | 77 | currentItem_.addGroup(currentText_); |
| 64 | } | 78 | } |
| 65 | } | 79 | } |
| 80 | else if (unknownContentParser_) { | ||
| 81 | unknownContentParser_->handleEndElement(element, ns); | ||
| 82 | } | ||
| 66 | } | 83 | } |
| 67 | 84 | ||
| 68 | void RosterParser::handleCharacterData(const String& data) { | 85 | void RosterParser::handleCharacterData(const String& data) { |
| 69 | currentText_ += data; | 86 | if (unknownContentParser_) { |
| 87 | unknownContentParser_->handleCharacterData(data); | ||
| 88 | } | ||
| 89 | else { | ||
| 90 | currentText_ += data; | ||
| 91 | } | ||
| 70 | } | 92 | } |
| 71 | 93 | ||
| 72 | } | 94 | } |
Swift