From 1edc69780b733f23ef3cf9f616b8ccfd1acb69b9 Mon Sep 17 00:00:00 2001 From: Michael Will Date: Thu, 4 Jun 2009 11:58:25 +0000 Subject: [PATCH] more work on generic add ' quoting fix IntegerInstantiation is more memory friendly git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11024 b35dd754-fafc-0310-a699-88a17e54d16e --- .../jivesoftware/smack/util/StringUtils.java | 10 ++++++- .../smackx/debugger/EnhancedDebugger.java | 26 ++++++++++--------- .../filetransfer/FileTransferManager.java | 4 +-- .../filetransfer/FileTransferNegotiator.java | 10 +++---- .../Socks5TransferNegotiator.java | 2 +- .../Socks5TransferNegotiatorManager.java | 12 ++++----- .../smack/util/StringUtilsTest.java | 3 +++ 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/source/org/jivesoftware/smack/util/StringUtils.java b/source/org/jivesoftware/smack/util/StringUtils.java index 0f742e342..628f4b57e 100644 --- a/source/org/jivesoftware/smack/util/StringUtils.java +++ b/source/org/jivesoftware/smack/util/StringUtils.java @@ -31,6 +31,7 @@ import java.util.Random; public class StringUtils { private static final char[] QUOTE_ENCODE = """.toCharArray(); + private static final char[] APOS_ENCODE = "'".toCharArray(); private static final char[] AMP_ENCODE = "&".toCharArray(); private static final char[] LT_ENCODE = "<".toCharArray(); private static final char[] GT_ENCODE = ">".toCharArray(); @@ -326,6 +327,13 @@ public class StringUtils { last = i + 1; out.append(QUOTE_ENCODE); } + else if (ch == '\'') { + if (i > last) { + out.append(input, last, i - last); + } + last = i + 1; + out.append(APOS_ENCODE); + } } if (last == 0) { return string; @@ -501,4 +509,4 @@ public class StringUtils { private StringUtils() { // Not instantiable. } -} \ No newline at end of file +} diff --git a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java index ca2267a69..c6b2d5ca3 100644 --- a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java +++ b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java @@ -253,7 +253,8 @@ public class EnhancedDebugger implements SmackDebugger { new DefaultTableModel( new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, 0) { - public boolean isCellEditable(int rowIndex, int mColIndex) { + private static final long serialVersionUID = 8136121224474217264L; + public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } @@ -645,7 +646,8 @@ public class EnhancedDebugger implements SmackDebugger { new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0}, {"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}}, new Object[]{"Type", "Received", "Sent"}) { - public boolean isCellEditable(int rowIndex, int mColIndex) { + private static final long serialVersionUID = -6793886085109589269L; + public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; @@ -711,20 +713,20 @@ public class EnhancedDebugger implements SmackDebugger { * Updates the statistics table */ private void updateStatistics() { - statisticsTable.setValueAt(new Integer(receivedIQPackets), 0, 1); - statisticsTable.setValueAt(new Integer(sentIQPackets), 0, 2); + statisticsTable.setValueAt(Integer.valueOf(receivedIQPackets), 0, 1); + statisticsTable.setValueAt(Integer.valueOf(sentIQPackets), 0, 2); - statisticsTable.setValueAt(new Integer(receivedMessagePackets), 1, 1); - statisticsTable.setValueAt(new Integer(sentMessagePackets), 1, 2); + statisticsTable.setValueAt(Integer.valueOf(receivedMessagePackets), 1, 1); + statisticsTable.setValueAt(Integer.valueOf(sentMessagePackets), 1, 2); - statisticsTable.setValueAt(new Integer(receivedPresencePackets), 2, 1); - statisticsTable.setValueAt(new Integer(sentPresencePackets), 2, 2); + statisticsTable.setValueAt(Integer.valueOf(receivedPresencePackets), 2, 1); + statisticsTable.setValueAt(Integer.valueOf(sentPresencePackets), 2, 2); - statisticsTable.setValueAt(new Integer(receivedOtherPackets), 3, 1); - statisticsTable.setValueAt(new Integer(sentOtherPackets), 3, 2); + statisticsTable.setValueAt(Integer.valueOf(receivedOtherPackets), 3, 1); + statisticsTable.setValueAt(Integer.valueOf(sentOtherPackets), 3, 2); - statisticsTable.setValueAt(new Integer(receivedPackets), 4, 1); - statisticsTable.setValueAt(new Integer(sentPackets), 4, 2); + statisticsTable.setValueAt(Integer.valueOf(receivedPackets), 4, 1); + statisticsTable.setValueAt(Integer.valueOf(sentPackets), 4, 2); } /** diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java b/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java index ddf30509b..6fbb58b25 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransferManager.java @@ -48,7 +48,7 @@ public class FileTransferManager { private final FileTransferNegotiator fileTransferNegotiator; - private List listeners; + private List listeners; private XMPPConnection connection; @@ -83,7 +83,7 @@ public class FileTransferManager { } private void initListeners() { - listeners = new ArrayList(); + listeners = new ArrayList(); connection.addPacketListener(new PacketListener() { public void processPacket(Packet packet) { diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index 1d2354b8e..5ad3b032f 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -175,7 +175,7 @@ public class FileTransferNegotiator { * * @return Returns a collection of the supported transfer protocols. */ - public static Collection getSupportedProtocols() { + public static Collection getSupportedProtocols() { return Collections.unmodifiableList(Arrays.asList(PROTOCOLS)); } @@ -271,8 +271,8 @@ public class FileTransferNegotiator { private FormField getStreamMethodField(DataForm form) { FormField field = null; - for (Iterator it = form.getFields(); it.hasNext();) { - field = (FormField) it.next(); + for (Iterator it = form.getFields(); it.hasNext();) { + field = it.next(); if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) { break; } @@ -286,8 +286,8 @@ public class FileTransferNegotiator { String variable; boolean isByteStream = false; boolean isIBB = false; - for (Iterator it = field.getOptions(); it.hasNext();) { - variable = ((FormField.Option) it.next()).getValue(); + for (Iterator it = field.getOptions(); it.hasNext();) { + variable = it.next().getValue(); if (variable.equals(BYTE_STREAM) && !IBB_ONLY) { isByteStream = true; } diff --git a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java index 973acbca6..da83ad6c8 100644 --- a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java +++ b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java @@ -179,7 +179,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator { */ private SelectedHostInfo selectHost(Bytestream streamHostsInfo) throws XMPPException { - Iterator it = streamHostsInfo.getStreamHosts().iterator(); + Iterator it = streamHostsInfo.getStreamHosts().iterator(); StreamHost selectedHost = null; Socket socket = null; while (it.hasNext()) { diff --git a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiatorManager.java b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiatorManager.java index 35f2c3509..bc49d59ed 100644 --- a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiatorManager.java +++ b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiatorManager.java @@ -127,9 +127,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa catch (XMPPException e) { return null; } - Iterator itx = info.getIdentities(); + Iterator itx = info.getIdentities(); while (itx.hasNext()) { - DiscoverInfo.Identity identity = (DiscoverInfo.Identity) itx.next(); + DiscoverInfo.Identity identity = itx.next(); if ("proxy".equalsIgnoreCase(identity.getCategory()) && "bytestreams".equalsIgnoreCase( identity.getType())) { @@ -145,9 +145,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa .getInstanceFor(connection); try { DiscoverItems discoItems = manager.discoverItems(connection.getServiceName()); - Iterator it = discoItems.getItems(); + Iterator it = discoItems.getItems(); while (it.hasNext()) { - DiscoverItems.Item item = (DiscoverItems.Item) it.next(); + DiscoverItems.Item item = it.next(); String proxy = checkIsProxy(manager, item); if (proxy != null) { proxies.add(proxy); @@ -167,12 +167,12 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa */ private void initStreamHosts() { List streamHosts = new ArrayList(); - Iterator it = proxies.iterator(); + Iterator it = proxies.iterator(); IQ query; PacketCollector collector; Bytestream response; while (it.hasNext()) { - String jid = it.next().toString(); + String jid = it.next(); query = new IQ() { public String getChildElementXML() { return ""; diff --git a/test/org/jivesoftware/smack/util/StringUtilsTest.java b/test/org/jivesoftware/smack/util/StringUtilsTest.java index b3ac230ea..f849cf81f 100644 --- a/test/org/jivesoftware/smack/util/StringUtilsTest.java +++ b/test/org/jivesoftware/smack/util/StringUtilsTest.java @@ -93,6 +93,9 @@ public class StringUtilsTest extends TestCase { input = "&"; assertEquals("&", StringUtils.escapeForXML(input)); + + input = "It's a good day today"; + assertEquals("It's a good day today", StringUtils.escapeForXML(input)); } public void testHash() {