diff --git a/include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp b/include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32f90d29ad9e2fcd412c35685e210879297a1a69 --- /dev/null +++ b/include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include +#include + +namespace Swift { + +XHTMLIMParser::XHTMLIMParser() : level_(TopLevel), bodyParser_(0) { +} + +void XHTMLIMParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + ++level_; + if (level_ == BodyLevel) { + if (element == "body") { + assert(!bodyParser_); + bodyParser_ = new SerializingParser(); + } + } + else if (level_ >= InsideBodyLevel && bodyParser_) { + bodyParser_->handleStartElement(element, ns, attributes); + } +} + +void XHTMLIMParser::handleEndElement(const std::string& element, const std::string& ns) { + if (level_ == BodyLevel) { + if (bodyParser_) { + if (element == "body") { + getPayloadInternal()->setBody(bodyParser_->getResult()); + } + delete bodyParser_; + bodyParser_ = 0; + } + } + else if (bodyParser_ && level_ >= InsideBodyLevel) { + bodyParser_->handleEndElement(element, ns); + } + --level_; +} + +void XHTMLIMParser::handleCharacterData(const std::string& data) { + if (bodyParser_) { + bodyParser_->handleCharacterData(data); + } + else { + currentText_ += data; + } +} + +boost::shared_ptr XHTMLIMParser::getLabelPayload() const { + return getPayloadInternal(); +} + +}