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

项目:communote-server    文件:XMPPMessagePacketListener.java   
/**
 * 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);
    }
}
项目:Smack    文件:CarExtensionProvider.java   
public PacketExtension parse(XmlPullParser parser, int initialDepth) throws Exception
{
    String color = null;
    int numTires = 0;

    for (int i=0; i<2; i++)
    {
        while (parser.next() != XmlPullParser.START_TAG);

        if (parser.getName().equals("paint"))
        {
            color = parser.getAttributeValue(0);
        }
        else
        {
            numTires = Integer.parseInt(parser.getAttributeValue(0));
        }
    }
    while (parser.next() != XmlPullParser.END_TAG);
    return new CarExtension(color, numTires);
}
项目: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;
}
项目:androidPN-client.    文件:PEPProvider.java   
/**
 * Parses a PEPEvent packet and extracts a PEPItem from it.
 * (There is only one per <event>.)
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {

    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("event")) {
            } else if (parser.getName().equals("items")) {
                // Figure out the node for this event.
                String node = parser.getAttributeValue("", "node");
                // Get the parser for this kind of node, and if found then parse the node.
                PacketExtensionProvider nodeParser = nodeParsers.get(node);
                if (nodeParser != null) {
                    pepItem = nodeParser.parseExtension(parser);
                }
             }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("event")) {
                done = true;
            }
        }
    }

    return pepItem;
}
项目:androidPN-client.    文件:MultipleAddressesProvider.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    boolean done = false;
    MultipleAddresses multipleAddresses = new MultipleAddresses();
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("address")) {
                String type = parser.getAttributeValue("", "type");
                String jid = parser.getAttributeValue("", "jid");
                String node = parser.getAttributeValue("", "node");
                String desc = parser.getAttributeValue("", "desc");
                boolean delivered = "true".equals(parser.getAttributeValue("", "delivered"));
                String uri = parser.getAttributeValue("", "uri");
                // Add the parsed address
                multipleAddresses.addAddress(type, jid, node, desc, delivered, uri);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(multipleAddresses.getElementName())) {
                done = true;
            }
        }
    }
    return multipleAddresses;
}
项目:androidPN-client.    文件:OfflineMessageInfo.java   
/**
 * Parses a OfflineMessageInfo packet (extension sub-packet).
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser)
    throws Exception {
    OfflineMessageInfo info = new OfflineMessageInfo();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("item"))
                info.setNode(parser.getAttributeValue("", "node"));
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("offline")) {
                done = true;
            }
        }
    }

    return info;
}
项目:EIM    文件:AgentStatus.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    AgentStatus agentStatus = new AgentStatus();

    agentStatus.workgroupJID = parser.getAttributeValue("", "jid");

    boolean done = false;
    while (!done) {
        int eventType = parser.next();

        if (eventType == XmlPullParser.START_TAG) {
            if ("chat".equals(parser.getName())) {
                agentStatus.currentChats.add(parseChatInfo(parser));
            }
            else if ("max-chats".equals(parser.getName())) {
                agentStatus.maxChats = Integer.parseInt(parser.nextText());
            }
        }
        else if (eventType == XmlPullParser.END_TAG &&
            ELEMENT_NAME.equals(parser.getName())) {
            done = true;
        }
    }
    return agentStatus;
}
项目:EIM    文件:InBandBytestreamSession.java   
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;
}
项目:EIM    文件:EmbeddedExtensionProvider.java   
final public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
       String namespace = parser.getNamespace();
       String name = parser.getName();
       Map<String, String> attMap = new HashMap<String, String>();

       for(int i=0; i<parser.getAttributeCount(); i++)
       {
        attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
       }
       List<PacketExtension> extensions = new ArrayList<PacketExtension>();

       do
       {
           int tag = parser.next();

           if (tag == XmlPullParser.START_TAG) 
            extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
       } while (!name.equals(parser.getName()));

    return createReturnExtension(name, namespace, attMap, extensions);
}
项目:EIM    文件:PEPProvider.java   
/**
 * Parses a PEPEvent packet and extracts a PEPItem from it.
 * (There is only one per <event>.)
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {

    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("event")) {
            } else if (parser.getName().equals("items")) {
                // Figure out the node for this event.
                String node = parser.getAttributeValue("", "node");
                // Get the parser for this kind of node, and if found then parse the node.
                PacketExtensionProvider nodeParser = nodeParsers.get(node);
                if (nodeParser != null) {
                    pepItem = nodeParser.parseExtension(parser);
                }
             }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("event")) {
                done = true;
            }
        }
    }

    return pepItem;
}
项目:EIM    文件:OfflineMessageInfo.java   
/**
 * Parses a OfflineMessageInfo packet (extension sub-packet).
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser)
    throws Exception {
    OfflineMessageInfo info = new OfflineMessageInfo();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("item"))
                info.setNode(parser.getAttributeValue("", "node"));
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("offline")) {
                done = true;
            }
        }
    }

    return info;
}
项目:androidPN-client.    文件:EmbeddedExtensionProvider.java   
final public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
       String namespace = parser.getNamespace();
       String name = parser.getName();
       Map<String, String> attMap = new HashMap<String, String>();

       for(int i=0; i<parser.getAttributeCount(); i++)
       {
        attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
       }
       List<PacketExtension> extensions = new ArrayList<PacketExtension>();

       do
       {
           int tag = parser.next();

           if (tag == XmlPullParser.START_TAG) 
            extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
       } while (!name.equals(parser.getName()));

    return createReturnExtension(name, namespace, attMap, extensions);
}
项目:fcmxmppserver    文件:CcsClient.java   
private CcsClient() {
    // Add FcmPacketExtension
    ProviderManager.getInstance().addExtensionProvider(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE,
            new PacketExtensionProvider() {

                @Override
                public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
                    String json = parser.nextText();
                    FcmPacketExtension packet = new FcmPacketExtension(json);
                    return packet;
                }
            });
}
项目:EIM    文件:Form.java   
/**
 * 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;
}
项目:androidPN-client.    文件:WorkgroupInformation.java   
/**
 * PacketExtensionProvider implementation
 */
public PacketExtension parseExtension (XmlPullParser parser)
    throws Exception {
    String workgroupJID = parser.getAttributeValue("", "jid");

    // since this is a start and end tag, and we arrive on the start, this should guarantee
    //      we leave on the end
    parser.next();

    return new WorkgroupInformation(workgroupJID);
}
项目:EIM    文件:PubSubManager.java   
static PubSub createPubsubPacket(String to, Type type, PacketExtension ext, PubSubNamespace ns)
{
    PubSub request = new PubSub();
    request.setTo(to);
    request.setType(type);

    if (ns != null)
    {
        request.setPubSubNamespace(ns);
    }
    request.addExtension(ext);

    return request;
}
项目:androidPN-client.    文件:ChatStateExtension.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    ChatState state;
    try {
        state = ChatState.valueOf(parser.getName());
    }
    catch (Exception ex) {
        state = ChatState.active;
    }
    return new ChatStateExtension(state);
}
项目:androidPN-client.    文件:Nick.java   
public PacketExtension parseExtension(XmlPullParser parser)
        throws Exception {

          parser.next();
    final String name = parser.getText();

    // Advance to end of extension.
    while(parser.getEventType() != XmlPullParser.END_TAG) {
        parser.next();
    }

    return new Nick(name);
}
项目:EIM    文件:ConfigurationEvent.java   
public List<PacketExtension> getExtensions()
{
    if (getConfiguration() == null)
        return Collections.EMPTY_LIST;
    else
        return Arrays.asList(((PacketExtension)getConfiguration().getDataFormToSend()));
}
项目:EIM    文件:ConfigEventProvider.java   
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
{
    if (content.size() == 0)
        return new ConfigurationEvent(attMap.get("node"));
    else
        return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next()));
}
项目:androidPN-client.    文件:RoomTransfer.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    final RoomTransfer invitation = new RoomTransfer();
    invitation.type = RoomTransfer.Type.valueOf(parser.getAttributeValue("", "type"));

    boolean done = false;
    while (!done) {
        parser.next();
        String elementName = parser.getName();
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if ("session".equals(elementName)) {
                invitation.sessionID = parser.getAttributeValue("", "id");
            }
            else if ("invitee".equals(elementName)) {
                invitation.invitee = parser.nextText();
            }
            else if ("inviter".equals(elementName)) {
                invitation.inviter = parser.nextText();
            }
            else if ("reason".equals(elementName)) {
                invitation.reason = parser.nextText();
            }
            else if ("room".equals(elementName)) {
                invitation.room = parser.nextText();
            }
        }
        else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
            done = true;
        }
    }
    return invitation;
}
项目:EIM    文件:ItemProvider.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
    String id = parser.getAttributeValue(null, "id");
    String elem = parser.getName();

    int tag = parser.next();

    if (tag == XmlPullParser.END_TAG)
    {
        return new Item(id);        
    }
    else
    {
        String payloadElemName = parser.getName();
        String payloadNS = parser.getNamespace();

        if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
        {
            boolean done = false;
            StringBuilder payloadText = new StringBuilder();

            while (!done)
            {
                if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
                    done = true;
                else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag()))
                    payloadText.append(parser.getText());

                if (!done)
                    tag = parser.next();
            }
            return new PayloadItem<SimplePayload>(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
        }
        else
        {
            return new PayloadItem<PacketExtension>(id, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
        }
    }
}
项目:EIM    文件:PubSubProvider.java   
public IQ parseIQ(XmlPullParser parser) throws Exception
{
       PubSub pubsub = new PubSub();
       String namespace = parser.getNamespace();
       pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
       boolean done = false;

       while (!done) 
       {
           int eventType = parser.next();

           if (eventType == XmlPullParser.START_TAG) 
           {
            PacketExtension ext = PacketParserUtils.parsePacketExtension(parser.getName(), namespace, parser);

            if (ext != null)
            {
                pubsub.addExtension(ext);
            }
           }
           else if (eventType == XmlPullParser.END_TAG) 
           {
               if (parser.getName().equals("pubsub")) 
               {
                   done = true;
               }
           }
       }
       return pubsub;
}
项目:EIM    文件:RoomInvitation.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    final RoomInvitation invitation = new RoomInvitation();
    invitation.type = Type.valueOf(parser.getAttributeValue("", "type"));

    boolean done = false;
    while (!done) {
        parser.next();
        String elementName = parser.getName();
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if ("session".equals(elementName)) {
                invitation.sessionID = parser.getAttributeValue("", "id");
            }
            else if ("invitee".equals(elementName)) {
                invitation.invitee = parser.nextText();
            }
            else if ("inviter".equals(elementName)) {
                invitation.inviter = parser.nextText();
            }
            else if ("reason".equals(elementName)) {
                invitation.reason = parser.nextText();
            }
            else if ("room".equals(elementName)) {
                invitation.room = parser.nextText();
            }
        }
        else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
            done = true;
        }
    }
    return invitation;
}
项目:EIM    文件:UserID.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    String userID = parser.getAttributeValue("", "id");

    // Advance to end of extension.
    parser.next();

    return new UserID(userID);
}
项目:EIM    文件:MetaDataProvider.java   
/**
 * PacketExtensionProvider implementation
 */
public PacketExtension parseExtension (XmlPullParser parser)
    throws Exception {
    Map metaData = MetaDataUtils.parseMetaData(parser);

    return new MetaData(metaData);
}
项目:EIM    文件:QueueOverview.java   
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
    int eventType = parser.getEventType();
    QueueOverview queueOverview = new QueueOverview();

    if (eventType != XmlPullParser.START_TAG) {
        // throw exception
    }

    eventType = parser.next();
    while ((eventType != XmlPullParser.END_TAG)
                 || (!ELEMENT_NAME.equals(parser.getName())))
    {
        if ("count".equals(parser.getName())) {
            queueOverview.setUserCount(Integer.parseInt(parser.nextText()));
        }
        else if ("time".equals(parser.getName())) {
            queueOverview.setAverageWaitTime(Integer.parseInt(parser.nextText()));
        }
        else if ("oldest".equals(parser.getName())) {
            queueOverview.setOldestEntry((DATE_FORMATTER.parse(parser.nextText())));
        }
        else if ("status".equals(parser.getName())) {
            queueOverview.setStatus(WorkgroupQueue.Status.fromString(parser.nextText()));
        }

        eventType = parser.next();

        if (eventType != XmlPullParser.END_TAG) {
            // throw exception
        }
    }

    if (eventType != XmlPullParser.END_TAG) {
        // throw exception
    }

    return queueOverview;
}
项目:EIM    文件:RoomTransfer.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    final RoomTransfer invitation = new RoomTransfer();
    invitation.type = RoomTransfer.Type.valueOf(parser.getAttributeValue("", "type"));

    boolean done = false;
    while (!done) {
        parser.next();
        String elementName = parser.getName();
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if ("session".equals(elementName)) {
                invitation.sessionID = parser.getAttributeValue("", "id");
            }
            else if ("invitee".equals(elementName)) {
                invitation.invitee = parser.nextText();
            }
            else if ("inviter".equals(elementName)) {
                invitation.inviter = parser.nextText();
            }
            else if ("reason".equals(elementName)) {
                invitation.reason = parser.nextText();
            }
            else if ("room".equals(elementName)) {
                invitation.room = parser.nextText();
            }
        }
        else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
            done = true;
        }
    }
    return invitation;
}
项目:EIM    文件:SessionID.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    String sessionID = parser.getAttributeValue("", "id");

    // Advance to end of extension.
    parser.next();

    return new SessionID(sessionID);
}
项目:androidPN-client.    文件:MessageEventProvider.java   
/**
 * Parses a MessageEvent packet (extension sub-packet).
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser)
    throws Exception {
    MessageEvent messageEvent = new MessageEvent();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("id"))
                messageEvent.setPacketID(parser.nextText());
            if (parser.getName().equals(MessageEvent.COMPOSING))
                messageEvent.setComposing(true);
            if (parser.getName().equals(MessageEvent.DELIVERED))
                messageEvent.setDelivered(true);
            if (parser.getName().equals(MessageEvent.DISPLAYED))
                messageEvent.setDisplayed(true);
            if (parser.getName().equals(MessageEvent.OFFLINE))
                messageEvent.setOffline(true);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("x")) {
                done = true;
            }
        }
    }

    return messageEvent;
}
项目:EIM    文件:ReportedData.java   
/**
 * 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;
}
项目:EIM    文件:HeaderProvider.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
{
    String name = parser.getAttributeValue(null, "name");
    String value = null;

    parser.next();

    if (parser.getEventType() == XmlPullParser.TEXT)
        value = parser.getText();

    while(parser.getEventType() != XmlPullParser.END_TAG)
        parser.next();

    return new Header(name, value);
}
项目:androidPN-client.    文件:RoomInvitation.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    final RoomInvitation invitation = new RoomInvitation();
    invitation.type = Type.valueOf(parser.getAttributeValue("", "type"));

    boolean done = false;
    while (!done) {
        parser.next();
        String elementName = parser.getName();
        if (parser.getEventType() == XmlPullParser.START_TAG) {
            if ("session".equals(elementName)) {
                invitation.sessionID = parser.getAttributeValue("", "id");
            }
            else if ("invitee".equals(elementName)) {
                invitation.invitee = parser.nextText();
            }
            else if ("inviter".equals(elementName)) {
                invitation.inviter = parser.nextText();
            }
            else if ("reason".equals(elementName)) {
                invitation.reason = parser.nextText();
            }
            else if ("room".equals(elementName)) {
                invitation.room = parser.nextText();
            }
        }
        else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
            done = true;
        }
    }
    return invitation;
}
项目:EIM    文件:MessageEventProvider.java   
/**
 * Parses a MessageEvent packet (extension sub-packet).
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public PacketExtension parseExtension(XmlPullParser parser)
    throws Exception {
    MessageEvent messageEvent = new MessageEvent();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("id"))
                messageEvent.setPacketID(parser.nextText());
            if (parser.getName().equals(MessageEvent.COMPOSING))
                messageEvent.setComposing(true);
            if (parser.getName().equals(MessageEvent.DELIVERED))
                messageEvent.setDelivered(true);
            if (parser.getName().equals(MessageEvent.DISPLAYED))
                messageEvent.setDisplayed(true);
            if (parser.getName().equals(MessageEvent.OFFLINE))
                messageEvent.setOffline(true);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("x")) {
                done = true;
            }
        }
    }

    return messageEvent;
}
项目:EIM    文件:RosterExchangeProvider.java   
/**
   * Parses a RosterExchange packet (extension sub-packet).
   *
   * @param parser the XML parser, positioned at the starting element of the extension.
   * @return a PacketExtension.
   * @throws Exception if a parsing error occurs.
   */
  public PacketExtension parseExtension(XmlPullParser parser) throws Exception {

      RosterExchange rosterExchange = new RosterExchange();
      boolean done = false;
      RemoteRosterEntry remoteRosterEntry = null;
String jid = "";
String name = "";
ArrayList groupsName = new ArrayList();
      while (!done) {
          int eventType = parser.next();
          if (eventType == XmlPullParser.START_TAG) {
              if (parser.getName().equals("item")) {
                // Reset this variable since they are optional for each item
            groupsName = new ArrayList();
            // Initialize the variables from the parsed XML
                  jid = parser.getAttributeValue("", "jid");
                  name = parser.getAttributeValue("", "name");
              }
              if (parser.getName().equals("group")) {
            groupsName.add(parser.nextText());
              }
          } else if (eventType == XmlPullParser.END_TAG) {
              if (parser.getName().equals("item")) {
            // Create packet.
            remoteRosterEntry = new RemoteRosterEntry(jid, name, (String[]) groupsName.toArray(new String[groupsName.size()]));
                  rosterExchange.addRosterEntry(remoteRosterEntry);
              }
              if (parser.getName().equals("x")) {
                  done = true;
              }
          }
      }

      return rosterExchange;

  }
项目:EIM    文件:DataFormProvider.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    boolean done = false;
    StringBuilder buffer = null;
    DataForm dataForm = new DataForm(parser.getAttributeValue("", "type"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("instructions")) { 
                dataForm.addInstruction(parser.nextText());
            }
            else if (parser.getName().equals("title")) {                    
                dataForm.setTitle(parser.nextText());
            }
            else if (parser.getName().equals("field")) {                    
                dataForm.addField(parseField(parser));
            }
            else if (parser.getName().equals("item")) {                    
                dataForm.addItem(parseItem(parser));
            }
            else if (parser.getName().equals("reported")) {                    
                dataForm.setReportedData(parseReported(parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(dataForm.getElementName())) {
                done = true;
            }
        }
    }
    return dataForm;
}
项目:androidPN-client.    文件:ReportedData.java   
/**
 * 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;
}
项目:androidPN-client.    文件:ConfigEventProvider.java   
@Override
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends PacketExtension> content)
{
    if (content.size() == 0)
        return new ConfigurationEvent(attMap.get("node"));
    else
        return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next()));
}
项目:androidPN-client.    文件:SessionID.java   
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
    String sessionID = parser.getAttributeValue("", "id");

    // Advance to end of extension.
    parser.next();

    return new SessionID(sessionID);
}
项目:androidPN-client.    文件:CapsExtensionProvider.java   
public PacketExtension parseExtension(XmlPullParser parser) throws XmlPullParserException, IOException,
        XMPPException {
    String hash = null;
    String version = null;
    String node = null;
    if (parser.getEventType() == XmlPullParser.START_TAG
            && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT)) {
        hash = parser.getAttributeValue(null, "hash");
        version = parser.getAttributeValue(null, "ver");
        node = parser.getAttributeValue(null, "node");
    } else {
        throw new XMPPException("Malformed Caps element");
    }

    parser.next();

    if (!(parser.getEventType() == XmlPullParser.END_TAG
            && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT))) {
        throw new XMPPException("Malformed nested Caps element");
    }

    if (hash != null && version != null && node != null) {
        return new CapsExtension(node, version, hash);
    } else {
        throw new XMPPException("Caps elment with missing attributes");
    }
}