summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/VCardParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/VCardParser.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp
new file mode 100644
index 0000000..87416ab
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp
@@ -0,0 +1,53 @@
+#include "Swiften/Parser/PayloadParsers/VCardParser.h"
+#include "Swiften/Base/foreach.h"
+#include "Swiften/StringCodecs/Base64.h"
+
+namespace Swift {
+
+VCardParser::VCardParser() {
+}
+
+void VCardParser::handleStartElement(const String& element, const String&, const AttributeMap&) {
+ elementStack_.push_back(element);
+ 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_));
+ }
+ else if (elementHierarchy == "/vCard/NICKNAME") {
+ getPayloadInternal()->setNickname(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/FN") {
+ getPayloadInternal()->setFullName(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/N/FAMILY") {
+ getPayloadInternal()->setFamilyName(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/N/GIVEN") {
+ getPayloadInternal()->setGivenName(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/EMAIL/USERID") {
+ getPayloadInternal()->setEMail(currentText_);
+ }
+ elementStack_.pop_back();
+}
+
+void VCardParser::handleCharacterData(const String& text) {
+ currentText_ += text;
+}
+
+String VCardParser::getElementHierarchy() const {
+ String result;
+ foreach(const String& element, elementStack_) {
+ result += "/" + element;
+ }
+ return result;
+}
+
+}