}
/*
* New incoming call
*/
VoiceManager vm = AppContext.getManager(VoiceManager.class);
CallSetup setup = new CallSetup();
setup.incomingCall = true;
setup.cp = new CallParticipant();
setup.cp.setCallId(callId);
setup.cp.setConferenceId(vm.getVoiceManagerParameters().conferenceId);
String callInfo = status.getCallInfo();
/*
* When a call is internal from our PBX caller ID is
*
* <last name>,<first name>@<10 digit phone number>@<gateway IP address>
*
* When we get a call from an outside line, the caller ID is
*
* sip:<10 digit phone number>@<gateway IP address>@<10 digit phone number>@<gateway IP address>
*/
String name;
String phoneNumber;
if (callInfo.startsWith("sip:")) {
callInfo = callInfo.substring(4);
String[] tokens = callInfo.split("@");
name = tokens[0];
phoneNumber = callInfo;
} else {
int ix = callInfo.indexOf("@");
if (ix > 0) {
name = callInfo.substring(0, ix);
String[] tokens = name.split(",");
if (tokens.length == 2) {
name = tokens[1] + " " + tokens[0];
} else {
name = callInfo;
}
phoneNumber = callInfo.substring(ix + 1);
} else {
name = callInfo;
phoneNumber = callInfo;
}
}
setup.cp.setPhoneNumber(phoneNumber);
setup.cp.setName(name);
Call call;
try {
call = vm.createCall(callId, setup);
} catch (IOException e) {
logger.warning("Unable to create call " + callId + ": " + e.getMessage());
return;
}