2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
|
|
|
* 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.nick.packet;
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2018-10-21 09:01:54 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2018-10-21 08:57:45 +02:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
/**
|
2015-02-26 18:41:17 +01:00
|
|
|
* A minimalistic implementation of a {@link ExtensionElement} for nicknames.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Guus der Kinderen, guus.der.kinderen@gmail.com
|
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0172.html">XEP-0172: User Nickname</a>
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class Nick implements ExtensionElement {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
public static final String NAMESPACE = "http://jabber.org/protocol/nick";
|
|
|
|
|
|
|
|
public static final String ELEMENT_NAME = "nick";
|
|
|
|
|
2018-10-21 09:01:54 +02:00
|
|
|
private final String name;
|
2017-02-07 22:02:40 +01:00
|
|
|
|
|
|
|
public Nick(String name) {
|
2018-10-21 09:01:54 +02:00
|
|
|
this.name = StringUtils.requireNotNullNorEmpty(name, "Nickname must be given");
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The value of this nickname.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return the nickname
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2017-02-07 22:02:40 +01:00
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT_NAME;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2017-02-07 22:02:40 +01:00
|
|
|
public String getNamespace() {
|
|
|
|
return NAMESPACE;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2018-10-21 08:57:45 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
|
|
|
xml.rightAngleBracket();
|
2017-02-07 22:02:40 +01:00
|
|
|
|
2018-10-21 08:57:45 +02:00
|
|
|
xml.escape(getName());
|
2017-02-07 22:02:40 +01:00
|
|
|
|
2018-10-21 08:57:45 +02:00
|
|
|
xml.closeElement(this);
|
|
|
|
return xml;
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|