All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jivesoftware.smackx.delay.DelayInformationManager Maven / Gradle / Ivy

Go to download

Smack extensions. Classes and methods that implement support for the various XMPP XEPs (Multi-User Chat, PubSub, …) and other XMPP extensions.

There is a newer version: 4.5.0-beta5
Show newest version
/**
 *
 * Copyright © 2014-2020 Florian Schmaus
 *
 * 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.delay;

import java.util.Date;

import javax.xml.namespace.QName;

import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;

import org.jivesoftware.smackx.delay.packet.DelayInformation;

/**
 * Delayed Delivery (XEP-203).
 *
 * @author Florian Schmaus
 * @see Delayed Delivery (XEP-203)
 *
 */
public class DelayInformationManager {

    public static final String LEGACY_DELAYED_DELIVERY_NAMESPACE = "jabber:x:delay";
    public static final String LEGACY_DELAYED_DELIVERY_ELEMENT = "x";
    public static final QName QNAME = new QName(LEGACY_DELAYED_DELIVERY_NAMESPACE, LEGACY_DELAYED_DELIVERY_ELEMENT);


    /**
     * Get Delayed Delivery information as defined in XEP-203
     * 

* Prefer {@link #getDelayInformation(Stanza)} over this method for backwards compatibility. *

* @param packet TODO javadoc me please * @return the Delayed Delivery information or null */ public static DelayInformation getXep203DelayInformation(Stanza packet) { return DelayInformation.from(packet); } /** * Get Delayed Delivery information as defined in XEP-91 *

* Prefer {@link #getDelayInformation(Stanza)} over this method for backwards compatibility. *

* @param packet TODO javadoc me please * @return the Delayed Delivery information or null */ public static DelayInformation getLegacyDelayInformation(Stanza packet) { return packet.getExtension(DelayInformation.class); } /** * Get Delayed Delivery information. This method first looks for a PacketExtension with the * XEP-203 namespace and falls back to the XEP-91 namespace. * * @param packet TODO javadoc me please * @return the Delayed Delivery information or null */ public static DelayInformation getDelayInformation(Stanza packet) { DelayInformation delayInformation = getXep203DelayInformation(packet); if (delayInformation != null) { return delayInformation; } return getLegacyDelayInformation(packet); } /** * Get the Delayed Delivery timestamp or null. * * @param packet TODO javadoc me please * @return the Delayed Delivery timestamp or null */ public static Date getDelayTimestamp(Stanza packet) { DelayInformation delayInformation = getDelayInformation(packet); if (delayInformation == null) { return null; } return delayInformation.getStamp(); } /** * Check if the given stanza is a delayed stanza as of XEP-203. * * @param packet TODO javadoc me please * @return true if the stanza got delayed. */ public static boolean isDelayedStanza(Stanza packet) { ExtensionElement packetExtension = getDelayInformation(packet); return packetExtension != null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy