当前位置: 首页>>代码示例>>Java>>正文


Java PacketParserUtils.parseMessage方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.util.PacketParserUtils.parseMessage方法的典型用法代码示例。如果您正苦于以下问题:Java PacketParserUtils.parseMessage方法的具体用法?Java PacketParserUtils.parseMessage怎么用?Java PacketParserUtils.parseMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.util.PacketParserUtils的用法示例。


在下文中一共展示了PacketParserUtils.parseMessage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeUnparsedInput

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void consumeUnparsedInput() throws Exception {
    final String MESSAGE_EXCEPTION_ELEMENT = 
                    "<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
                        "<nothingInHere>" +
                        "</nothingInHere>" +
                    "</" + ThrowException.ELEMENT + ">";
    XmlPullParser parser = TestUtils.getMessageParser(
            "<message from='[email protected]' to='[email protected]' id='foo'>" +
                MESSAGE_EXCEPTION_ELEMENT +
                EXTENSION2 +
            "</message>");
    int parserDepth = parser.getDepth();
    CharSequence content = null;
    try {
        PacketParserUtils.parseMessage(parser);
    } catch (Exception e) {
        content = PacketParserUtils.parseContentDepth(parser, parserDepth, false);
    }
    assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:22,代码来源:ParsingExceptionTest.java

示例2: parseBasicItem

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void parseBasicItem() throws Exception
{
       XmlPullParser parser = PacketParserUtils.getParserFor(
           "<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
               "<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
                   "<items node='testNode'>" +
                       "<item id='testid1' />" +
                   "</items>" + 
                "</event>" + 
           "</message>");
       
       Stanza message = PacketParserUtils.parseMessage(parser);
       ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
       
       assertTrue(eventExt instanceof EventElement);
       EventElement event = (EventElement) eventExt;
       assertEquals(EventElementType.items, event.getEventType());
       assertEquals(1, event.getExtensions().size());
       assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
       assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size());
       
       ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
       assertTrue(itemExt instanceof Item);
       assertEquals("testid1", ((Item)itemExt).getId());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:27,代码来源:ItemValidationTest.java

示例3: headersInMessageTest

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void headersInMessageTest() throws Exception {
    // @formatter:off
    final String messageStanza = 
      "<message from='[email protected]/orchard' to='[email protected]' type='chat'>" +
        "<body>Wherefore are thou?!?</body>" + 
        "<headers xmlns='http://jabber.org/protocol/shim'>" +
         "<header name='Urgency'>high</header>" +
        "</headers>" +
      "</message>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getMessageParser(messageStanza);
    Message message = PacketParserUtils.parseMessage(parser);
    HeadersExtension headers = HeadersExtension.from(message);
    Header header = headers.getHeaders().get(0);
    assertEquals("Urgency", header.getName());
    assertEquals("high", header.getValue());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:19,代码来源:HeadersProviderTest.java

示例4: receiptTest

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void receiptTest() throws Exception {
    XmlPullParser parser;
    String control;
    
    control = XMLBuilder.create("message")
        .a("from", "[email protected]")
        .e("request")
            .a("xmlns", "urn:xmpp:receipts")
        .asString(outputProperties);
    
    parser = PacketParserUtils.getParserFor(control);
    Message p = PacketParserUtils.parseMessage(parser);

    DeliveryReceiptRequest drr = (DeliveryReceiptRequest)p.getExtension(
                    DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE);
    assertNotNull(drr);

    assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));

    Message m = new Message("[email protected]", Message.Type.normal);
    assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
    DeliveryReceiptRequest.addTo(m);
    assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:26,代码来源:DeliveryReceiptTest.java

示例5: parse

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    DelayInformation di = null;
    Stanza packet = null;

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            String namespace = parser.getNamespace();
            switch (name) {
            case DelayInformation.ELEMENT:
                if (DelayInformation.NAMESPACE.equals(namespace)) {
                    di = DelayInformationProvider.INSTANCE.parse(parser, parser.getDepth());
                } else {
                    LOGGER.warning("Namespace '" + namespace + "' does not match expected namespace '"
                                    + DelayInformation.NAMESPACE + "'");
                }
                break;
            case Message.ELEMENT:
                packet = PacketParserUtils.parseMessage(parser);
                break;
            default:
                LOGGER.warning("Unsupported forwarded packet type: " + name);
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }

    if (packet == null)
        throw new SmackException("forwarded extension must contain a packet");
    return new Forwarded(di, packet);
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:40,代码来源:ForwardedProvider.java

示例6: parseSimplePayloadItem

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void parseSimplePayloadItem() throws Exception
{
    String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
    
    XmlPullParser parser = PacketParserUtils.getParserFor(
        "<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
            "<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
                "<items node='testNode'>" +
                    "<item id='testid1' >" +
                        itemContent +
                    "</item>" + 
                "</items>" + 
             "</event>" + 
        "</message>");
    
    Stanza message = PacketParserUtils.parseMessage(parser);
    ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
    EventElement event = (EventElement) eventExt;
    ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);

    assertTrue(itemExt instanceof PayloadItem<?>);
    PayloadItem<?> item = (PayloadItem<?>)itemExt;
    
    assertEquals("testid1", item.getId());
    assertTrue(item.getPayload() instanceof SimplePayload);
    
    SimplePayload payload = (SimplePayload) item.getPayload();
    assertEquals("foo", payload.getElementName());
    assertEquals("smack:test", payload.getNamespace());
    assertXMLEqual(itemContent, payload.toXML().toString());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:33,代码来源:ItemValidationTest.java

示例7: parseEmptyTag

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void parseEmptyTag() throws Exception
{
    String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
    
    XmlPullParser parser = PacketParserUtils.getParserFor(
        "<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
            "<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
                "<items node='testNode'>" +
                    "<item id='testid1' >" +
                        itemContent +
                    "</item>" + 
                "</items>" + 
             "</event>" + 
        "</message>");
    
    Stanza message = PacketParserUtils.parseMessage(parser);
    ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
    
    assertTrue(eventExt instanceof EventElement);
    EventElement event = (EventElement) eventExt;
    assertEquals(EventElementType.items, event.getEventType());
    assertEquals(1, event.getExtensions().size());
    assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
    assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size());
    
    ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
    assertTrue(itemExt instanceof PayloadItem<?>);
    PayloadItem<?> item = (PayloadItem<?>)itemExt;
    
    assertEquals("testid1", item.getId());
    assertTrue(item.getPayload() instanceof SimplePayload);
    
    assertXMLEqual(itemContent, ((SimplePayload)item.getPayload()).toXML().toString());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:36,代码来源:ItemValidationTest.java

示例8: parseMessageStanza

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
/** Parses a &lt;xmpp&gt;-wrapped message stanza. */
public static Message parseMessageStanza(String data) throws Exception {

    XmlPullParser parser = getPullParser(data);
    boolean done = false, in_xmpp = false;
    Message msg = null;

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

        if (eventType == XmlPullParser.START_TAG) {

            if ("xmpp".equals(parser.getName()))
                in_xmpp = true;

            else if ("message".equals(parser.getName()) && in_xmpp) {
                msg = PacketParserUtils.parseMessage(parser);
            }
        }

        else if (eventType == XmlPullParser.END_TAG) {

            if ("xmpp".equals(parser.getName()))
                done = true;
        }
    }

    return msg;
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:30,代码来源:XMPPUtils.java

示例9: parseMessageStanza

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
/** Parses a &lt;xmpp&gt;-wrapped message stanza. */
public static Message parseMessageStanza(String data) throws Exception {

    XmlPullParser parser = getPullParser(data);
    boolean done = false, in_xmpp = false;
    Message msg = null;

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

        if (eventType == XmlPullParser.START_TAG) {

            if ("xmpp".equals(parser.getName()))
                in_xmpp = true;

            else if ("message".equals(parser.getName()) && in_xmpp) {
                msg = (Message) PacketParserUtils.parseMessage(parser);
            }
        }

        else if (eventType == XmlPullParser.END_TAG) {

            if ("xmpp".equals(parser.getName()))
                done = true;
        }
    }

    return msg;
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:30,代码来源:XMPPUtils.java

示例10: parseComplexItem

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void parseComplexItem() throws Exception
{
    String itemContent = 
            "<entry xmlns='http://www.w3.org/2005/Atom'>" +
                "<title>Soliloquy</title>" +
                "<summary>" +
                    "To be, or not to be: that is the question:" +
                    "Whether 'tis nobler in the mind to suffer" +
                    "The slings and arrows of outrageous fortune," +
                    "Or to take arms against a sea of troubles," +
                    "And by opposing end them?" +
                "</summary>" +
                "<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" +
                "<id>tag:denmark.lit,2003:entry-32397</id>" +
                "<published>2003-12-13T18:30:02Z</published>" +
                "<updated>2003-12-13T18:30:02Z</updated>" +
            "</entry>";
    
    XmlPullParser parser = PacketParserUtils.getParserFor(
        "<message from='pubsub.myserver.com' to='[email protected]' id='foo'>" +
            "<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
                "<items node='testNode'>" +
                    "<item id='testid1' >" +
                        itemContent +
                    "</item>" + 
                "</items>" + 
             "</event>" + 
        "</message>");
    
    Stanza message = PacketParserUtils.parseMessage(parser);
    ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
    EventElement event = (EventElement) eventExt;
    ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);

    assertTrue(itemExt instanceof PayloadItem<?>);
    PayloadItem<?> item = (PayloadItem<?>)itemExt;
    
    assertEquals("testid1", item.getId());
    assertTrue(item.getPayload() instanceof SimplePayload);
    
    SimplePayload payload = (SimplePayload) item.getPayload();
    assertEquals("entry", payload.getElementName());
    assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
    assertXMLEqual(itemContent, payload.toXML().toString());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:47,代码来源:ItemValidationTest.java


注:本文中的org.jivesoftware.smack.util.PacketParserUtils.parseMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。