1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-23 02:58:00 +01:00

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
This commit is contained in:
Michael Will 2009-06-04 11:58:25 +00:00 committed by michael.will
parent 634afb2cad
commit 1edc69780b
7 changed files with 40 additions and 27 deletions

View file

@ -31,6 +31,7 @@ import java.util.Random;
public class StringUtils { public class StringUtils {
private static final char[] QUOTE_ENCODE = """.toCharArray(); 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[] AMP_ENCODE = "&".toCharArray();
private static final char[] LT_ENCODE = "<".toCharArray(); private static final char[] LT_ENCODE = "<".toCharArray();
private static final char[] GT_ENCODE = ">".toCharArray(); private static final char[] GT_ENCODE = ">".toCharArray();
@ -326,6 +327,13 @@ public class StringUtils {
last = i + 1; last = i + 1;
out.append(QUOTE_ENCODE); 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) { if (last == 0) {
return string; return string;

View file

@ -253,6 +253,7 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel( new DefaultTableModel(
new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"},
0) { 0) {
private static final long serialVersionUID = 8136121224474217264L;
public boolean isCellEditable(int rowIndex, int mColIndex) { public boolean isCellEditable(int rowIndex, int mColIndex) {
return false; return false;
} }
@ -645,6 +646,7 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0}, new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0},
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}}, {"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
new Object[]{"Type", "Received", "Sent"}) { new Object[]{"Type", "Received", "Sent"}) {
private static final long serialVersionUID = -6793886085109589269L;
public boolean isCellEditable(int rowIndex, int mColIndex) { public boolean isCellEditable(int rowIndex, int mColIndex) {
return false; return false;
} }
@ -711,20 +713,20 @@ public class EnhancedDebugger implements SmackDebugger {
* Updates the statistics table * Updates the statistics table
*/ */
private void updateStatistics() { private void updateStatistics() {
statisticsTable.setValueAt(new Integer(receivedIQPackets), 0, 1); statisticsTable.setValueAt(Integer.valueOf(receivedIQPackets), 0, 1);
statisticsTable.setValueAt(new Integer(sentIQPackets), 0, 2); statisticsTable.setValueAt(Integer.valueOf(sentIQPackets), 0, 2);
statisticsTable.setValueAt(new Integer(receivedMessagePackets), 1, 1); statisticsTable.setValueAt(Integer.valueOf(receivedMessagePackets), 1, 1);
statisticsTable.setValueAt(new Integer(sentMessagePackets), 1, 2); statisticsTable.setValueAt(Integer.valueOf(sentMessagePackets), 1, 2);
statisticsTable.setValueAt(new Integer(receivedPresencePackets), 2, 1); statisticsTable.setValueAt(Integer.valueOf(receivedPresencePackets), 2, 1);
statisticsTable.setValueAt(new Integer(sentPresencePackets), 2, 2); statisticsTable.setValueAt(Integer.valueOf(sentPresencePackets), 2, 2);
statisticsTable.setValueAt(new Integer(receivedOtherPackets), 3, 1); statisticsTable.setValueAt(Integer.valueOf(receivedOtherPackets), 3, 1);
statisticsTable.setValueAt(new Integer(sentOtherPackets), 3, 2); statisticsTable.setValueAt(Integer.valueOf(sentOtherPackets), 3, 2);
statisticsTable.setValueAt(new Integer(receivedPackets), 4, 1); statisticsTable.setValueAt(Integer.valueOf(receivedPackets), 4, 1);
statisticsTable.setValueAt(new Integer(sentPackets), 4, 2); statisticsTable.setValueAt(Integer.valueOf(sentPackets), 4, 2);
} }
/** /**

View file

@ -48,7 +48,7 @@ public class FileTransferManager {
private final FileTransferNegotiator fileTransferNegotiator; private final FileTransferNegotiator fileTransferNegotiator;
private List listeners; private List<FileTransferListener> listeners;
private XMPPConnection connection; private XMPPConnection connection;
@ -83,7 +83,7 @@ public class FileTransferManager {
} }
private void initListeners() { private void initListeners() {
listeners = new ArrayList(); listeners = new ArrayList<FileTransferListener>();
connection.addPacketListener(new PacketListener() { connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {

View file

@ -175,7 +175,7 @@ public class FileTransferNegotiator {
* *
* @return Returns a collection of the supported transfer protocols. * @return Returns a collection of the supported transfer protocols.
*/ */
public static Collection getSupportedProtocols() { public static Collection<String> getSupportedProtocols() {
return Collections.unmodifiableList(Arrays.asList(PROTOCOLS)); return Collections.unmodifiableList(Arrays.asList(PROTOCOLS));
} }
@ -271,8 +271,8 @@ public class FileTransferNegotiator {
private FormField getStreamMethodField(DataForm form) { private FormField getStreamMethodField(DataForm form) {
FormField field = null; FormField field = null;
for (Iterator it = form.getFields(); it.hasNext();) { for (Iterator<FormField> it = form.getFields(); it.hasNext();) {
field = (FormField) it.next(); field = it.next();
if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) { if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) {
break; break;
} }
@ -286,8 +286,8 @@ public class FileTransferNegotiator {
String variable; String variable;
boolean isByteStream = false; boolean isByteStream = false;
boolean isIBB = false; boolean isIBB = false;
for (Iterator it = field.getOptions(); it.hasNext();) { for (Iterator<FormField.Option> it = field.getOptions(); it.hasNext();) {
variable = ((FormField.Option) it.next()).getValue(); variable = it.next().getValue();
if (variable.equals(BYTE_STREAM) && !IBB_ONLY) { if (variable.equals(BYTE_STREAM) && !IBB_ONLY) {
isByteStream = true; isByteStream = true;
} }

View file

@ -179,7 +179,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
*/ */
private SelectedHostInfo selectHost(Bytestream streamHostsInfo) private SelectedHostInfo selectHost(Bytestream streamHostsInfo)
throws XMPPException { throws XMPPException {
Iterator it = streamHostsInfo.getStreamHosts().iterator(); Iterator<StreamHost> it = streamHostsInfo.getStreamHosts().iterator();
StreamHost selectedHost = null; StreamHost selectedHost = null;
Socket socket = null; Socket socket = null;
while (it.hasNext()) { while (it.hasNext()) {

View file

@ -127,9 +127,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
catch (XMPPException e) { catch (XMPPException e) {
return null; return null;
} }
Iterator itx = info.getIdentities(); Iterator<DiscoverInfo.Identity> itx = info.getIdentities();
while (itx.hasNext()) { while (itx.hasNext()) {
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) itx.next(); DiscoverInfo.Identity identity = itx.next();
if ("proxy".equalsIgnoreCase(identity.getCategory()) if ("proxy".equalsIgnoreCase(identity.getCategory())
&& "bytestreams".equalsIgnoreCase( && "bytestreams".equalsIgnoreCase(
identity.getType())) { identity.getType())) {
@ -145,9 +145,9 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
.getInstanceFor(connection); .getInstanceFor(connection);
try { try {
DiscoverItems discoItems = manager.discoverItems(connection.getServiceName()); DiscoverItems discoItems = manager.discoverItems(connection.getServiceName());
Iterator it = discoItems.getItems(); Iterator<DiscoverItems.Item> it = discoItems.getItems();
while (it.hasNext()) { while (it.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next(); DiscoverItems.Item item = it.next();
String proxy = checkIsProxy(manager, item); String proxy = checkIsProxy(manager, item);
if (proxy != null) { if (proxy != null) {
proxies.add(proxy); proxies.add(proxy);
@ -167,12 +167,12 @@ public class Socks5TransferNegotiatorManager implements FileTransferNegotiatorMa
*/ */
private void initStreamHosts() { private void initStreamHosts() {
List<Bytestream.StreamHost> streamHosts = new ArrayList<Bytestream.StreamHost>(); List<Bytestream.StreamHost> streamHosts = new ArrayList<Bytestream.StreamHost>();
Iterator it = proxies.iterator(); Iterator<String> it = proxies.iterator();
IQ query; IQ query;
PacketCollector collector; PacketCollector collector;
Bytestream response; Bytestream response;
while (it.hasNext()) { while (it.hasNext()) {
String jid = it.next().toString(); String jid = it.next();
query = new IQ() { query = new IQ() {
public String getChildElementXML() { public String getChildElementXML() {
return "<query xmlns=\"http://jabber.org/protocol/bytestreams\"/>"; return "<query xmlns=\"http://jabber.org/protocol/bytestreams\"/>";

View file

@ -93,6 +93,9 @@ public class StringUtilsTest extends TestCase {
input = "&"; input = "&";
assertEquals("&amp;", StringUtils.escapeForXML(input)); assertEquals("&amp;", StringUtils.escapeForXML(input));
input = "It's a good day today";
assertEquals("It&apos;s a good day today", StringUtils.escapeForXML(input));
} }
public void testHash() { public void testHash() {