diff --git a/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index 63b66779b..df0fb7747 100644 --- a/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -62,7 +62,7 @@ public class ConnectionConfiguration implements Cloneable { */ private CallbackHandler callbackHandler; - private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED; + private boolean debuggerEnabled = SmackConfiguration.DEBUG_ENABLED; // Flag that indicates if a reconnection should be attempted when abruptly disconnected private boolean reconnectionAllowed = true; @@ -332,7 +332,7 @@ public class ConnectionConfiguration implements Cloneable { /** * Returns true if the new connection about to be establish is going to be debugged. By - * default the value of {@link XMPPConnection#DEBUG_ENABLED} is used. + * default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used. * * @return true if the new connection about to be establish is going to be debugged. */ @@ -342,7 +342,7 @@ public class ConnectionConfiguration implements Cloneable { /** * Sets if the new connection about to be establish is going to be debugged. By - * default the value of {@link XMPPConnection#DEBUG_ENABLED} is used. + * default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used. * * @param debuggerEnabled if the new connection about to be establish is going to be debugged. */ diff --git a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index 262d8e048..beb14ca51 100644 --- a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -70,11 +70,27 @@ public final class SmackConfiguration { private final static List compressionHandlers = new ArrayList(2); /** - * Loads the configuration from the smack-config.xml file.

- * + * Value that indicates whether debugging is enabled. When enabled, a debug + * window will apear for each new connection that will contain the following + * information:

+ *

+ * Debugging can be enabled by setting this field to true, or by setting the Java system + * property smack.debugEnabled to true. The system property can be set on the + * command line such as "java SomeApp -Dsmack.debugEnabled=true". + */ + public static boolean DEBUG_ENABLED = false; + + /** + * Loads the configuration from the smack-config.xml and system properties file. + *

* So far this means that: * 1) a set of classes will be loaded in order to execute their static init block * 2) retrieve and set the current Smack release + * 3) set DEBUG_ENABLED */ static { String smackVersion; @@ -137,6 +153,15 @@ public final class SmackConfiguration { // Add the Java7 compression handler first, since it's preferred compressionHandlers.add(new Java7ZlibInputOutputStream()); + + // Use try block since we may not have permission to get a system + // property (for example, when an applet). + try { + DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled"); + } + catch (Exception e) { + // Ignore. + } } /** diff --git a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 9b611d80f..83b2e2c8a 100644 --- a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -104,30 +104,7 @@ public abstract class XMPPConnection { private final static Set connectionEstablishedListeners = new CopyOnWriteArraySet(); - /** - * Value that indicates whether debugging is enabled. When enabled, a debug - * window will apear for each new connection that will contain the following - * information:

- *

- * Debugging can be enabled by setting this field to true, or by setting the Java system - * property smack.debugEnabled to true. The system property can be set on the - * command line such as "java SomeApp -Dsmack.debugEnabled=true". - */ - public static boolean DEBUG_ENABLED = false; - static { - // Use try block since we may not have permission to get a system - // property (for example, when an applet). - try { - DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled"); - } - catch (Exception e) { - // Ignore. - } // Ensure the SmackConfiguration class is loaded by calling a method in it. SmackConfiguration.getVersion(); } diff --git a/core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/core/src/test/java/org/jivesoftware/smack/DummyConnection.java index 6eef3cf67..30b546482 100644 --- a/core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -187,7 +187,7 @@ public class DummyConnection extends XMPPConnection { @Override void sendPacketInternal(Packet packet) { - if (DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { System.out.println("[SEND]: " + packet.toXML()); } queue.add(packet); @@ -244,7 +244,7 @@ public class DummyConnection extends XMPPConnection { collector.processPacket(packet); } - if (DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { System.out.println("[RECV]: " + packet.toXML()); } diff --git a/core/src/test/java/org/jivesoftware/smack/RosterTest.java b/core/src/test/java/org/jivesoftware/smack/RosterTest.java index f0b9b383a..27e00253e 100644 --- a/core/src/test/java/org/jivesoftware/smack/RosterTest.java +++ b/core/src/test/java/org/jivesoftware/smack/RosterTest.java @@ -703,7 +703,7 @@ public class RosterTest { public synchronized void entriesAdded(Collection addresses) { addressesAdded.addAll(addresses); - if (XMPPConnection.DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { for (String address : addresses) { System.out.println("Roster entry for " + address + " added."); } @@ -712,7 +712,7 @@ public class RosterTest { public synchronized void entriesDeleted(Collection addresses) { addressesDeleted.addAll(addresses); - if (XMPPConnection.DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { for (String address : addresses) { System.out.println("Roster entry for " + address + " deleted."); } @@ -721,7 +721,7 @@ public class RosterTest { public synchronized void entriesUpdated(Collection addresses) { addressesUpdated.addAll(addresses); - if (XMPPConnection.DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { for (String address : addresses) { System.out.println("Roster entry for " + address + " updated."); } @@ -729,7 +729,7 @@ public class RosterTest { } public void presenceChanged(Presence presence) { - if (XMPPConnection.DEBUG_ENABLED) { + if (SmackConfiguration.DEBUG_ENABLED) { System.out.println("Roster presence changed: " + presence.toXML()); } }