2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* 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.pubsub;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2015-08-17 08:16:49 +02:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
|
|
|
|
|
|
|
/**
|
2017-12-13 23:10:11 +01:00
|
|
|
* Represents the top level element of a PubSub event extension. All types of PubSub events are
|
2018-05-09 23:06:12 +02:00
|
|
|
* represented by this class. The specific type can be found by {@link #getEventType()}. The
|
2014-02-17 23:58:40 +01:00
|
|
|
* embedded event information, which is specific to the event type, can be retrieved by the {@link #getEvent()}
|
|
|
|
* method.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Robin Collier
|
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public class EventElement implements EmbeddedPacketExtension {
|
2015-08-17 08:16:49 +02:00
|
|
|
/**
|
|
|
|
* The constant String "event".
|
|
|
|
*/
|
|
|
|
public static final String ELEMENT = "event";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The constant String "http://jabber.org/protocol/pubsub#event".
|
|
|
|
*/
|
2018-04-19 11:05:43 +02:00
|
|
|
public static final String NAMESPACE = PubSubNamespace.event.getXmlns();
|
2015-08-17 08:16:49 +02:00
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private final EventElementType type;
|
|
|
|
private final NodeExtension ext;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public EventElement(EventElementType eventType, NodeExtension eventExt) {
|
2017-02-07 22:02:40 +01:00
|
|
|
type = eventType;
|
|
|
|
ext = eventExt;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public EventElementType getEventType() {
|
2017-02-07 22:02:40 +01:00
|
|
|
return type;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-06 10:21:46 +02:00
|
|
|
public List<ExtensionElement> getExtensions() {
|
2017-05-23 16:45:04 +02:00
|
|
|
return Arrays.asList(new ExtensionElement[] {getEvent()});
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
public NodeExtension getEvent() {
|
2017-02-07 22:02:40 +01:00
|
|
|
return ext;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getElementName() {
|
2017-02-07 22:02:40 +01:00
|
|
|
return "event";
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getNamespace() {
|
2018-04-19 11:05:43 +02:00
|
|
|
return PubSubNamespace.event.getXmlns();
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-08-17 08:16:49 +02:00
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2015-08-17 08:16:49 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
|
|
|
xml.rightAngleBracket();
|
2019-02-04 13:27:41 +01:00
|
|
|
xml.append(ext.toXML());
|
2015-08-17 08:16:49 +02:00
|
|
|
xml.closeElement(this);
|
|
|
|
return xml;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-08-17 08:16:49 +02:00
|
|
|
public static EventElement from(Stanza stanza) {
|
2020-04-05 22:10:05 +02:00
|
|
|
return stanza.getExtension(EventElement.class);
|
2015-08-17 08:16:49 +02:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|