1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-30 07:52:06 +01:00

Modified to use new FormField constructor

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2280 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-04-05 16:28:18 +00:00 committed by gdombiak
parent 3223d0f290
commit 3600aa17d4

View file

@ -74,6 +74,10 @@ import org.jivesoftware.smackx.packet.DataForm;
*/ */
public class Form { public class Form {
public static final String TYPE_FORM = "form";
public static final String TYPE_SUBMIT = "submit";
public static final String TYPE_RESULT = "result";
private DataForm dataForm; private DataForm dataForm;
/** /**
@ -127,6 +131,7 @@ public class Form {
* Adds a new field to complete as part of the form. * Adds a new field to complete as part of the form.
* *
* @param field the field to complete. * @param field the field to complete.
* @throws IllegalStateException if the form is not of type "form".
*/ */
public void addField(FormField field) { public void addField(FormField field) {
if (!isFormType()) { if (!isFormType()) {
@ -141,13 +146,13 @@ public class Form {
* *
* @param variable the variable that was completed. * @param variable the variable that was completed.
* @param value the value that was answered. * @param value the value that was answered.
* @throws IllegalStateException if the form is not of type "submit".
*/ */
public void addAnswer(String variable, String value) { public void addAnswer(String variable, String value) {
if (!isSubmitType()) { if (!isSubmitType()) {
throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\""); throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\"");
} }
FormField field = new FormField(); FormField field = new FormField(variable);
field.setVariable(variable);
field.addValue(value); field.addValue(value);
dataForm.addField(field); dataForm.addField(field);
} }
@ -158,13 +163,13 @@ public class Form {
* *
* @param variable the variable that was completed. * @param variable the variable that was completed.
* @param values the values that were answered. * @param values the values that were answered.
* @throws IllegalStateException if the form is not of type "submit".
*/ */
public void addAnswer(String variable, List values) { public void addAnswer(String variable, List values) {
if (!isSubmitType()) { if (!isSubmitType()) {
throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\""); throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\"");
} }
FormField field = new FormField(); FormField field = new FormField(variable);
field.setVariable(variable);
field.addValues(values); field.addValues(values);
dataForm.addField(field); dataForm.addField(field);
} }
@ -255,7 +260,7 @@ public class Form {
* @return if the form is a form to fill out. * @return if the form is a form to fill out.
*/ */
private boolean isFormType() { private boolean isFormType() {
return DataForm.TYPE_FORM.equals(dataForm.getType()); return TYPE_FORM.equals(dataForm.getType());
} }
/** /**
@ -264,7 +269,7 @@ public class Form {
* @return if the form is a form to submit. * @return if the form is a form to submit.
*/ */
private boolean isSubmitType() { private boolean isSubmitType() {
return DataForm.TYPE_SUBMIT.equals(dataForm.getType()); return TYPE_SUBMIT.equals(dataForm.getType());
} }
/** /**
@ -278,7 +283,7 @@ public class Form {
throw new IllegalStateException("Only forms of type \"form\" could be answered"); throw new IllegalStateException("Only forms of type \"form\" could be answered");
} }
// Create a new Form // Create a new Form
Form form = new Form(DataForm.TYPE_SUBMIT); Form form = new Form(TYPE_SUBMIT);
// Copy the hidden fields to the new form // Copy the hidden fields to the new form
for (Iterator fields=getFields(); fields.hasNext();) { for (Iterator fields=getFields(); fields.hasNext();) {
FormField field = (FormField)fields.next(); FormField field = (FormField)fields.next();