diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/VCardParser.cpp')
| -rw-r--r-- | Swiften/Parser/PayloadParsers/VCardParser.cpp | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index 338efc6..2f1f8dc 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp | |||
| @@ -5,48 +5,111 @@ | |||
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include "Swiften/Parser/PayloadParsers/VCardParser.h" | 7 | #include "Swiften/Parser/PayloadParsers/VCardParser.h" |
| 8 | #include "Swiften/Base/foreach.h" | 8 | #include "Swiften/Base/foreach.h" |
| 9 | #include "Swiften/StringCodecs/Base64.h" | 9 | #include "Swiften/StringCodecs/Base64.h" |
| 10 | #include "Swiften/Parser/SerializingParser.h" | ||
| 10 | 11 | ||
| 11 | namespace Swift { | 12 | namespace Swift { |
| 12 | 13 | ||
| 13 | VCardParser::VCardParser() { | 14 | VCardParser::VCardParser() : unknownContentParser_(NULL) { |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | void VCardParser::handleStartElement(const String& element, const String&, const AttributeMap&) { | 17 | void VCardParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) { |
| 17 | elementStack_.push_back(element); | 18 | elementStack_.push_back(element); |
| 19 | String elementHierarchy = getElementHierarchy(); | ||
| 20 | if (elementHierarchy == "/vCard/EMAIL") { | ||
| 21 | currentEMailAddress_ = VCard::EMailAddress(); | ||
| 22 | } | ||
| 23 | if (elementStack_.size() == 2) { | ||
| 24 | assert(!unknownContentParser_); | ||
| 25 | unknownContentParser_ = new SerializingParser(); | ||
| 26 | unknownContentParser_->handleStartElement(element, ns, attributes); | ||
| 27 | } | ||
| 28 | else if (unknownContentParser_) { | ||
| 29 | unknownContentParser_->handleStartElement(element, ns, attributes); | ||
| 30 | } | ||
| 31 | |||
| 18 | currentText_ = ""; | 32 | currentText_ = ""; |
| 19 | } | 33 | } |
| 20 | 34 | ||
| 21 | void VCardParser::handleEndElement(const String&, const String&) { | 35 | void VCardParser::handleEndElement(const String& element, const String& ns) { |
| 22 | String elementHierarchy = getElementHierarchy(); | 36 | if (unknownContentParser_) { |
| 23 | if (elementHierarchy == "/vCard/PHOTO/TYPE") { | 37 | unknownContentParser_->handleEndElement(element, ns); |
| 24 | getPayloadInternal()->setPhotoType(currentText_); | ||
| 25 | } | ||
| 26 | else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { | ||
| 27 | getPayloadInternal()->setPhoto(Base64::decode(currentText_)); | ||
| 28 | } | 38 | } |
| 29 | else if (elementHierarchy == "/vCard/NICKNAME") { | 39 | |
| 30 | getPayloadInternal()->setNickname(currentText_); | 40 | String elementHierarchy = getElementHierarchy(); |
| 41 | if (elementHierarchy == "/vCard/VERSION") { | ||
| 42 | getPayloadInternal()->setVersion(currentText_); | ||
| 31 | } | 43 | } |
| 32 | else if (elementHierarchy == "/vCard/FN") { | 44 | else if (elementHierarchy == "/vCard/FN") { |
| 33 | getPayloadInternal()->setFullName(currentText_); | 45 | getPayloadInternal()->setFullName(currentText_); |
| 34 | } | 46 | } |
| 35 | else if (elementHierarchy == "/vCard/N/FAMILY") { | 47 | else if (elementHierarchy == "/vCard/N/FAMILY") { |
| 36 | getPayloadInternal()->setFamilyName(currentText_); | 48 | getPayloadInternal()->setFamilyName(currentText_); |
| 37 | } | 49 | } |
| 38 | else if (elementHierarchy == "/vCard/N/GIVEN") { | 50 | else if (elementHierarchy == "/vCard/N/GIVEN") { |
| 39 | getPayloadInternal()->setGivenName(currentText_); | 51 | getPayloadInternal()->setGivenName(currentText_); |
| 40 | } | 52 | } |
| 53 | else if (elementHierarchy == "/vCard/N/MIDDLE") { | ||
| 54 | getPayloadInternal()->setMiddleName(currentText_); | ||
| 55 | } | ||
| 56 | else if (elementHierarchy == "/vCard/N/PREFIX") { | ||
| 57 | getPayloadInternal()->setPrefix(currentText_); | ||
| 58 | } | ||
| 59 | else if (elementHierarchy == "/vCard/N/SUFFIX") { | ||
| 60 | getPayloadInternal()->setSuffix(currentText_); | ||
| 61 | } | ||
| 62 | else if (elementHierarchy == "/vCard/N") { | ||
| 63 | } | ||
| 64 | else if (elementHierarchy == "/vCard/NICKNAME") { | ||
| 65 | getPayloadInternal()->setNickname(currentText_); | ||
| 66 | } | ||
| 67 | else if (elementHierarchy == "/vCard/PHOTO/TYPE") { | ||
| 68 | getPayloadInternal()->setPhotoType(currentText_); | ||
| 69 | } | ||
| 70 | else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { | ||
| 71 | getPayloadInternal()->setPhoto(Base64::decode(currentText_)); | ||
| 72 | } | ||
| 73 | else if (elementHierarchy == "/vCard/PHOTO") { | ||
| 74 | } | ||
| 41 | else if (elementHierarchy == "/vCard/EMAIL/USERID") { | 75 | else if (elementHierarchy == "/vCard/EMAIL/USERID") { |
| 42 | getPayloadInternal()->setEMail(currentText_); | 76 | currentEMailAddress_.address = currentText_; |
| 77 | } | ||
| 78 | else if (elementHierarchy == "/vCard/EMAIL/HOME") { | ||
| 79 | currentEMailAddress_.isHome = true; | ||
| 80 | } | ||
| 81 | else if (elementHierarchy == "/vCard/EMAIL/WORK") { | ||
| 82 | currentEMailAddress_.isWork = true; | ||
| 83 | } | ||
| 84 | else if (elementHierarchy == "/vCard/EMAIL/INTERNET") { | ||
| 85 | currentEMailAddress_.isInternet = true; | ||
| 86 | } | ||
| 87 | else if (elementHierarchy == "/vCard/EMAIL/X400") { | ||
| 88 | currentEMailAddress_.isX400 = true; | ||
| 89 | } | ||
| 90 | else if (elementHierarchy == "/vCard/EMAIL/PREF") { | ||
| 91 | currentEMailAddress_.isPreferred = true; | ||
| 92 | } | ||
| 93 | else if (elementHierarchy == "/vCard/EMAIL") { | ||
| 94 | getPayloadInternal()->addEMailAddress(currentEMailAddress_); | ||
| 95 | } | ||
| 96 | else if (elementStack_.size() == 2 && unknownContentParser_) { | ||
| 97 | getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult()); | ||
| 98 | } | ||
| 99 | |||
| 100 | if (elementStack_.size() == 2 && unknownContentParser_) { | ||
| 101 | delete unknownContentParser_; | ||
| 102 | unknownContentParser_ = NULL; | ||
| 43 | } | 103 | } |
| 44 | elementStack_.pop_back(); | 104 | elementStack_.pop_back(); |
| 45 | } | 105 | } |
| 46 | 106 | ||
| 47 | void VCardParser::handleCharacterData(const String& text) { | 107 | void VCardParser::handleCharacterData(const String& text) { |
| 108 | if (unknownContentParser_) { | ||
| 109 | unknownContentParser_->handleCharacterData(text); | ||
| 110 | } | ||
| 48 | currentText_ += text; | 111 | currentText_ += text; |
| 49 | } | 112 | } |
| 50 | 113 | ||
| 51 | String VCardParser::getElementHierarchy() const { | 114 | String VCardParser::getElementHierarchy() const { |
| 52 | String result; | 115 | String result; |
Swift