diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-20 01:02:12 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-27 07:12:55 (GMT) |
commit | a673d269487fd86efe7f9c5f9b4cd1c00cab556d (patch) | |
tree | 10145697d3153a8a170361c5355ad9bccee21776 /src/com/isode/stroke/elements | |
parent | 27212e007077418d18014286a46723fa26693864 (diff) | |
download | stroke-a673d269487fd86efe7f9c5f9b4cd1c00cab556d.zip stroke-a673d269487fd86efe7f9c5f9b4cd1c00cab556d.tar.bz2 |
Adds Form Elements and Version Element.
Adds FormPage, FormReportedRef, FormSection, FormText and Version Elements.
Updates Form Elements, its Parser And Serializer.
Updates SearchPayload Element, its Parser And Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Adds Search Payload Parser and Serializer Test.
Updates tests for Form Parser and Serializer.
Updates InBandRegistrationPayloadSerializer Test and MAMQuerySerializerTest.
All tests passes.
Change-Id: I8c620a3db39fe433bc9a5478b98d5caeaf9ed40b
Diffstat (limited to 'src/com/isode/stroke/elements')
-rw-r--r-- | src/com/isode/stroke/elements/Form.java | 81 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/FormField.java | 3 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/FormPage.java | 134 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/FormReportedRef.java | 16 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/FormSection.java | 125 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/FormText.java | 41 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/SearchPayload.java | 18 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Version.java | 82 |
8 files changed, 493 insertions, 7 deletions
diff --git a/src/com/isode/stroke/elements/Form.java b/src/com/isode/stroke/elements/Form.java index 8068f28..a6ff0c2 100644 --- a/src/com/isode/stroke/elements/Form.java +++ b/src/com/isode/stroke/elements/Form.java @@ -108,6 +108,10 @@ public class Form extends Payload { } } + private List<FormReportedRef> reportedRefs_ = new ArrayList<FormReportedRef>(); + private List<FormText> textElements_ = new ArrayList<FormText>(); + private List<FormPage> pages_ = new ArrayList<FormPage>(); + private FormReportedRef reportedRef_; private List<FormField> fields_ = new ArrayList<FormField>(); private List<FormField> reportedFields_ = new ArrayList<FormField>(); private List<FormItem> items_ = new ArrayList<FormItem>(); @@ -132,6 +136,51 @@ public class Form extends Payload { } /** + * @param reportedRef, Not Null. + */ + public void addReportedRef(FormReportedRef reportedRef) { + assert(reportedRef != null); + reportedRefs_.add(reportedRef); + } + + /** + * @return reportedRef, Not Null. + */ + public List<FormReportedRef> getReportedRefs() { + return reportedRefs_; + } + + /** + * @param text, Not Null. + */ + public void addTextElement(FormText text) { + assert(text != null); + textElements_.add(text); + } + + /** + * @return text, Not Null. + */ + public List<FormText> getTextElements() { + return textElements_; + } + + /** + * @return page, Not Null. + */ + public void addPage(FormPage page) { + assert(page != null); + pages_.add(page); + } + + /** + * @return pages, Not Null. + */ + public List<FormPage> getPages() { + return pages_; + } + + /** * Add to the list of fields for the form. * * @param field Field to add, must not be null. The instance of the form @@ -153,7 +202,11 @@ public class Form extends Payload { public List<FormField> getFields() { return new ArrayList<FormField>(fields_); } - + + public void clearFields() { + fields_.clear(); + } + /** * Add a reported element to this Form. * @param reportedField should not be null @@ -183,7 +236,11 @@ public class Form extends Payload { } items_.add(item); } - + + public void clearItems() { + items_.clear(); + } + /** * Get the list of FormItem elements for the form. * @return itemsCopy ArrayList<List<FormItem>>, list of items for the Form, @@ -295,6 +352,26 @@ public class Form extends Payload { return null; } + public void clearEmptyTextFields() { + List<FormField> populatedFields = new ArrayList<FormField>(); + for (FormField field : fields_) { + if (field.getType() == FormField.Type.TEXT_SINGLE_TYPE) { + if (!field.getTextSingleValue().isEmpty()) { + populatedFields.add(field); + } + } + else if (field.getType() == FormField.Type.TEXT_MULTI_TYPE) { + if (!field.getTextMultiValue().isEmpty()) { + populatedFields.add(field); + } + } + else { + populatedFields.add(field); + } + } + fields_ = populatedFields; + } + @Override public String toString() { return Form.class.getSimpleName() + "\ntitle: " + title_ diff --git a/src/com/isode/stroke/elements/FormField.java b/src/com/isode/stroke/elements/FormField.java index 84b6af1..c38772f 100644 --- a/src/com/isode/stroke/elements/FormField.java +++ b/src/com/isode/stroke/elements/FormField.java @@ -88,9 +88,6 @@ public class FormField { public FormField(Type type) { type_ = type; required_ = false; - if (type == Type.BOOLEAN_TYPE) { - setBoolValue(false); - } } /** diff --git a/src/com/isode/stroke/elements/FormPage.java b/src/com/isode/stroke/elements/FormPage.java new file mode 100644 index 0000000..b23a6e2 --- /dev/null +++ b/src/com/isode/stroke/elements/FormPage.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.base.NotNull; +import com.isode.stroke.elements.FormField; +import com.isode.stroke.elements.FormReportedRef; +import com.isode.stroke.elements.FormText; +import com.isode.stroke.elements.FormSection; +import java.util.Vector; + +public class FormPage { + + private String label_ = ""; + private String xmlns_ = ""; + private Vector<FormText> textElements_ = new Vector<FormText>(); + private Vector<FormReportedRef> reportedRefs_ = new Vector<FormReportedRef>(); + private Vector<FormSection> childSections_ = new Vector<FormSection>(); + private Vector<FormField> fields_ = new Vector<FormField>(); + private Vector<String> fieldRefs_ = new Vector<String>(); + + /** + * Default Constructor. + */ + public FormPage() { + this.xmlns_ = "http://jabber.org/protocol/xdata-layout"; + } + + /** + * @param label, Not Null. + */ + public void setLabel(String label) { + NotNull.exceptIfNull(label, "label"); + label_ = label; + } + + /** + * @return label, Not Null. + */ + public String getLabel() { + return label_; + } + + /** + * @return xmlns, Not Null. + */ + public String getXMLNS() { + return xmlns_; + } + + /** + * @param textElement, Not Null. + */ + public void addTextElement(FormText textElement) { + NotNull.exceptIfNull(textElement, "textElement"); + textElements_.add(textElement); + } + + /** + * @return textElement, Not Null. + */ + public Vector<FormText> getTextElements() { + return textElements_; + } + + /** + * @param reportedRef, Not Null. + */ + public void addReportedRef(FormReportedRef reportedRef) { + NotNull.exceptIfNull(reportedRef, "reportedRef"); + reportedRefs_.add(reportedRef); + } + + /** + * @return reportedRef, Not Null. + */ + public Vector<FormReportedRef> getReportedRefs() { + return reportedRefs_; + } + + /** + * @param childSection, Not Null. + */ + public void addChildSection(FormSection childSection) { + NotNull.exceptIfNull(childSection, "childSection"); + childSections_.add(childSection); + } + + /** + * @return childSection, Not Null. + */ + public Vector<FormSection> getChildSections() { + return childSections_; + } + + /** + * @param field, Not Null. + */ + public void addField(FormField field) { + NotNull.exceptIfNull(field, "field"); + fields_.add(field); + } + + /** + * @return field, Not Null. + */ + public Vector<FormField> getFields() { + return fields_; + } + + /** + * @param ref, Not Null. + */ + public void addFieldRef(String ref) { + NotNull.exceptIfNull(ref, "ref"); + fieldRefs_.add(ref); + } + + /** + * @return ref, Not Null. + */ + public Vector<String> getFieldRefs() { + return fieldRefs_; + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/FormReportedRef.java b/src/com/isode/stroke/elements/FormReportedRef.java new file mode 100644 index 0000000..1785ce1 --- /dev/null +++ b/src/com/isode/stroke/elements/FormReportedRef.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +public class FormReportedRef { + +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/FormSection.java b/src/com/isode/stroke/elements/FormSection.java new file mode 100644 index 0000000..8cc42b3 --- /dev/null +++ b/src/com/isode/stroke/elements/FormSection.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.base.NotNull; +import com.isode.stroke.elements.FormField; +import com.isode.stroke.elements.FormReportedRef; +import com.isode.stroke.elements.FormText; +import java.util.Vector; + +public class FormSection { + + private String label_ = ""; + private Vector<FormText> textElements_ = new Vector<FormText>(); + private Vector<FormReportedRef> reportedRefs_ = new Vector<FormReportedRef>(); + private Vector<FormSection> childSections_ = new Vector<FormSection>(); + private Vector<FormField> fields_ = new Vector<FormField>(); + private Vector<String> fieldRefs_ = new Vector<String>(); + + /** + * Default Constructor. + */ + public FormSection() { + + } + + /** + * @param label, Not Null. + */ + public void setLabel(String label) { + NotNull.exceptIfNull(label, "label"); + label_ = label; + } + + /** + * @return label, Not Null. + */ + public String getLabel() { + return label_; + } + + /** + * @param textElement, Not Null. + */ + public void addTextElement(FormText textElement) { + NotNull.exceptIfNull(textElement, "textElement"); + textElements_.add(textElement); + } + + /** + * @return textElement, Not Null. + */ + public Vector<FormText> getTextElements() { + return textElements_; + } + + /** + * @param reportedRef, Not Null. + */ + public void addReportedRef(FormReportedRef reportedRef) { + NotNull.exceptIfNull(reportedRef, "reportedRef"); + reportedRefs_.add(reportedRef); + } + + /** + * @return reportedRef, Not Null. + */ + public Vector<FormReportedRef> getReportedRefs() { + return reportedRefs_; + } + + /** + * @param childSection, Not Null. + */ + public void addChildSection(FormSection childSection) { + NotNull.exceptIfNull(childSection, "childSection"); + childSections_.add(childSection); + } + + /** + * @return childSection, Not Null. + */ + public Vector<FormSection> getChildSections() { + return childSections_; + } + + /** + * @param field, Not Null. + */ + public void addField(FormField field) { + NotNull.exceptIfNull(field, "field"); + fields_.add(field); + } + + /** + * @return field, Not Null. + */ + public Vector<FormField> getFields() { + return fields_; + } + + /** + * @param ref, Not Null. + */ + public void addFieldRef(String ref) { + NotNull.exceptIfNull(ref, "ref"); + fieldRefs_.add(ref); + } + + /** + * @return ref, Not Null. + */ + public Vector<String> getFieldRefs() { + return fieldRefs_; + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/FormText.java b/src/com/isode/stroke/elements/FormText.java new file mode 100644 index 0000000..4a400b3 --- /dev/null +++ b/src/com/isode/stroke/elements/FormText.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.base.NotNull; + +public class FormText { + + private String text_ = ""; + + /** + * Default Constructor. + */ + public FormText() { + + } + + /** + * @param text, Not Null. + */ + public void setTextString(String text) { + NotNull.exceptIfNull(text, "text"); + text_ = text; + } + + /** + * @return text, Not Null. + */ + public String getTextString() { + return text_; + } +}
\ No newline at end of file diff --git a/src/com/isode/stroke/elements/SearchPayload.java b/src/com/isode/stroke/elements/SearchPayload.java index 1568961..8b85841 100644 --- a/src/com/isode/stroke/elements/SearchPayload.java +++ b/src/com/isode/stroke/elements/SearchPayload.java @@ -9,6 +9,7 @@ package com.isode.stroke.elements; import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.Form; import java.util.ArrayList; import java.util.List; @@ -26,8 +27,20 @@ public class SearchPayload extends Payload { public SearchPayload() { } - //Form::ref getForm() const { return form; } /* Not ported yet */ - //void setForm(Form::ref f) { form = f; } /* Not ported yet */ + /** + * @return Can be null + */ + public Form getForm() { + return form; + } + + /** + * @param v Null means no value. + */ + public void setForm(Form f) { + form = f; + } + /** * @return Can be null */ @@ -121,4 +134,5 @@ public class SearchPayload extends Payload { private String last; private String email; private ArrayList<Item> items = new ArrayList<Item>(); + private Form form; } diff --git a/src/com/isode/stroke/elements/Version.java b/src/com/isode/stroke/elements/Version.java new file mode 100644 index 0000000..02c6507 --- /dev/null +++ b/src/com/isode/stroke/elements/Version.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2010-2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; +import com.isode.stroke.base.NotNull; + +public class Version extends Payload { + + private String name_; + private String version_; + private String os_; + + /** + * Default Constructor. + */ + public Version() { + this("", "", ""); + } + + /** + * Parameterized Constructor. + * @param name, Not Null. + */ + public Version(String name) { + this(name, "", ""); + } + + /** + * Parameterized Constructor. + * @param name, Not Null. + * @param version, NotNull. + */ + public Version(String name, String version) { + this(name, version, ""); + } + + /** + * Parameterized Constructor. + * @param name, Not Null. + * @param version, NotNull. + * @param os , Not Null. + */ + public Version(String name, String version, String os) { + NotNull.exceptIfNull(name, "name"); + NotNull.exceptIfNull(version, "version"); + NotNull.exceptIfNull(os, "os"); + this.name_ = name; + this.version_ = version; + this.os_ = os; + } + + /** + * @return name, Not Null. + */ + public String getName() { + return name_; + } + + /** + * @return version, Not Null. + */ + public String getVersion() { + return version_; + } + + /** + * @return os, Not Null. + */ + public String getOS() { + return os_; + } +}
\ No newline at end of file |