| Code with Finding: |
class AsteriskServerImpl {
public int[] getVersion(String file) throws ManagerCommunicationException
{
String fileVersion = null;
String[] parts;
int[] intParts;
initializeIfNeeded();
if (versions == null)
{
Map<String, String> map;
ManagerResponse response;
map = new HashMap<String, String>();
try
{
final String command;
if (eventConnection.getVersion().isAtLeast(AsteriskVersion.ASTERISK_1_6))
{
command = SHOW_VERSION_FILES_1_6_COMMAND;
}
else
{
command = SHOW_VERSION_FILES_COMMAND;
}
response = sendAction(new CommandAction(command));
if (response instanceof CommandResponse)
{
List<String> result;
result = ((CommandResponse) response).getResult();
for (int i = 2; i < result.size(); i++)
{
String line;
Matcher matcher;
line = result.get(i);
matcher = SHOW_VERSION_FILES_PATTERN.matcher(line);
if (matcher.find())
{
String key = matcher.group(1);
String value = matcher.group(2);
map.put(key, value);
}
}
fileVersion = map.get(file);
versions = map;
}
else
{
logger.error("Response to CommandAction(\"" + command + "\") was not a CommandResponse but " + response);
}
}
catch (Exception e)
{
logger.warn("Unable to send '" + SHOW_VERSION_FILES_COMMAND + "' command.", e);
}
}
else
{
synchronized (versions)
{
fileVersion = versions.get(file);
}
}
if (fileVersion == null)
{
return null;
}
parts = fileVersion.split("\\.");
intParts = new int[parts.length];
for (int i = 0; i < parts.length; i++)
{
try
{
intParts[i] = Integer.parseInt(parts[i]);
}
catch (NumberFormatException e)
{
intParts[i] = 0;
}
}
return intParts;
}
}
class AsteriskServerImpl {
public Collection<Voicemailbox> getVoicemailboxes() throws ManagerCommunicationException
{
final Collection<Voicemailbox> voicemailboxes;
ManagerResponse response;
final List<String> result;
initializeIfNeeded();
voicemailboxes = new ArrayList<Voicemailbox>();
if (eventConnection.getVersion().isAtLeast(AsteriskVersion.ASTERISK_1_6))
{
response = sendAction(new CommandAction(SHOW_VOICEMAIL_USERS_1_6_COMMAND));
}
else
{
response = sendAction(new CommandAction(SHOW_VOICEMAIL_USERS_COMMAND));
}
if (!(response instanceof CommandResponse))
{
logger.error("Response to CommandAction(\"" + SHOW_VOICEMAIL_USERS_COMMAND
+ "\") was not a CommandResponse but " + response);
return voicemailboxes;
}
result = ((CommandResponse) response).getResult();
if (result == null || result.size() < 1)
{
return voicemailboxes;
}
// remove headline
result.remove(0);
for (String line : result)
{
final Matcher matcher;
final Voicemailbox voicemailbox;
final String context;
final String mailbox;
final String user;
matcher = SHOW_VOICEMAIL_USERS_PATTERN.matcher(line);
if (!matcher.find())
{
continue;
}
context = matcher.group(1);
mailbox = matcher.group(2);
user = matcher.group(3).trim();
voicemailbox = new Voicemailbox(mailbox, context, user);
voicemailboxes.add(voicemailbox);
}
// get message count for each mailbox
for (Voicemailbox voicemailbox : voicemailboxes)
{
final String fullname;
fullname = voicemailbox.getMailbox() + "@" + voicemailbox.getContext();
response = sendAction(new MailboxCountAction(fullname));
if (response instanceof MailboxCountResponse)
{
MailboxCountResponse mailboxCountResponse;
mailboxCountResponse = (MailboxCountResponse) response;
voicemailbox.setNewMessages(mailboxCountResponse.getNewMessages());
voicemailbox.setOldMessages(mailboxCountResponse.getOldMessages());
}
else
{
logger.error("Response to MailboxCountAction was not a MailboxCountResponse but " + response);
}
}
return voicemailboxes;
}
}
|