• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java DelayInformation类的典型用法和代码示例

未分类 9次浏览

本文整理汇总了Java中org.jivesoftware.smackx.packet.DelayInformation的典型用法代码示例。如果您正苦于以下问题:Java DelayInformation类的具体用法?Java DelayInformation怎么用?Java DelayInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

DelayInformation类属于org.jivesoftware.smackx.packet包,在下文中一共展示了DelayInformation类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleDateWithMissingLeadingZeros

点赞 3

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
/**
 * Parses the given date string in different ways and returns the date that
 * lies in the past and/or is nearest to the current date-time.
 * 
 * @param stampString date in string representation
 * @return the parsed date
 */
private Date handleDateWithMissingLeadingZeros(String stampString) {
    Calendar now = new GregorianCalendar();
    Calendar xep91 = null;
    Calendar xep91Fallback = null;
    
    xep91 = parseXEP91Date(stampString, DelayInformation.XEP_0091_UTC_FORMAT);
    xep91Fallback = parseXEP91Date(stampString, XEP_0091_UTC_FALLBACK_FORMAT);
    
    List<Calendar> dates = filterDatesBefore(now, xep91, xep91Fallback);
    
    if (!dates.isEmpty()) {
        return determineNearestDate(now, dates).getTime();
    } 
    return null;
}
 

开发者ID:ice-coffee,
项目名称:EIM,
代码行数:23,
代码来源:DelayInformationProvider.java

示例2: getSendDate

点赞 3

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public static String getSendDate(final Message msg, final Locale loc) {
    for (final Iterator iter = msg.getExtensions().iterator(); iter.hasNext();) {
        final PacketExtension extension = (PacketExtension) iter.next();
        if (extension.getNamespace().equals("jabber:x:delay")) {
            final DelayInformation delayInfo = (DelayInformation) extension;
            final Date date = delayInfo.getStamp();
            // why does formatter with this method return a time in the afternoon
            // like 03:24 instead of 15:24 like formatTime does??
            return Formatter.getInstance(loc).formatDateAndTime(date);
        }
    }
    // if no delay time now is returned
    // return Formatter.getInstance(locale).formatTime(new Date());
    final Long receiveTime = (Long) msg.getProperty("receiveTime");
    final Date d = new Date();
    d.setTime(receiveTime.longValue());
    return Formatter.getInstance(loc).formatTime(d);
}
 

开发者ID:huihoo,
项目名称:olat,
代码行数:19,
代码来源:ClientHelper.java

示例3: handleDateWithMissingLeadingZeros

点赞 3

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
/**
 * Parses the given date string in different ways and returns the date that
 * lies in the past and/or is nearest to the current date-time.
 * 
 * @param stampString
 *            date in string representation
 * @return the parsed date
 */
private Date handleDateWithMissingLeadingZeros(String stampString) {
	Calendar now = new GregorianCalendar();
	Calendar xep91 = null;
	Calendar xep91Fallback = null;

	xep91 = parseXEP91Date(stampString,
			DelayInformation.XEP_0091_UTC_FORMAT);
	xep91Fallback = parseXEP91Date(stampString,
			XEP_0091_UTC_FALLBACK_FORMAT);

	List<Calendar> dates = filterDatesBefore(now, xep91, xep91Fallback);

	if (!dates.isEmpty()) {
		return determineNearestDate(now, dates).getTime();
	}
	return null;
}
 

开发者ID:ikantech,
项目名称:xmppsupport_v2,
代码行数:26,
代码来源:DelayInformationProvider.java

示例4: parseExtension

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    String stampString = (parser.getAttributeValue("", "stamp"));
    Date stamp = null;
    
    try {
        stamp = StringUtils.parseDate(stampString);
    }
    catch (ParseException parseExc) {
        /*
         * if date could not be parsed but XML is valid, don't shutdown
         * connection by throwing an exception instead set timestamp to epoch 
         * so that it is obviously wrong. 
         */
        if (stamp == null) {
            stamp = new Date(0);
        }
    }
    
    
    DelayInformation delayInformation = new DelayInformation(stamp);
    delayInformation.setFrom(parser.getAttributeValue("", "from"));
    String reason = parser.nextText();

    /*
     * parser.nextText() returns empty string if there is no reason.
     * DelayInformation API specifies that null should be returned in that
     * case.
     */
    reason = "".equals(reason) ? null : reason;
    delayInformation.setReason(reason);
    
    return delayInformation;
}
 

开发者ID:CJC-ivotten,
项目名称:androidPN-client.,
代码行数:34,
代码来源:DelayInformationProvider.java

示例5: sendOfflineMessages

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public void sendOfflineMessages() {
	Cursor cursor = mContentResolver.query(ChatProvider.CONTENT_URI,
			SEND_OFFLINE_PROJECTION, SEND_OFFLINE_SELECTION,
			null, null);
	final int      _ID_COL = cursor.getColumnIndexOrThrow(ChatConstants._ID);
	final int      JID_COL = cursor.getColumnIndexOrThrow(ChatConstants.JID);
	final int      MSG_COL = cursor.getColumnIndexOrThrow(ChatConstants.MESSAGE);
	final int       TS_COL = cursor.getColumnIndexOrThrow(ChatConstants.DATE);
	final int PACKETID_COL = cursor.getColumnIndexOrThrow(ChatConstants.PACKET_ID);
	ContentValues mark_sent = new ContentValues();
	mark_sent.put(ChatConstants.DELIVERY_STATUS, ChatConstants.DS_SENT_OR_READ);
	while (cursor.moveToNext()) {
		int _id = cursor.getInt(_ID_COL);
		String toJID = cursor.getString(JID_COL);
		String message = cursor.getString(MSG_COL);
		String packetID = cursor.getString(PACKETID_COL);
		long ts = cursor.getLong(TS_COL);
		Log.d(TAG, "sendOfflineMessages: " + toJID + " > " + message);
		final Message newMessage = new Message(toJID, Message.Type.chat);
		newMessage.setBody(message);
		DelayInformation delay = new DelayInformation(new Date(ts));
		newMessage.addExtension(delay);
		newMessage.addExtension(new DelayInfo(delay));
		newMessage.addExtension(new DeliveryReceiptRequest());
		if ((packetID != null) && (packetID.length() > 0)) {
			newMessage.setPacketID(packetID);
		} else {
			packetID = newMessage.getPacketID();
			mark_sent.put(ChatConstants.PACKET_ID, packetID);
		}
		Uri rowuri = Uri.parse("content://" + ChatProvider.AUTHORITY
			+ "/" + ChatProvider.TABLE_NAME + "/" + _id);
		mContentResolver.update(rowuri, mark_sent,
					null, null);
		mXMPPConnection.sendPacket(newMessage);		// must be after marking delivered, otherwise it may override the SendFailListener
	}
	cursor.close();
}
 

开发者ID:ufo22940268,
项目名称:maven-yaxim,
代码行数:39,
代码来源:SmackableImp.java

示例6: processPacket

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public void processPacket(final Packet packet) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                final Message message = (Message)packet;

                // Do not handle errors or offline messages
                final DelayInformation offlineInformation = (DelayInformation)message.getExtension("x", "jabber:x:delay");
                if (offlineInformation != null || message.getError() != null) {
                    return;
                }

                boolean broadcast = message.getProperty("broadcast") != null;

                if ((broadcast || message.getType() == Message.Type.normal
            	    || message.getType() == Message.Type.headline) && message.getBody() != null) {
                    showAlert((Message)packet);
                }
                else {
                    String host = SparkManager.getSessionManager().getServerAddress();
                    String from = packet.getFrom() != null ? packet.getFrom() : "";
                    if (host.equalsIgnoreCase(from) || !ModelUtil.hasLength(from)) {
                        showAlert((Message)packet);
                    }
                }
            }
            catch (Exception e) {
                Log.error(e);
            }
        }
    });

}
 

开发者ID:visit,
项目名称:spark-svn-mirror,
代码行数:34,
代码来源:BroadcastPlugin.java

示例7: messageReceived

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public void messageReceived(ChatRoom room, Message message) {

        // Do not play sounds on history updates.
        DelayInformation inf = (DelayInformation)message.getExtension("x", "jabber:x:delay");
        if (inf != null) {
            return;
        }

        SoundPreferences preferences = soundPreference.getPreferences();
        if (preferences.isPlayIncomingSound()) {
            File incomingFile = new File(preferences.getIncomingSound());
            SparkManager.getSoundManager().playClip(incomingFile);
        }
    }
 

开发者ID:visit,
项目名称:spark-svn-mirror,
代码行数:15,
代码来源:SoundPlugin.java

示例8: testDiscussionHistory

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public void testDiscussionHistory() {
    try {
        // User1 sends some messages to the room
        muc.sendMessage("Message 1");
        muc.sendMessage("Message 2");
        // Wait 5 seconds before sending the last message
        Thread.sleep(5000);
        muc.sendMessage("Message 3");

        // User2 joins the room requesting to receive the messages of the last 2 seconds.
        MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
        DiscussionHistory history = new DiscussionHistory();
        history.setSeconds(2);
        muc2.join("testbot2", null, history, SmackConfiguration.getPacketReplyTimeout());

        Message msg;
        // Get first historic message
        msg = muc2.nextMessage(1000);
        assertNotNull("First message is null", msg);
        DelayInformation delay = DelayInformationManager.getDelayInformation(msg);
        assertNotNull("Message contains no delay information", delay);
        SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
        UTC_FORMAT.setTimeZone(TimeZone.getDefault());
        System.out.println(UTC_FORMAT.format(delay.getStamp()));

        assertEquals("Body of first message is incorrect", "Message 3", msg.getBody());
        // Try to get second historic message 
        msg = muc2.nextMessage(1000);
        assertNull("Second message is not null", msg);


        // User3 joins the room requesting to receive the last 2 messages.
        MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
        history = new DiscussionHistory();
        history.setMaxStanzas(2);
        muc3.join("testbot3", null, history, SmackConfiguration.getPacketReplyTimeout());

        // Get first historic message 
        msg = muc3.nextMessage(1000);
        assertNotNull("First message is null", msg);
        assertEquals("Body of first message is incorrect", "Message 2", msg.getBody());
        // Get second historic message 
        msg = muc3.nextMessage(1000);
        assertNotNull("Second message is null", msg);
        assertEquals("Body of second message is incorrect", "Message 3", msg.getBody());
        // Try to get third historic message 
        msg = muc3.nextMessage(1000);
        assertNull("Third message is not null", msg);

        // User2 leaves the room
        muc2.leave();
        // User3 leaves the room
        muc3.leave();

    }
    catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 

开发者ID:TTalkIM,
项目名称:Smack,
代码行数:61,
代码来源:MultiUserChatTest.java

示例9: parseExtension

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    String stampString = (parser.getAttributeValue("", "stamp"));
    Date stamp = null;
    DateFormat format = null;
    
    for (String regexp : formats.keySet()) {
        if (stampString.matches(regexp)) {
            try {
                format = formats.get(regexp);
                synchronized (format) {
                    stamp = format.parse(stampString);
                }
            }
            catch (ParseException e) {
                // do nothing, format is still set
            }
            
            // break because only one regexp can match
            break;
        }
    }
    
    /*
     * if date is in XEP-0091 format handle ambiguous dates missing the
     * leading zero in month and day
     */
    if (format == DelayInformation.XEP_0091_UTC_FORMAT
                    && stampString.split("T")[0].length() < 8) {
        stamp = handleDateWithMissingLeadingZeros(stampString);
    }
    
    /*
     * if date could not be parsed but XML is valid, don't shutdown
     * connection by throwing an exception instead set timestamp to current
     * time
     */
    if (stamp == null) {
        stamp = new Date();
    }
    
    DelayInformation delayInformation = new DelayInformation(stamp);
    delayInformation.setFrom(parser.getAttributeValue("", "from"));
    String reason = parser.nextText();

    /*
     * parser.nextText() returns empty string if there is no reason.
     * DelayInformation API specifies that null should be returned in that
     * case.
     */
    reason = "".equals(reason) ? null : reason;
    delayInformation.setReason(reason);
    
    return delayInformation;
}
 

开发者ID:ice-coffee,
项目名称:EIM,
代码行数:55,
代码来源:DelayInformationProvider.java

示例10: parseExtension

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
@Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
	return new DelayInfo((DelayInformation)super.parseExtension(parser));
}
 

开发者ID:ice-coffee,
项目名称:EIM,
代码行数:6,
代码来源:DelayInfoProvider.java

示例11: sendOfflineMessages

点赞 2

import org.jivesoftware.smackx.packet.DelayInformation; //导入依赖的package包/类
/***************** start 发送离线消息 ***********************/
public void sendOfflineMessages() {
	Cursor cursor = mContentResolver.query(ChatProvider.CONTENT_URI,
			SEND_OFFLINE_PROJECTION, SEND_OFFLINE_SELECTION, null, null);// 查询数据库获取离线消息游标
	final int _ID_COL = cursor.getColumnIndexOrThrow(ChatConstants._ID);
	final int JID_COL = cursor.getColumnIndexOrThrow(ChatConstants.JID);
	final int MSG_COL = cursor.getColumnIndexOrThrow(ChatConstants.MESSAGE);
	final int TS_COL = cursor.getColumnIndexOrThrow(ChatConstants.DATE);
	final int PACKETID_COL = cursor
			.getColumnIndexOrThrow(ChatConstants.PACKET_ID);
	ContentValues mark_sent = new ContentValues();
	mark_sent.put(ChatConstants.DELIVERY_STATUS,
			ChatConstants.DS_SENT_OR_READ);
	while (cursor.moveToNext()) {// 遍历之后将离线消息发出
		int _id = cursor.getInt(_ID_COL);
		String toJID = cursor.getString(JID_COL);
		String message = cursor.getString(MSG_COL);
		String packetID = cursor.getString(PACKETID_COL);
		long ts = cursor.getLong(TS_COL);
		L.d("sendOfflineMessages: " + toJID + " > " + message);
		final Message newMessage = new Message(toJID, Message.Type.chat);
		newMessage.setBody(message);
		DelayInformation delay = new DelayInformation(new Date(ts));
		newMessage.addExtension(delay);
		newMessage.addExtension(new DelayInfo(delay));
		newMessage.addExtension(new DeliveryReceiptRequest());
		if ((packetID != null) && (packetID.length() > 0)) {
			newMessage.setPacketID(packetID);
		} else {
			packetID = newMessage.getPacketID();
			mark_sent.put(ChatConstants.PACKET_ID, packetID);
		}
		Uri rowuri = Uri.parse("content://" + ChatProvider.AUTHORITY + "/"
				+ ChatProvider.TABLE_NAME + "/" + _id);
		// 将消息标记为已发送再调用发送,因为,假设此消息又未发送成功,有SendFailListener重新标记消息
		mContentResolver.update(rowuri, mark_sent, null, null);
		mXMPPConnection.sendPacket(newMessage); // must be after marking
												// delivered, otherwise it
												// may override the
												// SendFailListener
	}
	cursor.close();
}
 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)