mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 14:01:08 +01:00
Introduce UInt(16|32) datatypes
This commit is contained in:
parent
c0183775fe
commit
ce70308099
16 changed files with 262 additions and 49 deletions
|
|
@ -18,8 +18,8 @@ package org.jivesoftware.smackx.xdatavalidation.packet;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.datatypes.UInt32;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.NumberUtil;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
|
@ -339,8 +339,12 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
public static class ListRange implements NamedElement {
|
||||
|
||||
public static final String ELEMENT = "list-range";
|
||||
private final Long min;
|
||||
private final Long max;
|
||||
private final UInt32 min;
|
||||
private final UInt32 max;
|
||||
|
||||
public ListRange(Long min, Long max) {
|
||||
this(min != null ? UInt32.from(min) : null, max != null ? UInt32.from(max) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'max' attribute specifies the maximum allowable number of selected/entered values. The 'min' attribute
|
||||
|
|
@ -350,13 +354,7 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
public ListRange(Long min, Long max) {
|
||||
if (min != null) {
|
||||
NumberUtil.requireUInt32(min);
|
||||
}
|
||||
if (max != null) {
|
||||
NumberUtil.requireUInt32(max);
|
||||
}
|
||||
public ListRange(UInt32 min, UInt32 max) {
|
||||
if (max == null && min == null) {
|
||||
throw new IllegalArgumentException("Either min or max must be given");
|
||||
}
|
||||
|
|
@ -367,8 +365,8 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
buf.optLongAttribute("min", getMin());
|
||||
buf.optLongAttribute("max", getMax());
|
||||
buf.optAttribute("min", getMin());
|
||||
buf.optAttribute("max", getMax());
|
||||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
}
|
||||
|
|
@ -383,7 +381,7 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
*
|
||||
* @return a positive integer, can be null
|
||||
*/
|
||||
public Long getMin() {
|
||||
public UInt32 getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
|
|
@ -392,7 +390,7 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
*
|
||||
* @return a positive integer, can be null
|
||||
*/
|
||||
public Long getMax() {
|
||||
public UInt32 getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
|
|
@ -410,8 +408,8 @@ public abstract class ValidateElement implements FormFieldChildElement {
|
|||
return;
|
||||
}
|
||||
|
||||
Long max = listRange.getMax();
|
||||
Long min = listRange.getMin();
|
||||
Object max = listRange.getMax();
|
||||
Object min = listRange.getMin();
|
||||
if ((max != null || min != null) && formField.getType() != FormField.Type.list_multi) {
|
||||
throw new ValidationConsistencyException(
|
||||
"Field type is not of type 'list-multi' while a 'list-range' is defined.");
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.datatypes.UInt32;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
|
@ -72,8 +73,8 @@ public class DataValidationProvider extends FormFieldChildElementProvider<Valida
|
|||
dataValidation = new RegexValidateElement(dataType, parser.nextText());
|
||||
break;
|
||||
case ListRange.ELEMENT:
|
||||
Long min = ParserUtils.getLongAttribute(parser, "min");
|
||||
Long max = ParserUtils.getLongAttribute(parser, "max");
|
||||
UInt32 min = ParserUtils.getUInt32Attribute(parser, "min");
|
||||
UInt32 max = ParserUtils.getUInt32Attribute(parser, "max");
|
||||
if (min != null || max != null) {
|
||||
listRange = new ListRange(min, max);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue