To use this class, you simply register your subclasses as extension providers in the + * smack.properties file. Then they will be automatically picked up and used to parse + * any child elements. + * + *
+ * For example, given the following message + * + * <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo> + * <event xmlns='http://jabber.org/protocol/pubsub#event> + * <items node='princely_musings'> + * <item id='asdjkwei3i34234n356'> + * <entry xmlns='http://www.w3.org/2005/Atom'> + * <title>Soliloquy</title> + * <link rel='alternative' type='text/html'/> + * <id>tag:denmark.lit,2003:entry-32397</id> + * </entry> + * </item> + * </items> + * </event> + * </message> + * + * I would have a classes + * {@link ItemsProvider} extends {@link EmbeddedExtensionProvider} + * {@link ItemProvider} extends {@link EmbeddedExtensionProvider} + * and + * AtomProvider extends {@link PacketExtensionProvider} + * + * These classes are then registered in the meta-inf/smack.providers file + * as follows. + * + * <extensionProvider> + * <elementName>items</elementName> + * <namespace>http://jabber.org/protocol/pubsub#event</namespace> + * <className>org.jivesoftware.smackx.provider.ItemsEventProvider</className> + * </extensionProvider> + * <extensionProvider> + * <elementName>item</elementName> + * <namespace>http://jabber.org/protocol/pubsub#event</namespace> + * <className>org.jivesoftware.smackx.provider.ItemProvider</className> + * </extensionProvider> + * + *+ * + * @author Robin Collier + */ +abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider +{ + + final public PacketExtension parseExtension(XmlPullParser parser) throws Exception + { + String namespace = parser.getNamespace(); + String name = parser.getName(); + Map
* Note: This method is only useful when the {@link #sendFile(File, String)} - * method is called, as it is the only method that actualy transmits the + * method is called, as it is the only method that actually transmits the * file. * * @return Returns the amount of bytes that have been sent for the file @@ -410,7 +413,7 @@ public class OutgoingFileTransfer extends FileTransfer { } /** - * A callback class to retrive the status of an outgoing transfer + * A callback class to retrieve the status of an outgoing transfer * negotiation process. * * @author Alexander Wenckus @@ -438,7 +441,7 @@ public class OutgoingFileTransfer extends FileTransfer { /** * Called when an exception occurs during the negotiation progress. * - * @param e the exception that occured. + * @param e the exception that occurred. */ void errorEstablishingStream(Exception e); } diff --git a/source/org/jivesoftware/smackx/muc/RoomInfo.java b/source/org/jivesoftware/smackx/muc/RoomInfo.java index 7a632cfa0..f97f5443e 100644 --- a/source/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/source/org/jivesoftware/smackx/muc/RoomInfo.java @@ -90,10 +90,10 @@ public class RoomInfo { Form form = Form.getFormFrom(info); if (form != null) { FormField descField = form.getField("muc#roominfo_description"); - this.description = descField == null ? "" : descField.getValues().next(); + this.description = ( descField == null || !(descField.getValues().hasNext()) )? "" : descField.getValues().next(); FormField subjField = form.getField("muc#roominfo_subject"); - this.subject = subjField == null ? "" : subjField.getValues().next(); + this.subject = ( subjField == null || !(subjField.getValues().hasNext()) ) ? "" : subjField.getValues().next(); FormField occCountField = form.getField("muc#roominfo_occupants"); this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues() diff --git a/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java b/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java index 87354c963..3d5ceb458 100644 --- a/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java +++ b/source/org/jivesoftware/smackx/provider/EmbeddedExtensionProvider.java @@ -78,6 +78,8 @@ import org.xmlpull.v1.XmlPullParser; * * * @author Robin Collier + * + * @deprecated This has been moved to {@link org.jivesoftware.smack.provider.EmbeddedExtensionProvider} */ abstract public class EmbeddedExtensionProvider implements PacketExtensionProvider { diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java index a420fdff4..632d4410a 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java @@ -40,6 +40,7 @@ public class InBandBytestreamSessionMessageTest { String sessionID = "session_id"; int blockSize = 10; + int dataSize = blockSize/4 * 3; // protocol verifier Protocol protocol; @@ -102,7 +103,7 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); outputStream.write(controlData); @@ -127,7 +128,7 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); for (byte b : controlData) { @@ -154,11 +155,11 @@ public class InBandBytestreamSessionMessageTest { protocol.addResponse(null, incrementingSequence); protocol.addResponse(null, incrementingSequence); - byte[] controlData = new byte[(blockSize * 3) - 2]; + byte[] controlData = new byte[(dataSize * 3) - 2]; OutputStream outputStream = session.getOutputStream(); int off = 0; - for (int i = 1; i <= 7; i++) { + for (int i = 1; off+i <= controlData.length; i++) { outputStream.write(controlData, off, i); off += i; } @@ -175,7 +176,7 @@ public class InBandBytestreamSessionMessageTest { */ @Test public void shouldSendThirtyDataPackets() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -202,7 +203,7 @@ public class InBandBytestreamSessionMessageTest { */ @Test public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -273,7 +274,7 @@ public class InBandBytestreamSessionMessageTest { public void shouldReadAllReceivedData1() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); // get IBB sessions data packet listener @@ -283,8 +284,8 @@ public class InBandBytestreamSessionMessageTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // verify data packet and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + for (int i = 0; i < controlData.length / dataSize; i++) { + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Message dataMessage = new Message(); @@ -292,14 +293,14 @@ public class InBandBytestreamSessionMessageTest { listener.processPacket(dataMessage); } - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; int read = 0; - read = inputStream.read(bytes, 0, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 10, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 20, blockSize); - assertEquals(blockSize, read); + read = inputStream.read(bytes, 0, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize*2, dataSize); + assertEquals(dataSize, read); // verify data for (int i = 0; i < bytes.length; i++) { @@ -319,7 +320,7 @@ public class InBandBytestreamSessionMessageTest { public void shouldReadAllReceivedData2() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); // get IBB sessions data packet listener @@ -329,8 +330,8 @@ public class InBandBytestreamSessionMessageTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // verify data packet and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + for (int i = 0; i < controlData.length / dataSize; i++) { + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Message dataMessage = new Message(); @@ -339,7 +340,7 @@ public class InBandBytestreamSessionMessageTest { } // read data - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) inputStream.read(); } diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java index d2f20e5e9..723572747 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java @@ -40,7 +40,8 @@ public class InBandBytestreamSessionTest { String xmppServer = "xmpp-server"; String sessionID = "session_id"; - int blockSize = 10; + int blockSize = 20; + int dataSize = blockSize/4 * 3; // protocol verifier Protocol protocol; @@ -102,7 +103,7 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); outputStream.write(controlData); @@ -128,7 +129,7 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; OutputStream outputStream = session.getOutputStream(); for (byte b : controlData) { @@ -156,11 +157,11 @@ public class InBandBytestreamSessionTest { protocol.addResponse(resultIQ, incrementingSequence); protocol.addResponse(resultIQ, incrementingSequence); - byte[] controlData = new byte[(blockSize * 3) - 2]; + byte[] controlData = new byte[(dataSize * 3) - 2]; OutputStream outputStream = session.getOutputStream(); int off = 0; - for (int i = 1; i <= 7; i++) { + for (int i = 1; i+off <= controlData.length; i++) { outputStream.write(controlData, off, i); off += i; } @@ -177,7 +178,7 @@ public class InBandBytestreamSessionTest { */ @Test public void shouldSendThirtyDataPackets() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -205,7 +206,7 @@ public class InBandBytestreamSessionTest { */ @Test public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception { - byte[] controlData = new byte[blockSize * 3]; + byte[] controlData = new byte[dataSize * 3]; InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID); @@ -236,7 +237,7 @@ public class InBandBytestreamSessionTest { public void shouldSendDataCorrectly() throws Exception { // create random data Random rand = new Random(); - final byte[] controlData = new byte[256 * blockSize]; + final byte[] controlData = new byte[256 * dataSize]; rand.nextBytes(controlData); // compares the data of each packet with the control data @@ -246,7 +247,7 @@ public class InBandBytestreamSessionTest { byte[] decodedData = request.getDataPacketExtension().getDecodedData(); int seq = (int) request.getDataPacketExtension().getSeq(); for (int i = 0; i < decodedData.length; i++) { - assertEquals(controlData[(seq * blockSize) + i], decodedData[i]); + assertEquals(controlData[(seq * dataSize) + i], decodedData[i]); } } @@ -254,7 +255,7 @@ public class InBandBytestreamSessionTest { // set acknowledgments for the data packets IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); - for (int i = 0; i < controlData.length / blockSize; i++) { + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ, incrementingSequence, dataVerification); } @@ -462,7 +463,7 @@ public class InBandBytestreamSessionTest { public void shouldReadAllReceivedData1() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); @@ -473,24 +474,24 @@ public class InBandBytestreamSessionTest { InputStream inputStream = session.getInputStream(); PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); - // set data packet acknowledgment and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { + // set data packet acknowledgement and notify listener + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ); - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); listener.processPacket(data); } - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; int read = 0; - read = inputStream.read(bytes, 0, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 10, blockSize); - assertEquals(blockSize, read); - read = inputStream.read(bytes, 20, blockSize); - assertEquals(blockSize, read); + read = inputStream.read(bytes, 0, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize, dataSize); + assertEquals(dataSize, read); + read = inputStream.read(bytes, dataSize*2, dataSize); + assertEquals(dataSize, read); // verify data for (int i = 0; i < bytes.length; i++) { @@ -510,7 +511,7 @@ public class InBandBytestreamSessionTest { public void shouldReadAllReceivedData2() throws Exception { // create random data Random rand = new Random(); - byte[] controlData = new byte[3 * blockSize]; + byte[] controlData = new byte[3 * dataSize]; rand.nextBytes(controlData); IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID); @@ -522,9 +523,9 @@ public class InBandBytestreamSessionTest { PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class); // set data packet acknowledgment and notify listener - for (int i = 0; i < controlData.length / blockSize; i++) { + for (int i = 0; i < controlData.length / dataSize; i++) { protocol.addResponse(resultIQ); - String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize, + String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize, false); DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data); Data data = new Data(dpe); @@ -532,7 +533,7 @@ public class InBandBytestreamSessionTest { } // read data - byte[] bytes = new byte[3 * blockSize]; + byte[] bytes = new byte[3 * dataSize]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) inputStream.read(); }