001/** 002 * 003 * Copyright 2014 Vyacheslav Blinov 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.amp; 018 019import org.jivesoftware.smack.SmackException.NoResponseException; 020import org.jivesoftware.smack.SmackException.NotConnectedException; 021import org.jivesoftware.smack.XMPPConnection; 022import org.jivesoftware.smack.XMPPException.XMPPErrorException; 023import org.jxmpp.util.XmppDateTime; 024import org.jivesoftware.smackx.amp.packet.AMPExtension; 025 026import java.util.Date; 027 028 029public class AMPExpireAtCondition implements AMPExtension.Condition { 030 031 public static final String NAME = "expire-at"; 032 033 /** 034 * Check if server supports expire-at condition. 035 * @param connection Smack connection instance 036 * @return true if expire-at condition is supported. 037 * @throws XMPPErrorException 038 * @throws NoResponseException 039 * @throws NotConnectedException 040 * @throws InterruptedException 041 */ 042 public static boolean isSupported(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 043 return AMPManager.isConditionSupported(connection, NAME); 044 } 045 046 private final String value; 047 048 /** 049 * Create new expire-at amp condition with value setted as XEP-0082 formatted date. 050 * @param utcDateTime Date instance of time 051 * that will be used as value parameter after formatting to XEP-0082 format. Can't be null. 052 */ 053 public AMPExpireAtCondition(Date utcDateTime) { 054 if (utcDateTime == null) 055 throw new NullPointerException("Can't create AMPExpireAtCondition with null value"); 056 this.value = XmppDateTime.formatXEP0082Date(utcDateTime); 057 } 058 059 /** 060 * Create new expire-at amp condition with defined value. 061 * @param utcDateTime UTC time string that will be used as value parameter. 062 * Should be formatted as XEP-0082 Date format. Can't be null. 063 */ 064 public AMPExpireAtCondition(String utcDateTime) { 065 if (utcDateTime == null) 066 throw new NullPointerException("Can't create AMPExpireAtCondition with null value"); 067 this.value = utcDateTime; 068 } 069 070 @Override 071 public String getName() { 072 return NAME; 073 } 074 075 @Override 076 public String getValue() { 077 return value; 078 } 079 080}