1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 10:49:41 +02:00

SMACK-534 Refactored all System.out/err and printStackTrace calls with appropriate Java util logging calls.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_4_0@13887 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2014-02-02 22:39:07 +00:00
parent 9bb940da4b
commit 1b651d4939
30 changed files with 189 additions and 183 deletions

View file

@ -25,6 +25,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Connection;
@ -42,7 +44,8 @@ import org.jivesoftware.smackx.packet.MessageEvent;
* @author Gaston Dombiak
*/
public class MessageEventManager {
private static Logger log = Logger.getLogger(MessageEventManager.class.getName());
private List<MessageEventNotificationListener> messageEventNotificationListeners = new ArrayList<MessageEventNotificationListener>();
private List<MessageEventRequestListener> messageEventRequestListeners = new ArrayList<MessageEventRequestListener>();
@ -157,12 +160,8 @@ public class MessageEventManager {
for (int i = 0; i < listeners.length; i++) {
method.invoke(listeners[i], new Object[] { from, packetID, this });
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
log.log(Level.SEVERE, "Error while invoking MessageEventRequestListener", e);
}
}
@ -188,12 +187,8 @@ public class MessageEventManager {
for (int i = 0; i < listeners.length; i++) {
method.invoke(listeners[i], new Object[] { from, packetID });
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
log.log(Level.SEVERE, "Error while invoking MessageEventNotificationListener", e);
}
}

View file

@ -33,6 +33,8 @@ import org.jivesoftware.smackx.packet.MultipleAddresses;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A MultipleRecipientManager allows to send packets to multiple recipients by making use of
@ -42,7 +44,8 @@ import java.util.List;
* @author Gaston Dombiak
*/
public class MultipleRecipientManager {
private static Logger log = Logger.getLogger(MultipleRecipientManager.class.getName());
/**
* Create a cache to hold the 100 most recently accessed elements for a period of
* 24 hours.
@ -309,13 +312,12 @@ public class MultipleRecipientManager {
break;
}
}
}
// Cache the discovered information
services.put(serviceName, serviceAddress == null ? "" : serviceAddress);
}
catch (XMPPException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error occurred retrieving multiple recipients service", e);
}
}
}

View file

@ -28,6 +28,8 @@ import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.XHTMLExtension;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Manages XHTML formatted texts within messages. A XHTMLManager provides a high level access to
@ -38,6 +40,8 @@ import java.util.Iterator;
*/
public class XHTMLManager {
private static Logger log = Logger.getLogger(XHTMLManager.class.getName());
private final static String namespace = "http://jabber.org/protocol/xhtml-im";
// Enable the XHTML support on every established connection
@ -137,7 +141,7 @@ public class XHTMLManager {
return result.containsFeature(namespace);
}
catch (XMPPException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error checking if service is available", e);
return false;
}
}

View file

@ -29,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
@ -67,7 +69,8 @@ import org.jivesoftware.smack.XMPPException;
* @author Henning Staib
*/
public class Socks5Proxy {
private static Logger log = Logger.getLogger(Socks5Proxy.class.getName());
/* SOCKS5 proxy singleton */
private static Socks5Proxy socks5Server;
@ -150,8 +153,7 @@ public class Socks5Proxy {
}
catch (IOException e) {
// couldn't setup server
System.err.println("couldn't setup local SOCKS5 proxy on port "
+ SmackConfiguration.getLocalSocks5ProxyPort() + ": " + e.getMessage());
log.log(Level.SEVERE, "couldn't setup local SOCKS5 proxy on port " + SmackConfiguration.getLocalSocks5ProxyPort(), e);
}
}

View file

@ -46,6 +46,7 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
/**
* An AdHocCommandManager is responsible for keeping the list of available
@ -58,7 +59,6 @@ import java.util.concurrent.ConcurrentHashMap;
* @author Gabriel Guardincerri
*/
public class AdHocCommandManager {
private static final String DISCO_NAMESPACE = "http://jabber.org/protocol/commands";
private static final String discoNode = DISCO_NAMESPACE;
@ -470,7 +470,6 @@ public class AdHocCommandManager {
executingCommands.remove(sessionId);
}
respondError(response, error);
e.printStackTrace();
}
}
else {
@ -527,7 +526,7 @@ public class AdHocCommandManager {
}
try {
// TODO: Check that all the requierd fields of the form are
// TODO: Check that all the required fields of the form are
// TODO: filled, if not throw an exception. This will simplify the
// TODO: construction of new commands
@ -585,8 +584,6 @@ public class AdHocCommandManager {
executingCommands.remove(sessionId);
}
respondError(response, error);
e.printStackTrace();
}
}
}
@ -650,12 +647,10 @@ public class AdHocCommandManager {
command.setNode(commandInfo.getNode());
}
catch (InstantiationException e) {
e.printStackTrace();
throw new XMPPException(new XMPPError(
XMPPError.Condition.interna_server_error));
}
catch (IllegalAccessException e) {
e.printStackTrace();
throw new XMPPException(new XMPPError(
XMPPError.Condition.interna_server_error));
}

View file

@ -52,6 +52,8 @@ import java.io.Writer;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* The EnhancedDebugger is a debugger that allows to debug sent, received and interpreted messages
@ -64,6 +66,8 @@ import java.util.Date;
*/
public class EnhancedDebugger implements SmackDebugger {
private static Logger log = Logger.getLogger(EnhancedDebugger.class.getName());
private static final String NEWLINE = "\n";
private static ImageIcon packetReceivedIcon;
@ -427,7 +431,7 @@ public class EnhancedDebugger implements SmackDebugger {
receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
}
catch (BadLocationException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
}
}
receivedText.append(str.substring(0, index + 1));
@ -462,7 +466,7 @@ public class EnhancedDebugger implements SmackDebugger {
sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
}
catch (BadLocationException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
}
}
@ -895,28 +899,10 @@ public class EnhancedDebugger implements SmackDebugger {
}
catch (TransformerConfigurationException tce) {
// Error generated by the parser
System.out.println("\n** Transformer Factory error");
System.out.println(" " + tce.getMessage());
// Use the contained exception, if any
Throwable x = tce;
if (tce.getException() != null)
x = tce.getException();
x.printStackTrace();
log.log(Level.SEVERE, "Transformer Factory error", tce);
}
catch (TransformerException te) {
// Error generated by the parser
System.out.println("\n** Transformation error");
System.out.println(" " + te.getMessage());
// Use the contained exception, if any
Throwable x = te;
if (te.getException() != null)
x = te.getException();
x.printStackTrace();
log.log(Level.SEVERE, "Transformation error", te);
}
return str;
}

View file

@ -24,6 +24,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
@ -40,13 +42,14 @@ import org.xmlpull.v1.XmlPullParserException;
/**
* Simple implementation of an EntityCapsPersistentCache that uses a directory
* to store the Caps information for every known node. Every node is represented
* by an file.
* by a file.
*
* @author Florian Schmaus
*
*/
public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache {
private static Logger log = Logger.getLogger(SimpleDirectoryPersistentCache.class.getName());
private File cacheDir;
private StringEncoder filenameEncoder;
@ -55,7 +58,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
* cacheDir exists and that it's an directory.
* <p>
* Default filename encoder {@link Base32Encoder}, as this will work on all
* filesystems, both case sensitive and case insensitive. It does however
* file systems, both case sensitive and case insensitive. It does however
* produce longer filenames.
*
* @param cacheDir
@ -92,7 +95,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
if (nodeFile.createNewFile())
writeInfoToFile(nodeFile, info);
} catch (IOException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to write disco info to file", e);
}
}
@ -161,7 +164,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(reader);
} catch (XmlPullParserException xppe) {
xppe.printStackTrace();
log.log(Level.SEVERE, "Exception initializing parser", xppe);
return null;
}

View file

@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionCreationListener;
@ -76,7 +78,8 @@ import org.jivesoftware.smackx.packet.MUCUser;
* @author Gaston Dombiak, Larry Kirschner
*/
public class MultiUserChat {
private static Logger log = Logger.getLogger(MultiUserChat.class.getName());
private final static String discoNamespace = "http://jabber.org/protocol/muc";
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
@ -179,7 +182,7 @@ public class MultiUserChat {
return result.containsFeature(discoNamespace);
}
catch (XMPPException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error checking user [" + user + "] for MUC support", e);
return false;
}
}
@ -222,7 +225,7 @@ public class MultiUserChat {
return answer.iterator();
}
catch (XMPPException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error getting joined rooms for user [" + user + "]", e);
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
@ -953,13 +956,12 @@ public class MultiUserChat {
DiscoverInfo.Identity identity = identities.next();
return identity.getName();
}
// If no Identity was found then the user does not have a reserved room nickname
return null;
}
catch (XMPPException e) {
e.printStackTrace();
return null;
log.log(Level.SEVERE, "Error retrieving room nickname", e);
}
// If no Identity was found then the user does not have a reserved room nickname
return null;
}
/**
@ -2061,11 +2063,11 @@ public class MultiUserChat {
method.invoke(listener, params);
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on UserStatusListener", e);
} catch (InvocationTargetException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on UserStatusListener", e);
} catch (IllegalAccessException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on UserStatusListener", e);
}
}
@ -2112,11 +2114,11 @@ public class MultiUserChat {
method.invoke(listener, params.toArray());
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on ParticipantStatusListener", e);
} catch (InvocationTargetException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on ParticipantStatusListener", e);
} catch (IllegalAccessException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to invoke method on ParticipantStatusListener", e);
}
}

View file

@ -27,6 +27,8 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A Time IQ packet, which is used by XMPP clients to exchange their respective local
@ -61,7 +63,8 @@ import java.util.TimeZone;
* @author Matt Tucker
*/
public class Time extends IQ {
private static Logger log = Logger.getLogger(Time.class.getName());
private static SimpleDateFormat utcFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
private static DateFormat displayFormat = DateFormat.getDateTimeInstance();
@ -94,7 +97,7 @@ public class Time extends IQ {
/**
* Returns the local time or <tt>null</tt> if the time hasn't been set.
*
* @return the lcocal time.
* @return the local time.
*/
public Date getTime() {
if (utc == null) {
@ -109,7 +112,7 @@ public class Time extends IQ {
date = cal.getTime();
}
catch (Exception e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error getting local time", e);
}
return date;
}

View file

@ -33,6 +33,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
@ -85,6 +87,8 @@ import org.jivesoftware.smack.util.StringUtils;
* @author Kirill Maximov (kir@maxkir.com)
*/
public class VCard extends IQ {
private static Logger log = Logger.getLogger(VCard.class.getName());
private static final String DEFAULT_MIME_TYPE = "image/jpeg";
/**
@ -332,7 +336,7 @@ public class VCard extends IQ {
bytes = getBytes(avatarURL);
}
catch (IOException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Error getting bytes from URL: " + avatarURL, e);
}
setAvatar(bytes);
@ -489,7 +493,7 @@ public class VCard extends IQ {
digest = MessageDigest.getInstance("SHA-1");
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to get message digest", e);
return null;
}
@ -582,7 +586,7 @@ public class VCard extends IQ {
result = (VCard) packet;
}
catch (ClassCastException e) {
System.out.println("No VCard for " + user);
log.log(Level.SEVERE, "No VCard for " + user, e);
return;
}

View file

@ -21,6 +21,8 @@ package org.jivesoftware.smackx.provider;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
@ -37,7 +39,8 @@ import org.xmlpull.v1.XmlPullParser;
*
*/
public class StreamInitiationProvider implements IQProvider {
private static Logger log = Logger.getLogger(StreamInitiationProvider.class.getName());
public IQ parseIQ(final XmlPullParser parser) throws Exception {
boolean done = false;
@ -90,7 +93,7 @@ public class StreamInitiationProvider implements IQProvider {
fileSize = Long.parseLong(size);
}
catch (NumberFormatException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Failed to parse file size from " + fileSize, e);
}
}

View file

@ -34,6 +34,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* vCard provider.
@ -42,7 +44,8 @@ import java.util.List;
* @author Derek DeMoro
*/
public class VCardProvider implements IQProvider {
private static Logger log = Logger.getLogger(VCardProvider.class.getName());
private static final String PREFERRED_ENCODING = "UTF-8";
public IQ parseIQ(XmlPullParser parser) throws Exception {
@ -71,10 +74,10 @@ public class VCardProvider implements IQProvider {
}
}
catch (XmlPullParserException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Exception parsing VCard", e);
}
catch (IOException e) {
e.printStackTrace();
log.log(Level.SEVERE, "Exception parsing VCard", e);
}
String xmlText = sb.toString();