本文整理汇总了Java中org.jivesoftware.smack.packet.DefaultPacketExtension类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPacketExtension类的具体用法?Java DefaultPacketExtension怎么用?Java DefaultPacketExtension使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPacketExtension类属于org.jivesoftware.smack.packet包,在下文中一共展示了DefaultPacketExtension类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractHeadersFromXmpp
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的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;
}
示例2: setPresence
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
/**
* Sets the current presence on this contact item.
*
* @param presence the presence.
*/
public void setPresence(Presence presence) {
this.presence = presence;
final PacketExtension packetExtension = presence.getExtension("x", "vcard-temp:x:update");
// Handle vCard update packet.
if (packetExtension != null && packetExtension instanceof DefaultPacketExtension) {
DefaultPacketExtension o = (DefaultPacketExtension)packetExtension;
String hash = o.getValue("photo");
if (hash != null) {
this.hash = hash;
if (!hashExists(hash)) {
updateAvatar();
updateAvatarInSideIcon();
}
}
}
updatePresenceIcon(presence);
}
示例3: extractHeadersFrom
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
private void extractHeadersFrom(DefaultPacketExtension jpe, Exchange exchange, Map<String, Object> answer) {
for (String name : jpe.getNames()) {
Object value = jpe.getValue(name);
if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) {
answer.put(name, value);
}
}
}
示例4: parseIQ
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
Privacy privacy = new Privacy();
/* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser
.getName(), parser.getNamespace(), parser)); */
privacy.addExtension(new DefaultPacketExtension(parser.getName(), parser.getNamespace()));
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("active")) {
String activeName = parser.getAttributeValue("", "name");
if (activeName == null) {
privacy.setDeclineActiveList(true);
} else {
privacy.setActiveName(activeName);
}
}
else if (parser.getName().equals("default")) {
String defaultName = parser.getAttributeValue("", "name");
if (defaultName == null) {
privacy.setDeclineDefaultList(true);
} else {
privacy.setDefaultName(defaultName);
}
}
else if (parser.getName().equals("list")) {
parseList(parser, privacy);
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
return privacy;
}
示例5: parseIQ
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
public IQ parseIQ(XmlPullParser parser) throws Exception {
Privacy privacy = new Privacy();
/*
* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser
* .getName(), parser.getNamespace(), parser));
*/
privacy.addExtension(new DefaultPacketExtension(parser.getName(),
parser.getNamespace()));
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("active")) {
String activeName = parser.getAttributeValue("", "name");
if (activeName == null) {
privacy.setDeclineActiveList(true);
} else {
privacy.setActiveName(activeName);
}
} else if (parser.getName().equals("default")) {
String defaultName = parser.getAttributeValue("", "name");
if (defaultName == null) {
privacy.setDeclineDefaultList(true);
} else {
privacy.setDefaultName(defaultName);
}
} else if (parser.getName().equals("list")) {
parseList(parser, privacy);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("query")) {
done = true;
}
}
}
return privacy;
}
示例6: parsePacketExtension
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
/**
* Parses a packet extension sub-packet.
*
* @param elementName
* the XML element name of the packet extension.
* @param namespace
* the XML namespace of the packet extension.
* @param parser
* the XML parser, positioned at the starting element of the
* extension.
* @return a PacketExtension.
* @throws Exception
* if a parsing error occurs.
*/
public static PacketExtension parsePacketExtension(String elementName,
String namespace, XmlPullParser parser) throws Exception {
DefaultPacketExtension extension = new DefaultPacketExtension(
elementName, namespace);
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
// If an empty element, set the value with the empty string.
if (parser.isEmptyElementTag()) {
extension.setValue(name, "");
}
// Otherwise, get the the element text.
else {
eventType = parser.next();
if (eventType == XmlPullParser.TEXT) {
String value = parser.getText();
extension.setValue(name, value);
}
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(elementName)) {
done = true;
}
}
}
return extension;
}
示例7: sendForfeit
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
/**
* Sends a forfeit message to the other player.
*/
public void sendForfeit() {
DefaultPacketExtension forfeit = new DefaultPacketExtension(GameForfeit.ELEMENT_NAME, GameForfeit.NAMESPACE);
forfeit.setValue("gameID", Integer.toString(gameID));
Message message = new Message();
message.setTo(opponentJID);
message.addExtension(forfeit);
connection.sendPacket(message);
connection.removePacketListener(gameMoveListener);
}
示例8: parsePacketExtension
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
/**
* Parses a packet extension sub-packet.
*
* @param elementName the XML element name of the packet extension.
* @param namespace the XML namespace of the packet extension.
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser)
throws Exception
{
// See if a provider is registered to handle the extension.
Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace);
if (provider != null) {
if (provider instanceof PacketExtensionProvider) {
return ((PacketExtensionProvider)provider).parseExtension(parser);
}
else if (provider instanceof Class) {
return (PacketExtension)parseWithIntrospection(
elementName, (Class)provider, parser);
}
}
// No providers registered, so use a default extension.
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
// If an empty element, set the value with the empty string.
if (parser.isEmptyElementTag()) {
extension.setValue(name,"");
}
// Otherwise, get the the element text.
else {
eventType = parser.next();
if (eventType == XmlPullParser.TEXT) {
String value = parser.getText();
extension.setValue(name, value);
}
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(elementName)) {
done = true;
}
}
}
return extension;
}
示例9: parsePacketExtension
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
/**
* Parses a packet extension sub-packet.
*
* @param elementName the XML element name of the packet extension.
* @param namespace the XML namespace of the packet extension.
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws Exception if a parsing error occurs.
*/
public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser)
throws Exception
{
// See if a provider is registered to handle the extension.
Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace);
if (provider != null) {
if (provider instanceof PacketExtensionProvider) {
return ((PacketExtensionProvider)provider).parseExtension(parser);
}
else if (provider instanceof Class) {
return (PacketExtension)parseWithIntrospection(
elementName, (Class<?>)provider, parser);
}
}
// No providers registered, so use a default extension.
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
// If an empty element, set the value with the empty string.
if (parser.isEmptyElementTag()) {
extension.setValue(name,"");
}
// Otherwise, get the the element text.
else {
eventType = parser.next();
if (eventType == XmlPullParser.TEXT) {
String value = parser.getText();
extension.setValue(name, value);
}
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(elementName)) {
done = true;
}
}
}
return extension;
}
示例10: initStatusListener
import org.jivesoftware.smack.packet.DefaultPacketExtension; //导入依赖的package包/类
public static void initStatusListener() {
ChatManager chatManager = ChatManager.getInstance();
final PacketListener presenceListener = new PacketListener() {
public void processPacket(Packet packet) {
if (packet instanceof Presence) {
Presence p = (Presence)packet;
DefaultPacketExtension ext = (DefaultPacketExtension)p.getExtension("workgroup", "http://jivesoftware.com/protocol/workgroup");
if (ext != null) {
String lastModified = ext.getValue("lastModified");
if (lastModified != null) {
String workgroupName = StringUtils.parseName(p.getFrom());
String previousDate = (String)CHANGE_MAP.get(workgroupName);
final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
try {
Date newDate = UTC_FORMAT.parse(lastModified);
if (ModelUtil.hasLength(previousDate)) {
Date oldDate = UTC_FORMAT.parse(previousDate);
if (newDate.getTime() > oldDate.getTime()) {
CHANGE_MAP.put(workgroupName, lastModified);
fireWorkgroupChanged(p.getFrom());
workgroupForms.remove(p.getFrom());
}
}
else {
CHANGE_MAP.put(workgroupName, lastModified);
}
}
catch (ParseException e) {
WebLog.logError("Error processing workgroup packet.", e);
}
}
}
}
}
};
if (chatManager.getGlobalConnection() == null || !chatManager.getGlobalConnection().isConnected()) {
ConnectionSettings settings = chatManager.getChatSettingsManager().getSettings();
WebLog.logError("A connection to the server could not be made when attempting connection to " + settings.getServerDomain());
}
else {
chatManager.getGlobalConnection().addPacketListener(presenceListener, new PacketTypeFilter(Presence.class));
workgroups.clear();
workgroupForms.clear();
workgroupPresence.clear();
}
}