mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Remove ValidateElement.EmptyValidateElement
because it has the same semantic as BasicValidateElement.
This commit is contained in:
parent
c770b12348
commit
d78b39d117
3 changed files with 9 additions and 33 deletions
|
@ -117,32 +117,6 @@ public abstract class ValidateElement implements PacketExtension {
|
|||
*/
|
||||
public abstract void checkConsistency(FormField formField);
|
||||
|
||||
/**
|
||||
*
|
||||
* This defines the empty validate element that does only specify a 'datatype' attribute.
|
||||
*
|
||||
*/
|
||||
public static class EmptyValidateElement extends ValidateElement {
|
||||
|
||||
/**
|
||||
* @param dataType
|
||||
* @see #getDatatype()
|
||||
*/
|
||||
public EmptyValidateElement(String dataType) {
|
||||
super(dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendXML(XmlStringBuilder buf) {
|
||||
// The empty validate element does not contain any further elements or text, it is empty.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConsistency(FormField formField) {
|
||||
// Since we can't know all possible datatypes, we can not perform any validation here
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation only against the datatype itself. Indicates that the value(s) should simply match the field type and
|
||||
* datatype constraints.
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.BasicValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.EmptyValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.ListRange;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.OpenValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement;
|
||||
|
@ -81,7 +80,9 @@ public class DataValidationProvider {
|
|||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
if (dataValidation == null) {
|
||||
dataValidation = new EmptyValidateElement(dataType);
|
||||
// XEP-122 § 3.2 states that "If no validation method is specified,
|
||||
// form processors MUST assume <basic/> validation."
|
||||
dataValidation = new BasicValidateElement(dataType);
|
||||
}
|
||||
dataValidation.setListRange(listRange);
|
||||
break outerloop;
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.EmptyValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.BasicValidateElement;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.ListRange;
|
||||
import org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement;
|
||||
import org.junit.Test;
|
||||
|
@ -38,7 +38,8 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
*
|
||||
*/
|
||||
public class DataValidationTest {
|
||||
private static final String TEST_OUTPUT_MIN = "<validate xmlns='http://jabber.org/protocol/xdata-validate'></validate>";
|
||||
private static final String TEST_INPUT_MIN = "<validate xmlns='http://jabber.org/protocol/xdata-validate'></validate>";
|
||||
private static final String TEST_OUTPUT_MIN = "<validate xmlns='http://jabber.org/protocol/xdata-validate'><basic/></validate>";
|
||||
private static final String TEST_OUTPUT_RANGE = "<validate xmlns='http://jabber.org/protocol/xdata-validate' datatype='xs:string'><range min='min-val' max='max-val'/><list-range min='111' max='999'/></validate>";
|
||||
private static final String TEST_OUTPUT_RANGE2 = "<validate xmlns='http://jabber.org/protocol/xdata-validate'><range/></validate>";
|
||||
private static final String TEST_OUTPUT_FAIL = "<validate xmlns='http://jabber.org/protocol/xdata-validate'><list-range min='1-1-1' max='999'/></validate>";
|
||||
|
@ -46,19 +47,19 @@ public class DataValidationTest {
|
|||
@Test
|
||||
public void testMin() throws XmlPullParserException, IOException, SmackException {
|
||||
|
||||
ValidateElement dv = new EmptyValidateElement(null);
|
||||
ValidateElement dv = new BasicValidateElement(null);
|
||||
|
||||
assertNotNull( dv.toXML());
|
||||
String output = dv.toXML().toString();
|
||||
assertEquals(TEST_OUTPUT_MIN, output);
|
||||
|
||||
XmlPullParser parser = getParser(output);
|
||||
XmlPullParser parser = getParser(TEST_INPUT_MIN);
|
||||
|
||||
dv = DataValidationProvider.parse(parser);
|
||||
|
||||
assertNotNull(dv);
|
||||
assertEquals("xs:string", dv.getDatatype());
|
||||
assertTrue( dv instanceof EmptyValidateElement);
|
||||
assertTrue( dv instanceof BasicValidateElement);
|
||||
|
||||
assertNotNull( dv.toXML());
|
||||
output = dv.toXML().toString();
|
||||
|
|
Loading…
Reference in a new issue