summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/VCardParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/VCardParser.cpp87
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
@@ -7,27 +7,39 @@
#include "Swiften/Parser/PayloadParsers/VCardParser.h"
#include "Swiften/Base/foreach.h"
#include "Swiften/StringCodecs/Base64.h"
+#include "Swiften/Parser/SerializingParser.h"
namespace Swift {
-VCardParser::VCardParser() {
+VCardParser::VCardParser() : unknownContentParser_(NULL) {
}
-void VCardParser::handleStartElement(const String& element, const String&, const AttributeMap&) {
+void VCardParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
elementStack_.push_back(element);
+ String elementHierarchy = getElementHierarchy();
+ if (elementHierarchy == "/vCard/EMAIL") {
+ currentEMailAddress_ = VCard::EMailAddress();
+ }
+ if (elementStack_.size() == 2) {
+ assert(!unknownContentParser_);
+ unknownContentParser_ = new SerializingParser();
+ unknownContentParser_->handleStartElement(element, ns, attributes);
+ }
+ else if (unknownContentParser_) {
+ unknownContentParser_->handleStartElement(element, ns, attributes);
+ }
+
currentText_ = "";
}
-void VCardParser::handleEndElement(const String&, const String&) {
- String elementHierarchy = getElementHierarchy();
- if (elementHierarchy == "/vCard/PHOTO/TYPE") {
- getPayloadInternal()->setPhotoType(currentText_);
- }
- else if (elementHierarchy == "/vCard/PHOTO/BINVAL") {
- getPayloadInternal()->setPhoto(Base64::decode(currentText_));
+void VCardParser::handleEndElement(const String& element, const String& ns) {
+ if (unknownContentParser_) {
+ unknownContentParser_->handleEndElement(element, ns);
}
- else if (elementHierarchy == "/vCard/NICKNAME") {
- getPayloadInternal()->setNickname(currentText_);
+
+ String elementHierarchy = getElementHierarchy();
+ if (elementHierarchy == "/vCard/VERSION") {
+ getPayloadInternal()->setVersion(currentText_);
}
else if (elementHierarchy == "/vCard/FN") {
getPayloadInternal()->setFullName(currentText_);
@@ -38,13 +50,64 @@ void VCardParser::handleEndElement(const String&, const String&) {
else if (elementHierarchy == "/vCard/N/GIVEN") {
getPayloadInternal()->setGivenName(currentText_);
}
+ else if (elementHierarchy == "/vCard/N/MIDDLE") {
+ getPayloadInternal()->setMiddleName(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/N/PREFIX") {
+ getPayloadInternal()->setPrefix(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/N/SUFFIX") {
+ getPayloadInternal()->setSuffix(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/N") {
+ }
+ else if (elementHierarchy == "/vCard/NICKNAME") {
+ getPayloadInternal()->setNickname(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/PHOTO/TYPE") {
+ getPayloadInternal()->setPhotoType(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/PHOTO/BINVAL") {
+ getPayloadInternal()->setPhoto(Base64::decode(currentText_));
+ }
+ else if (elementHierarchy == "/vCard/PHOTO") {
+ }
else if (elementHierarchy == "/vCard/EMAIL/USERID") {
- getPayloadInternal()->setEMail(currentText_);
+ currentEMailAddress_.address = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/HOME") {
+ currentEMailAddress_.isHome = true;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/WORK") {
+ currentEMailAddress_.isWork = true;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/INTERNET") {
+ currentEMailAddress_.isInternet = true;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/X400") {
+ currentEMailAddress_.isX400 = true;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/PREF") {
+ currentEMailAddress_.isPreferred = true;
+ }
+ else if (elementHierarchy == "/vCard/EMAIL") {
+ getPayloadInternal()->addEMailAddress(currentEMailAddress_);
+ }
+ else if (elementStack_.size() == 2 && unknownContentParser_) {
+ getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult());
+ }
+
+ if (elementStack_.size() == 2 && unknownContentParser_) {
+ delete unknownContentParser_;
+ unknownContentParser_ = NULL;
}
elementStack_.pop_back();
}
void VCardParser::handleCharacterData(const String& text) {
+ if (unknownContentParser_) {
+ unknownContentParser_->handleCharacterData(text);
+ }
currentText_ += text;
}