1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-08 22:21:08 +01:00

Fix DataFormProvider parsing 'fixed' FormFields

b71039660b made FormField.setType(Type)
throw an illegal argument exception if type is fixed, but the
DataFormProvider was not changed, so it still would call
setType(Type.fixed).

Change DataFormProvider so that the non-argument constructer of
FormField is used when type == fixed.
This commit is contained in:
Florian Schmaus 2015-01-25 15:45:56 +01:00
parent 616768a5a9
commit 2cba6a68eb
3 changed files with 30 additions and 12 deletions

View file

@ -113,7 +113,16 @@ public class FormField implements NamedElement {
}
}
/**
* Get a form field type from the given string. If <code>string</code> is null, then null will be returned.
*
* @param string the string to transform or null.
* @return the type or null.
*/
public static Type fromString(String string) {
if (string == null) {
return null;
}
switch (string) {
case "boolean":
return bool;

View file

@ -94,12 +94,18 @@ public class DataFormProvider extends PacketExtensionProvider<DataForm> {
private FormField parseField(XmlPullParser parser) throws XmlPullParserException, IOException {
final int initialDepth = parser.getDepth();
FormField formField = new FormField(parser.getAttributeValue("", "var"));
formField.setLabel(parser.getAttributeValue("", "label"));
String typeString = parser.getAttributeValue("", "type");
if (typeString != null) {
formField.setType(FormField.Type.fromString(typeString));
final String var = parser.getAttributeValue("", "var");
final FormField.Type type = FormField.Type.fromString(parser.getAttributeValue("", "type"));
final FormField formField;
if (type == FormField.Type.fixed) {
formField = new FormField();
} else {
formField = new FormField(var);
formField.setType(type);
}
formField.setLabel(parser.getAttributeValue("", "label"));
outerloop: while (true) {
int eventType = parser.next();
switch (eventType) {