本文整理汇总了Java中org.jivesoftware.smack.packet.Packet.getExtension方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.getExtension方法的具体用法?Java Packet.getExtension怎么用?Java Packet.getExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.packet.Packet
的用法示例。
在下文中一共展示了Packet.getExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processPacket
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* This method handles incoming packets.
*
* @param packet
* The incoming packet.
* @throws NotConnectedException
*/
@Override
public void processPacket(Packet packet) throws NotConnectedException {
if (!(packet instanceof Message)) {
return;
}
Message message = (Message) packet;
if (message.getBody() == null) {
return;
}
PacketExtension extension = packet.getExtension(AliasPacketExtension.ALIAS_ELEMENT_NAME,
AliasPacketExtension.ALIAS_NAMESPACE);
if (extension == null) {
sendMessage(
packet.getFrom(),
packet.getTo(),
ResourceBundleManager.instance().getText(
"xmpp.message.error.bot",
XMPPPatternUtils.extractKenmeiUser(packet.getFrom())
.getLanguageLocale(),
XMPPPatternUtils.extractClientIdFromUser(packet.getFrom()),
XMPPPatternUtils.getBlogSuffix()));
} else {
sendMessageToCommunote(message, (AliasPacketExtension) extension);
}
}
示例2: extractHeadersFromXmpp
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
Map<String, Object> answer = new HashMap<String, Object>();
PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null && jpe instanceof JivePropertiesExtension) {
extractHeadersFrom((JivePropertiesExtension)jpe, exchange, answer);
}
if (jpe != null && jpe instanceof DefaultPacketExtension) {
extractHeadersFrom((DefaultPacketExtension)jpe, exchange, answer);
}
if (xmppPacket instanceof Message) {
Message xmppMessage = (Message) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
} else if (xmppPacket instanceof PubSub) {
PubSub pubsubPacket = (PubSub) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
}
answer.put(XmppConstants.FROM, xmppPacket.getFrom());
answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
answer.put(XmppConstants.TO, xmppPacket.getTo());
return answer;
}
示例3: getSubscriptionIds
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
private static List<String> getSubscriptionIds(Packet packet)
{
HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim");
List<String> values = null;
if (headers != null)
{
values = new ArrayList<String>(headers.getHeaders().size());
for (Header header : headers.getHeaders())
{
values.add(header.getValue());
}
}
return values;
}
示例4: accept
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
public boolean accept(Packet packet) {
// sender equals remote peer
if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
return false;
}
// stanza contains data packet extension
PacketExtension packetExtension = packet.getExtension(DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
if (packetExtension == null || !(packetExtension instanceof DataPacketExtension)) {
return false;
}
// session ID equals this session ID
DataPacketExtension data = (DataPacketExtension) packetExtension;
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
return false;
}
return true;
}
示例5: processPacket
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
@Override
public void processPacket(Packet packet) {
DeliveryReceipt dr = (DeliveryReceipt)packet.getExtension(
DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE);
if (dr != null) {
// notify listeners of incoming receipt
for (ReceiptReceivedListener l : receiptReceivedListeners) {
l.onReceiptReceived(packet.getFrom(), packet.getTo(), dr.getId());
}
}
// if enabled, automatically send a receipt
if (auto_receipts_enabled) {
DeliveryReceiptRequest drr = (DeliveryReceiptRequest)packet.getExtension(
DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE);
if (drr != null) {
Message ack = new Message(packet.getFrom(), Message.Type.normal);
ack.addExtension(new DeliveryReceipt(packet.getPacketID()));
connection.sendPacket(ack);
}
}
}
示例6: getFormFrom
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Returns a new ReportedData if the packet is used for gathering data and includes an
* extension that matches the elementName and namespace "x","jabber:x:data".
*
* @param packet the packet used for gathering data.
* @return the data form parsed from the packet or <tt>null</tt> if there was not
* a form in the packet.
*/
public static Form getFormFrom(Packet packet) {
// Check if the packet includes the DataForm extension
PacketExtension packetExtension = packet.getExtension("x","jabber:x:data");
if (packetExtension != null) {
// Check if the existing DataForm is not a result of a search
DataForm dataForm = (DataForm) packetExtension;
if (dataForm.getReportedData() == null)
return new Form(dataForm);
}
// Otherwise return null
return null;
}
示例7: getMUCUserExtension
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
*
* @param packet the packet that may include the MUCUser extension.
* @return the MUCUser found in the packet.
*/
private MUCUser getMUCUserExtension(Packet packet) {
if (packet != null) {
// Get the MUC User extension
return (MUCUser) packet.getExtension("x", "http://jabber.org/protocol/muc#user");
}
return null;
}
示例8: getSubscriptions
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Gets the subscriptions on the root node.
*
* @return List of exceptions
*
* @throws XMPPException
*/
public List<Subscription> getSubscriptions()
throws XMPPException
{
Packet reply = sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS));
SubscriptionsExtension subElem = (SubscriptionsExtension)reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
return subElem.getSubscriptions();
}
示例9: processPacket
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
public void processPacket(Packet packet)
{
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
ConfigurationEvent config = (ConfigurationEvent)event.getEvent();
listener.handleNodeConfiguration(config);
}
示例10: accept
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
public boolean accept(Packet packet)
{
if (!(packet instanceof Message))
return false;
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
if (event == null)
return false;
NodeExtension embedEvent = event.getEvent();
if (embedEvent == null)
return false;
if (embedEvent.getElementName().equals(firstElement))
{
if (!embedEvent.getNode().equals(getId()))
return false;
if (secondElement == null)
return true;
if (embedEvent instanceof EmbeddedPacketExtension)
{
List<PacketExtension> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions();
if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement))
return true;
}
}
return false;
}
示例11: getFormFromPacket
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Get a {@link ConfigureForm} from a packet.
*
* @param packet
* @param elem
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem)
{
FormNode config = (FormNode)packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
Form formReply = config.getForm();
return new ConfigureForm(formReply);
}
示例12: getDataPacketListener
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
protected PacketListener getDataPacketListener() {
return new PacketListener() {
public void processPacket(Packet packet) {
// get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
// check if encoded data is valid
if (data.getDecodedData() == null) {
/*
* TODO once a majority of XMPP server implementation support XEP-0079
* Advanced Message Processing the invalid message could be answered with an
* appropriate error. For now we just ignore the packet. Subsequent packets
* with an increased sequence will cause the input stream to close the
* stream/session.
*/
return;
}
// data is valid; add to data queue
dataQueue.offer(data);
// TODO confirm packet once XMPP servers support XEP-0079
}
};
}
示例13: getReportedDataFrom
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Returns a new ReportedData if the packet is used for reporting data and includes an
* extension that matches the elementName and namespace "x","jabber:x:data".
*
* @param packet the packet used for reporting data.
*/
public static ReportedData getReportedDataFrom(Packet packet) {
// Check if the packet includes the DataForm extension
PacketExtension packetExtension = packet.getExtension("x","jabber:x:data");
if (packetExtension != null) {
// Check if the existing DataForm is a result of a search
DataForm dataForm = (DataForm) packetExtension;
if (dataForm.getReportedData() != null)
return new ReportedData(dataForm);
}
// Otherwise return null
return null;
}
示例14: accept
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
public boolean accept(Packet packet) {
return packet.getExtension(elementName, namespace) != null;
}
示例15: getMessages
import org.jivesoftware.smack.packet.Packet; //导入方法依赖的package包/类
/**
* Returns an Iterator with the offline <tt>Messages</tt> whose stamp matches the specified
* request. The request will include the list of stamps that uniquely identifies
* the offline messages to retrieve. The returned offline messages will not be deleted
* from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages.
*
* @param nodes the list of stamps that uniquely identifies offline message.
* @return an Iterator with the offline <tt>Messages</tt> that were received as part of
* this request.
* @throws XMPPException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
*/
public Iterator<Message> getMessages(final List<String> nodes) throws XMPPException {
List<Message> messages = new ArrayList<Message>();
OfflineMessageRequest request = new OfflineMessageRequest();
for (String node : nodes) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
item.setAction("view");
request.addItem(item);
}
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Filter offline messages that were requested by this request
PacketFilter messageFilter = new AndFilter(packetFilter, new PacketFilter() {
public boolean accept(Packet packet) {
OfflineMessageInfo info = (OfflineMessageInfo) packet.getExtension("offline",
namespace);
return nodes.contains(info.getNode());
}
});
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
// Send the retrieval request to the server.
connection.sendPacket(request);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
} else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
// Collect the received offline messages
Message message = (Message) messageCollector.nextResult(
SmackConfiguration.getPacketReplyTimeout());
while (message != null) {
messages.add(message);
message =
(Message) messageCollector.nextResult(
SmackConfiguration.getPacketReplyTimeout());
}
// Stop queuing offline messages
messageCollector.cancel();
return messages.iterator();
}