正在查看: Housing v14.7.8 应用的 ValidateElement.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 ValidateElement.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.jivesoftware.smackx.xdatavalidation.packet;
import com.quickblox.customobjects.request.QBAggregationRequestBuilder;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.util.NumberUtil;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdatavalidation.ValidationConsistencyException;
public abstract class ValidateElement implements ExtensionElement {
public static final String DATATYPE_XS_STRING = "xs:string";
public static final String ELEMENT = "validate";
public static final String NAMESPACE = "http://jabber.org/protocol/xdata-validate";
private final String datatype;
private ListRange listRange;
public static class AnonymousClass1 {
static final int[] $SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type;
static {
int[] iArr = new int[FormField.Type.values().length];
$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type = iArr;
try {
iArr[FormField.Type.hidden.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[FormField.Type.jid_multi.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[FormField.Type.jid_single.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[FormField.Type.list_multi.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[FormField.Type.text_multi.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
}
}
public static class BasicValidateElement extends ValidateElement {
public static final String METHOD = "basic";
public BasicValidateElement(String str) {
super(str, null);
}
@Override
public void appendXML(XmlStringBuilder xmlStringBuilder) {
xmlStringBuilder.emptyElement(METHOD);
}
@Override
public void checkConsistency(FormField formField) {
checkListRangeConsistency(formField);
if (formField.getType() != null) {
int i = AnonymousClass1.$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[formField.getType().ordinal()];
if (i == 1 || i == 2 || i == 3) {
throw new ValidationConsistencyException(String.format("Field type '%1$s' is not consistent with validation method '%2$s'.", formField.getType(), METHOD));
}
}
}
@Override
public CharSequence toXML() {
return super.toXML();
}
}
public static class ListRange implements NamedElement {
public static final String ELEMENT = "list-range";
private final Long max;
private final Long min;
public ListRange(Long l, Long l2) {
if (l != null) {
NumberUtil.checkIfInUInt32Range(l.longValue());
}
if (l2 != null) {
NumberUtil.checkIfInUInt32Range(l2.longValue());
}
if (l2 == null && l == null) {
throw new IllegalArgumentException("Either min or max must be given");
}
this.min = l;
this.max = l2;
}
@Override
public String getElementName() {
return ELEMENT;
}
public Long getMax() {
return this.max;
}
public Long getMin() {
return this.min;
}
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xmlStringBuilder = new XmlStringBuilder(this);
xmlStringBuilder.optLongAttribute(QBAggregationRequestBuilder.MIN, getMin());
xmlStringBuilder.optLongAttribute(QBAggregationRequestBuilder.MAX, getMax());
xmlStringBuilder.closeEmptyElement();
return xmlStringBuilder;
}
}
public static class OpenValidateElement extends ValidateElement {
public static final String METHOD = "open";
public OpenValidateElement(String str) {
super(str, null);
}
@Override
public void appendXML(XmlStringBuilder xmlStringBuilder) {
xmlStringBuilder.emptyElement("open");
}
@Override
public void checkConsistency(FormField formField) {
checkListRangeConsistency(formField);
if (formField.getType() != null && AnonymousClass1.$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[formField.getType().ordinal()] == 1) {
throw new ValidationConsistencyException(String.format("Field type '%1$s' is not consistent with validation method '%2$s'.", formField.getType(), "open"));
}
}
@Override
public CharSequence toXML() {
return super.toXML();
}
}
public static class RangeValidateElement extends ValidateElement {
public static final String METHOD = "range";
private final String max;
private final String min;
public RangeValidateElement(String str, String str2, String str3) {
super(str, null);
this.min = str2;
this.max = str3;
}
@Override
public void appendXML(XmlStringBuilder xmlStringBuilder) {
xmlStringBuilder.halfOpenElement(METHOD);
xmlStringBuilder.optAttribute(QBAggregationRequestBuilder.MIN, getMin());
xmlStringBuilder.optAttribute(QBAggregationRequestBuilder.MAX, getMax());
xmlStringBuilder.closeEmptyElement();
}
@Override
public void checkConsistency(FormField formField) {
checkNonMultiConsistency(formField, METHOD);
if (getDatatype().equals(ValidateElement.DATATYPE_XS_STRING)) {
throw new ValidationConsistencyException(String.format("Field data type '%1$s' is not consistent with validation method '%2$s'.", getDatatype(), METHOD));
}
}
public String getMax() {
return this.max;
}
public String getMin() {
return this.min;
}
@Override
public CharSequence toXML() {
return super.toXML();
}
}
public static class RegexValidateElement extends ValidateElement {
public static final String METHOD = "regex";
private final String regex;
public RegexValidateElement(String str, String str2) {
super(str, null);
this.regex = str2;
}
@Override
public void appendXML(XmlStringBuilder xmlStringBuilder) {
xmlStringBuilder.element(METHOD, getRegex());
}
@Override
public void checkConsistency(FormField formField) {
checkNonMultiConsistency(formField, METHOD);
}
public String getRegex() {
return this.regex;
}
@Override
public CharSequence toXML() {
return super.toXML();
}
}
private ValidateElement(String str) {
this.datatype = StringUtils.isNotEmpty(str) ? str : null;
}
public abstract void appendXML(XmlStringBuilder xmlStringBuilder);
public abstract void checkConsistency(FormField formField);
public void checkListRangeConsistency(FormField formField) {
ListRange listRange = getListRange();
if (listRange == null) {
return;
}
Long max = listRange.getMax();
Long 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.");
}
}
public void checkNonMultiConsistency(FormField formField, String str) {
checkListRangeConsistency(formField);
if (formField.getType() != null) {
int i = AnonymousClass1.$SwitchMap$org$jivesoftware$smackx$xdata$FormField$Type[formField.getType().ordinal()];
if (i == 1 || i == 2 || i == 4 || i == 5) {
throw new ValidationConsistencyException(String.format("Field type '%1$s' is not consistent with validation method '%2$s'.", formField.getType(), str));
}
}
}
public String getDatatype() {
String str = this.datatype;
return str != null ? str : DATATYPE_XS_STRING;
}
@Override
public String getElementName() {
return ELEMENT;
}
public ListRange getListRange() {
return this.listRange;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
public void setListRange(ListRange listRange) {
this.listRange = listRange;
}
public ValidateElement(String str, AnonymousClass1 anonymousClass1) {
this(str);
}
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xmlStringBuilder = new XmlStringBuilder((ExtensionElement) this);
xmlStringBuilder.optAttribute("datatype", this.datatype);
xmlStringBuilder.rightAngleBracket();
appendXML(xmlStringBuilder);
xmlStringBuilder.optAppend(getListRange());
xmlStringBuilder.closeElement(this);
return xmlStringBuilder;
}
}