Java 类org.jivesoftware.smack.packet.DefaultPacketExtension 实例源码

项目:Camel    文件:XmppBinding.java   
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;
}
项目:spark-svn-mirror    文件:ContactItem.java   
/**
 * 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);
}
项目:Camel    文件:XmppBinding.java   
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);
        }
    }
}
项目:EIM    文件:PrivacyProvider.java   
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;
}
项目:androidpn_enhanced_client    文件:PrivacyProvider.java   
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;
}
项目:androidPN-client.    文件:PrivacyProvider.java   
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;
}
项目:xmppsupport_v2    文件:PrivacyProvider.java   
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;
}
项目:AndroidPNClient    文件:PrivacyProvider.java   
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;
}
项目:jamppa    文件:PacketParserUtils.java   
/**
 * 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;
}
项目:java-bells    文件:PrivacyProvider.java   
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;
}
项目:telegraph    文件:PrivacyProvider.java   
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;
}
项目:NewCommunication-Android    文件:PrivacyProvider.java   
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;
}
项目:asmack-mini    文件:PrivacyProvider.java   
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;
}
项目:spark-svn-mirror    文件:ReversiPanel.java   
/**
 * 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);
}
项目:androidpn_enhanced_client    文件:PacketParserUtils.java   
/**
 * 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;
}
项目:androidPN-client.    文件:PacketParserUtils.java   
/**
 * 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;
}
项目:Fastpath-webchat    文件:WorkgroupStatus.java   
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();
    }
}
项目:java-bells    文件:PacketParserUtils.java   
/**
 * 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;
}
项目:asmack-mini    文件:PacketParserUtils.java   
/**
 * 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;
}