1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 13:07:59 +01:00

SMACK-288 - Parser is now advanced correctly to the end tag when parsing multiple items.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11574 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2010-01-29 13:50:23 +00:00
parent 5718a52133
commit e600fb02f5
3 changed files with 22 additions and 19 deletions

View file

@ -51,24 +51,19 @@ public class ItemProvider implements PacketExtensionProvider
if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null) if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null)
{ {
boolean done = false; boolean done = false;
String payloadText = null; StringBuilder payloadText = new StringBuilder();
while (!done) while (!done)
{ {
if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem)) if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem))
{
done = true; done = true;
}
else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag())) else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag()))
{ payloadText.append(parser.getText());
if (payloadText == null)
payloadText = parser.getText(); if (!done)
else tag = parser.next();
payloadText += parser.getText();
}
tag = parser.next();
} }
return new PayloadItem<SimplePayload>(id, new SimplePayload(payloadElemName, payloadNS, payloadText)); return new PayloadItem<SimplePayload>(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
} }
else else
{ {

View file

@ -7,11 +7,9 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.FormField; import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
@ -180,12 +178,20 @@ public class SubscriberUseCases extends SingleUserTestCase
} }
payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>"))); payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>")));
payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\"/up/here\"/>"))); payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\'/up/here\'/>")));
payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner></inner></entity>"))); payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner>a</inner></entity>")));
payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text></text></inner></entity>"))); payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>")));
Collection<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems(); List<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems();
assertTrue(payloadItems.size() == 4); assertTrue(payloadItems.size() == 4);
assertEquals(payloadItems.get(0).getId(), "6-" + curTime);
assertEquals("<a xmlns='pubsub:test'/>", payloadItems.get(0).getPayload().toXML().replace('\"', '\''));
assertEquals(payloadItems.get(1).getId(), "7-" + curTime);
assertEquals("<a xmlns='pubsub:test' href=\'/up/here\'/>", payloadItems.get(1).getPayload().toXML().replace('\"', '\''));
assertEquals(payloadItems.get(2).getId(), "8-" + curTime);
assertEquals("<entity xmlns='pubsub:test'>text<inner>a</inner></entity>", payloadItems.get(2).getPayload().toXML().replace('\"', '\''));
assertEquals(payloadItems.get(3).getId(), "9-" + curTime);
assertEquals("<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>", payloadItems.get(3).getPayload().toXML().replace('\"', '\''));
} }
public void testGetSpecifiedItems() throws XMPPException public void testGetSpecifiedItems() throws XMPPException
@ -210,7 +216,7 @@ public class SubscriberUseCases extends SingleUserTestCase
assertEquals(items.get(1).getId(), "3"); assertEquals(items.get(1).getId(), "3");
assertEquals("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML().replace('\"', '\'')); assertEquals("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML().replace('\"', '\''));
assertEquals(items.get(2).getId(), "4"); assertEquals(items.get(2).getId(), "4");
assertEquals("<a xmlns='pubsub:test' href='4'/>", items.get(3).getPayload().toXML().replace('\"', '\'')); assertEquals("<a xmlns='pubsub:test' href='4'/>", items.get(2).getPayload().toXML().replace('\"', '\''));
} }
public void testGetLastNItems() throws XMPPException public void testGetLastNItems() throws XMPPException

View file

@ -199,6 +199,7 @@ public class TestEvents extends SmackTestCase
* <className>org.jivesoftware.smackx.pubsub.CarExtensionProvider</className> * <className>org.jivesoftware.smackx.pubsub.CarExtensionProvider</className>
* </extensionProvider> * </extensionProvider>
*/ */
/*
public void testSendAndReceiveCarPayload() throws Exception public void testSendAndReceiveCarPayload() throws Exception
{ {
// Setup event source // Setup event source
@ -231,7 +232,8 @@ public class TestEvents extends SmackTestCase
assertEquals("green", car.getColor()); assertEquals("green", car.getColor());
assertEquals(4, car.getNumTires()); assertEquals(4, car.getNumTires());
} }
*/
public void testSendAndReceiveMultipleSubs() throws Exception public void testSendAndReceiveMultipleSubs() throws Exception
{ {
// Setup event source // Setup event source