From 3600aa17d4b89cf3d0fe22ab8a2d82501a6cd9d9 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Mon, 5 Apr 2004 16:28:18 +0000 Subject: [PATCH] Modified to use new FormField constructor git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2280 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smackx/Form.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/org/jivesoftware/smackx/Form.java b/source/org/jivesoftware/smackx/Form.java index ca129fceb..5fa30fce0 100644 --- a/source/org/jivesoftware/smackx/Form.java +++ b/source/org/jivesoftware/smackx/Form.java @@ -74,6 +74,10 @@ import org.jivesoftware.smackx.packet.DataForm; */ 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; /** @@ -127,6 +131,7 @@ public class Form { * Adds a new field to complete as part of the form. * * @param field the field to complete. + * @throws IllegalStateException if the form is not of type "form". */ public void addField(FormField field) { if (!isFormType()) { @@ -141,13 +146,13 @@ public class Form { * * @param variable the variable that was completed. * @param value the value that was answered. + * @throws IllegalStateException if the form is not of type "submit". */ public void addAnswer(String variable, String value) { if (!isSubmitType()) { throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\""); } - FormField field = new FormField(); - field.setVariable(variable); + FormField field = new FormField(variable); field.addValue(value); dataForm.addField(field); } @@ -158,13 +163,13 @@ public class Form { * * @param variable the variable that was completed. * @param values the values that were answered. + * @throws IllegalStateException if the form is not of type "submit". */ public void addAnswer(String variable, List values) { if (!isSubmitType()) { throw new IllegalStateException("Cannot add fields if the form is not of type \"submit\""); } - FormField field = new FormField(); - field.setVariable(variable); + FormField field = new FormField(variable); field.addValues(values); dataForm.addField(field); } @@ -255,7 +260,7 @@ public class Form { * @return if the form is a form to fill out. */ 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. */ 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"); } // 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 for (Iterator fields=getFields(); fields.hasNext();) { FormField field = (FormField)fields.next();