diff options
author | Tim Robbings <tim.robbings@isode.com> | 2015-01-26 17:33:20 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-02-17 12:17:35 (GMT) |
commit | 55461d1b5f97591b4ab9510896ca1bc5b5e2a71f (patch) | |
tree | 17c79419d06c6740bb6ff04f6e17a13e7c4533a5 /Swiften/Elements | |
parent | 265b779d6766130afa8f2f166733dc172ba22dca (diff) | |
download | swift-55461d1b5f97591b4ab9510896ca1bc5b5e2a71f.zip swift-55461d1b5f97591b4ab9510896ca1bc5b5e2a71f.tar.bz2 |
Swiften XEP-0141 support
Classes to support XEP-0141 data forms layout. This includes <page/>,
<section/>, <reportedref/> and <text/> elements. The form
parser and serializer classes have also been updated to handle these new
elements, with added CPPUnit tests.
Test-information:
Tested using updated CPPUnit tests to check the parsing and serializing of
new elements. All tests complete successfully.
Change-Id: Ibeab22d2834512d06c7f656acd1ef24eea39d650
Diffstat (limited to 'Swiften/Elements')
-rw-r--r-- | Swiften/Elements/Form.h | 89 | ||||
-rw-r--r-- | Swiften/Elements/FormPage.cpp | 68 | ||||
-rw-r--r-- | Swiften/Elements/FormPage.h | 47 | ||||
-rw-r--r-- | Swiften/Elements/FormReportedRef.h | 17 | ||||
-rw-r--r-- | Swiften/Elements/FormSection.cpp | 64 | ||||
-rw-r--r-- | Swiften/Elements/FormSection.h | 44 | ||||
-rw-r--r-- | Swiften/Elements/FormText.cpp | 24 | ||||
-rw-r--r-- | Swiften/Elements/FormText.h | 26 |
8 files changed, 361 insertions, 18 deletions
diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index 42fe7ed..c1d7a5b 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,6 +11,8 @@ #include <Swiften/Base/API.h> #include <Swiften/Elements/Payload.h> +#include <Swiften/Elements/FormPage.h> +#include <Swiften/Elements/FormSection.h> #include <Swiften/Elements/FormField.h> #include <Swiften/JID/JID.h> @@ -30,39 +32,90 @@ namespace Swift { public: Form(Type type = FormType) : type_(type) {} - /** Add a field to the form. - * @param field New field - must not be null. - */ - void addField(boost::shared_ptr<FormField> field) {assert(field); fields_.push_back(field); } - const std::vector<boost::shared_ptr<FormField> >& getFields() const { return fields_; } - void clearFields() { fields_.clear(); } - void setTitle(const std::string& title) { title_ = title; } - const std::string& getTitle() const { return title_; } + void addPage(boost::shared_ptr<FormPage> page) { + assert(page); + pages_.push_back(page); + } - void setInstructions(const std::string& instructions) { instructions_ = instructions; } - const std::string& getInstructions() const { return instructions_; } + const std::vector<boost::shared_ptr<FormPage> >& getPages() const { + return pages_; + } - Type getType() const { return type_; } - void setType(Type type) { type_ = type; } + void addField(boost::shared_ptr<FormField> field) { + assert(field); + fields_.push_back(field); + } - std::string getFormType() const; + const std::vector<boost::shared_ptr<FormField> >& getFields() const { + return fields_; + } - FormField::ref getField(const std::string& name) const; + void clearFields() { + fields_.clear(); + } - void addReportedField(FormField::ref field); - const std::vector<FormField::ref>& getReportedFields() const; - void clearReportedFields() { reportedFields_.clear(); } + void addTextElement(boost::shared_ptr<FormText> text) { + assert(text); + textElements_.push_back(text); + } + + const std::vector<boost::shared_ptr<FormText> >& getTextElements() const { + return textElements_; + } + + void addReportedRef(boost::shared_ptr<FormReportedRef> reportedRef) { + assert(reportedRef); + reportedRefs_.push_back(reportedRef); + } + + const std::vector<boost::shared_ptr<FormReportedRef> >& getReportedRefs() const { + return reportedRefs_; + } + + void setTitle(const std::string& title) { + title_ = title; + } + + const std::string& getTitle() const { + return title_; + } + void setInstructions(const std::string& instructions) { + instructions_ = instructions; + } + + const std::string& getInstructions() const { + return instructions_; + } + + Type getType() const { + return type_; + } + + void setType(Type type) { + type_ = type; + } + + std::string getFormType() const; + FormField::ref getField(const std::string& name) const; void addItem(const FormItem& item); const std::vector<FormItem>& getItems() const; void clearItems() { items_.clear(); } void clearEmptyTextFields(); + void addReportedField(FormField::ref field); + const std::vector<FormField::ref> & getReportedFields() const; + void clearReportedFields() { reportedFields_.clear(); } + private: + std::vector<boost::shared_ptr<FormReportedRef> >reportedRefs_; + std::vector<boost::shared_ptr<FormText> > textElements_; + std::vector<boost::shared_ptr<FormPage> > pages_; std::vector<boost::shared_ptr<FormField> > fields_; std::vector<boost::shared_ptr<FormField> > reportedFields_; std::vector<FormItem> items_; + boost::shared_ptr<FormReportedRef> reportedRef_; std::string title_; std::string instructions_; Type type_; diff --git a/Swiften/Elements/FormPage.cpp b/Swiften/Elements/FormPage.cpp new file mode 100644 index 0000000..37ff32c --- /dev/null +++ b/Swiften/Elements/FormPage.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#include <Swiften/Elements/FormPage.h> + +namespace Swift { + +FormPage::FormPage() : xmlns_("http://jabber.org/protocol/xdata-layout") { +} + +FormPage::~FormPage() { +} + +void FormPage::setLabel(const std::string& label) { + label_ = label; +} + +const std::string& FormPage::getLabel() const { + return label_; +} + +const std::string& FormPage::getXMLNS() const { + return xmlns_; +} + +void FormPage::addChildSection(boost::shared_ptr<FormSection>& section) { + childSections_.push_back(section); +} + +const std::vector<boost::shared_ptr<FormSection> >& FormPage::getChildSections() const { + return childSections_; +} + +void FormPage::addTextElement(boost::shared_ptr<FormText>& textElement) { + textElements_.push_back(textElement); +} + +const std::vector<boost::shared_ptr<FormText> >& FormPage::getTextElements() const { + return textElements_; +} + +void FormPage::addReportedRef(boost::shared_ptr<FormReportedRef>& reportedRef) { + reportedRefs_.push_back(reportedRef); +} + +const std::vector<boost::shared_ptr<FormReportedRef> >& FormPage::getReportedRefs() const { + return reportedRefs_; +} + +void FormPage::addField(boost::shared_ptr<FormField>& field) { + fields_.push_back(field); +} + +const std::vector<boost::shared_ptr<FormField> >& FormPage::getFields() const { + return fields_; +} + +void FormPage::addFieldRef(std::string ref) { + fieldRefs_.push_back(ref); +} + +const std::vector<std::string> FormPage::getFieldRefs() const { + return fieldRefs_; +} + +}
\ No newline at end of file diff --git a/Swiften/Elements/FormPage.h b/Swiften/Elements/FormPage.h new file mode 100644 index 0000000..e5ecda2 --- /dev/null +++ b/Swiften/Elements/FormPage.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#pragma once + +#include <string> +#include <vector> +#include <boost/shared_ptr.hpp> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/Elements/FormReportedRef.h> +#include <Swiften/Elements/FormSection.h> +#include <Swiften/Elements/FormText.h> + +namespace Swift { + + class SWIFTEN_API FormPage { + public: + typedef boost::shared_ptr<FormPage> page; + FormPage (); + ~FormPage(); + void setLabel(const std::string& label); + const std::string& getLabel() const; + const std::string& getXMLNS() const; + void addChildSection(boost::shared_ptr<FormSection>& section); + const std::vector<boost::shared_ptr<FormSection> >& getChildSections() const; + void addTextElement(boost::shared_ptr<FormText>& textElement); + const std::vector<boost::shared_ptr<FormText> >& getTextElements() const; + void addReportedRef(boost::shared_ptr<FormReportedRef>& reportedRef); + const std::vector<boost::shared_ptr<FormReportedRef> >& getReportedRefs() const; + void addField(boost::shared_ptr<FormField>& field); + const std::vector<boost::shared_ptr<FormField> >& getFields() const; + void addFieldRef(std::string ref); + const std::vector<std::string> getFieldRefs() const; + + private: + std::string xmlns_; + std::string label_; + std::vector<boost::shared_ptr<FormText> > textElements_; + std::vector<boost::shared_ptr<FormSection> > childSections_; + std::vector<boost::shared_ptr<FormReportedRef> > reportedRefs_; + std::vector<boost::shared_ptr<FormField> > fields_; + std::vector<std::string> fieldRefs_; + }; +} diff --git a/Swiften/Elements/FormReportedRef.h b/Swiften/Elements/FormReportedRef.h new file mode 100644 index 0000000..b985167 --- /dev/null +++ b/Swiften/Elements/FormReportedRef.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#pragma once + +#include <Swiften/Base/API.h> + +namespace Swift { + + class SWIFTEN_API FormReportedRef { + + public: + typedef boost::shared_ptr<FormReportedRef> ref; + }; +} diff --git a/Swiften/Elements/FormSection.cpp b/Swiften/Elements/FormSection.cpp new file mode 100644 index 0000000..1784714 --- /dev/null +++ b/Swiften/Elements/FormSection.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#include <Swiften/Elements/FormSection.h> + +namespace Swift { + +FormSection::FormSection() { +} + +FormSection::~FormSection() { +} + +void FormSection::setLabel(const std::string& label) { + label_ = label; +} + +const std::string& FormSection::getLabel() const { + return label_; +} + +void FormSection::addTextElement(boost::shared_ptr<FormText>& textElement) { + textElements_.push_back(textElement); +} + +const std::vector<boost::shared_ptr<FormText> >& FormSection::getTextElements() const { + return textElements_; +} + +void FormSection::addReportedRef(boost::shared_ptr<FormReportedRef>& reportedRef) { + reportedRefs_.push_back(reportedRef); +} + +const std::vector<boost::shared_ptr<FormReportedRef> >& FormSection::getReportedRefs() const { + return reportedRefs_; +} + +void FormSection::addChildSection(boost::shared_ptr<FormSection>& childSection) { + childSections_.push_back(childSection); +} + +const std::vector<boost::shared_ptr<FormSection> >& FormSection::getChildSections() const { + return childSections_; +} + +void FormSection::addField(boost::shared_ptr<FormField>& field) { + fields_.push_back(field); +} + +const std::vector<boost::shared_ptr<FormField> >& FormSection::getFields() const { + return fields_; +} + +void FormSection::addFieldRef(std::string ref) { + fieldRefs_.push_back(ref); +} + +const std::vector<std::string> FormSection::getFieldRefs() const { + return fieldRefs_; +} + +}
\ No newline at end of file diff --git a/Swiften/Elements/FormSection.h b/Swiften/Elements/FormSection.h new file mode 100644 index 0000000..f799062 --- /dev/null +++ b/Swiften/Elements/FormSection.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#pragma once + +#include <string> +#include <vector> +#include <boost/shared_ptr.hpp> +#include <Swiften/Base/API.h> +#include <Swiften/Elements/FormField.h> +#include <Swiften/Elements/FormReportedRef.h> +#include <Swiften/Elements/FormText.h> + +namespace Swift { + + class SWIFTEN_API FormSection { + public: + typedef boost::shared_ptr<FormSection> section; + FormSection(); + ~FormSection(); + void setLabel(const std::string& label); + const std::string& getLabel() const; + void addTextElement(boost::shared_ptr<FormText>& textElement); + const std::vector<boost::shared_ptr<FormText> >& getTextElements() const; + void addReportedRef(boost::shared_ptr<FormReportedRef>& reportedRef); + const std::vector<boost::shared_ptr<FormReportedRef> >& getReportedRefs() const; + void addChildSection(boost::shared_ptr<FormSection>& childSection); + const std::vector<boost::shared_ptr<FormSection> >& getChildSections() const; + void addField(boost::shared_ptr<FormField>& field); + const std::vector<boost::shared_ptr<FormField> >& getFields() const; + void addFieldRef(std::string ref); + const std::vector<std::string> getFieldRefs() const; + + private: + std::string label_; + std::vector<boost::shared_ptr<FormText> > textElements_; + std::vector<boost::shared_ptr<FormReportedRef> > reportedRefs_; + std::vector<boost::shared_ptr<FormSection> > childSections_; + std::vector<boost::shared_ptr<FormField> > fields_; + std::vector<std::string> fieldRefs_; + }; +} diff --git a/Swiften/Elements/FormText.cpp b/Swiften/Elements/FormText.cpp new file mode 100644 index 0000000..cbbfbe4 --- /dev/null +++ b/Swiften/Elements/FormText.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#include <Swiften/Elements/FormText.h> + +namespace Swift { + +FormText::FormText() { +} + +FormText::~FormText() { +} + +void FormText::setTextString(const std::string& text) { + text_ = text; +} + +const std::string& FormText::getTextString() const { + return text_; +} + +} diff --git a/Swiften/Elements/FormText.h b/Swiften/Elements/FormText.h new file mode 100644 index 0000000..501af11 --- /dev/null +++ b/Swiften/Elements/FormText.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +#pragma once + +#include <string> +#include <boost/shared_ptr.hpp> +#include <Swiften/Base/API.h> + +namespace Swift { + + class SWIFTEN_API FormText{ + + public: + typedef boost::shared_ptr<FormText> text; + FormText(); + virtual ~FormText(); + void setTextString(const std::string& text); + const std::string& getTextString() const; + + private: + std::string text_; + }; +} |