AMPExpireAtCondition.java

  1. /**
  2.  *
  3.  * Copyright 2014 Vyacheslav Blinov
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.amp;

  18. import java.util.Date;

  19. import org.jivesoftware.smack.SmackException.NoResponseException;
  20. import org.jivesoftware.smack.SmackException.NotConnectedException;
  21. import org.jivesoftware.smack.XMPPConnection;
  22. import org.jivesoftware.smack.XMPPException.XMPPErrorException;

  23. import org.jivesoftware.smackx.amp.packet.AMPExtension;

  24. import org.jxmpp.util.XmppDateTime;


  25. public class AMPExpireAtCondition implements AMPExtension.Condition {

  26.     public static final String NAME = "expire-at";

  27.     /**
  28.      * Check if server supports expire-at condition.
  29.      * @param connection Smack connection instance
  30.      * @return true if expire-at condition is supported.
  31.      * @throws XMPPErrorException if there was an XMPP error returned.
  32.      * @throws NoResponseException if there was no response from the remote entity.
  33.      * @throws NotConnectedException if the XMPP connection is not connected.
  34.      * @throws InterruptedException if the calling thread was interrupted.
  35.      */
  36.     public static boolean isSupported(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException  {
  37.         return AMPManager.isConditionSupported(connection, NAME);
  38.     }

  39.     private final String value;

  40.     /**
  41.      * Create new expire-at amp condition with value set as XEP-0082 formatted date.
  42.      * @param utcDateTime Date instance of time
  43.      *                    that will be used as value parameter after formatting to XEP-0082 format. Can't be null.
  44.      */
  45.     public AMPExpireAtCondition(Date utcDateTime) {
  46.         if (utcDateTime == null)
  47.             throw new NullPointerException("Can't create AMPExpireAtCondition with null value");
  48.         this.value = XmppDateTime.formatXEP0082Date(utcDateTime);
  49.     }

  50.     /**
  51.      * Create new expire-at amp condition with defined value.
  52.      * @param utcDateTime UTC time string that will be used as value parameter.
  53.      *                    Should be formatted as XEP-0082 Date format. Can't be null.
  54.      */
  55.     public AMPExpireAtCondition(String utcDateTime) {
  56.         if (utcDateTime == null)
  57.             throw new NullPointerException("Can't create AMPExpireAtCondition with null value");
  58.         this.value = utcDateTime;
  59.     }

  60.     @Override
  61.     public String getName() {
  62.         return NAME;
  63.     }

  64.     @Override
  65.     public String getValue() {
  66.         return value;
  67.     }

  68. }