2020-05-13 20:14:41 +02:00
|
|
|
/**
|
|
|
|
*
|
2021-07-18 17:21:50 +02:00
|
|
|
* Copyright 2020-2021 Florian Schmaus.
|
2020-05-13 20:14:41 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.xdata;
|
|
|
|
|
|
|
|
import org.jxmpp.jid.Jid;
|
2021-07-18 17:21:50 +02:00
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
|
import org.jxmpp.stringprep.XmppStringprepException;
|
2020-05-13 20:14:41 +02:00
|
|
|
|
|
|
|
public class JidSingleFormField extends SingleValueFormField {
|
|
|
|
|
|
|
|
private final Jid value;
|
|
|
|
|
|
|
|
protected JidSingleFormField(Builder builder) {
|
|
|
|
super(builder);
|
|
|
|
value = builder.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Jid getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder asBuilder() {
|
|
|
|
return new Builder(this);
|
|
|
|
}
|
|
|
|
|
2021-07-18 17:21:50 +02:00
|
|
|
public static final class Builder extends SingleValueFormField.Builder<JidSingleFormField, JidSingleFormField.Builder> {
|
2020-05-13 20:14:41 +02:00
|
|
|
private Jid value;
|
|
|
|
|
|
|
|
private Builder(JidSingleFormField jidSingleFormField) {
|
|
|
|
super(jidSingleFormField);
|
|
|
|
value = jidSingleFormField.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
Builder(String fieldName) {
|
|
|
|
super(fieldName, FormField.Type.jid_single);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void resetInternal() {
|
2021-07-18 17:21:50 +02:00
|
|
|
super.resetInternal();
|
2020-05-13 20:14:41 +02:00
|
|
|
value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder setValue(Jid value) {
|
2021-07-18 17:21:50 +02:00
|
|
|
return setValue(value, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder setValue(Jid value, String rawValue) {
|
2020-05-13 20:14:41 +02:00
|
|
|
this.value = value;
|
2021-07-18 17:21:50 +02:00
|
|
|
this.rawValue = new Value(value);
|
|
|
|
return getThis();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder setValue(Value value) throws XmppStringprepException {
|
|
|
|
this.value = JidCreate.from(value.getValue());
|
|
|
|
this.rawValue = value;
|
2020-05-13 20:14:41 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JidSingleFormField build() {
|
|
|
|
return new JidSingleFormField(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Builder getThis() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|