📄 accredittable.java
字号:
Element authPassword = (Element) authPasswords.item(0);
String pw = authPassword.getAttribute("value");
userData.set(AUTHENTICATION_PASSWORD, pw);
}
}
// static registration
NodeList staticRegs = group.getElementsByTagName("staticRegistration");
if (staticRegs.getLength() > 0)
{
Element staticReg = (Element) staticRegs.item(0);
String enabled = staticReg.getAttribute("value");
userData.set(STATIC_REGISTRATION_ENABLED, enabled);
NodeList contactLists =
staticReg.getElementsByTagName("terminatingContactList");
if (contactLists.getLength() > 0)
{
Element contactList = (Element) contactLists.item(0);
NodeList contacts = contactList.getElementsByTagName("contact");
// need to find the terminating host/port:
for (int i = 0; i < contacts.getLength(); i++)
{
Element contact = (Element) contacts.item(i);
String contactStr = contact.getAttribute("value");
// hopefully, there is only one of these that specifies a host/port
// combination or this is not going to work
if (contactStr.indexOf(":") != -1)
{
String host = contactStr.substring(0, contactStr.indexOf(":"));
String port = contactStr.substring(contactStr.indexOf(":") + 1);
userData.set(UserTableModel.TERMINATING_HOST, host);
userData.set(UserTableModel.TERMINATING_PORT, port);
}
}
}
}
// call return
NodeList callReturns = group.getElementsByTagName("callReturn");
if (callReturns.getLength() > 0)
{
Element callReturn = (Element) callReturns.item(0);
String enabled = callReturn.getAttribute("enabled");
userData.set(UserTableModel.CALL_RETURN_ADMIN_ENABLED, enabled);
NodeList groups = callReturn.getElementsByTagName("featuregroup");
if (groups.getLength() > 0)
{
Element user = (Element) groups.item(0);
if (group.hasChildNodes())
{
String groupName = group.getFirstChild().getNodeValue();
userData.set(UserTableModel.CALL_RETURN_GROUP, groupName);
}
}
}
// caller id blocking
NodeList idBlockings = group.getElementsByTagName("callerIdBlocking");
if (idBlockings.getLength() > 0)
{
Element idBlocking = (Element) idBlockings.item(0);
String enabled = idBlocking.getAttribute("enabled");
userData.set(UserTableModel.CALLER_ID_BLOCKING_ADMIN_ENABLED, enabled);
NodeList groups = idBlocking.getElementsByTagName("featuregroup");
if (groups.getLength() > 0)
{
Element user = (Element) groups.item(0);
if (group.hasChildNodes())
{
String groupName = group.getFirstChild().getNodeValue();
userData.set(UserTableModel.CALLER_ID_BLOCKING_GROUP, groupName);
}
}
NodeList setFeats = idBlocking.getElementsByTagName("setfeat");
if (setFeats.getLength() > 0)
{
Element setFeat = (Element) setFeats.item(0);
if (setFeat.hasChildNodes())
{
String set = setFeat.getFirstChild().getNodeValue();
userData.set(UserTableModel.CALLER_ID_BLOCKING_USER_SET, set);
}
}
}
return userData;
}
public void loadUserNames() throws VPPNoSuchFileException
{
String[] names = psInterface.getAllUserNames();
data = new Vector(names.length);
Logger.swingLog("Adding users ...");
for (int i = 0; i < names.length; i++)
{
Vector user = new Vector();
user.addElement(names[i]);
data.addElement(user);
if (i % 1000 == 0)
{
Logger.swingLog("Adding user #" + i + " - " + names[i]);
}
}
Logger.swingLog("Done adding users");
fireTableDataChanged();
}
public void deleteUserAt(int row)
throws VPPNoSuchFileException, IOException, SAXException,
NoSuchNodeException, NotTextNodeException, VPPException
{
Vector user = (Vector) data.elementAt(row);
String userName = (String)user.elementAt(this.GROUP_NAME);
if (user.size() <= 1)
{
// if the data for this user was not loaded, need to load it first to
// find out what aliases are defined for this user so the alias xml files
// may be deleted as well
user = loadUserAt(row);
}
boolean deleted;
if (user.elementAt(this.IS_ALIAS).equals("true"))
{
deleted = deleteAlias(user);
}
else
{
deleted = deleteUser(user);
}
// remove the user from the table
if (deleted)
{
//some aliases may have already been removed from the data vector, which
//may cause the position of this user to change -> need to find it again
int index = this.findMasterIndex(userName);
data.removeElementAt(index);
this.fireTableDataChanged();
}
}
private boolean deleteAlias(Vector alias)
throws IOException, SAXException, NotTextNodeException,
NoSuchNodeException, VPPNoSuchFileException, VPPException
{
// find the master user for this alias
String masterIndexString = (String) alias.elementAt(this.MASTER_INDEX);
int masterIndex;
if (masterIndexString != null)
{
masterIndex = Integer.parseInt(masterIndexString);
}
else
{
masterIndex =
findMasterIndex((String) alias.elementAt(this.MASTER_NAME));
alias.setElementAt(masterIndex + "", this.MASTER_INDEX);
}
// This is a bug. If the master index ends up -1, it means that the master
// user's vector could not be found. This situation should never arise if
// if the data is consistent. But since it has come up, this bit of code
// is put in specifically to allow the alias to be deleted even if the master
// user cannot be found.
if (masterIndex == -1)
{
if (JOptionPane.showConfirmDialog(null, "The master user for this alias was not found.\nYour user data is likely corrupted.\n\nDo you still want to delete this alias?", "ERROR", JOptionPane.ERROR_MESSAGE)
== JOptionPane.NO_OPTION)
{
return false;
}
}
else
{
// If the master user was found, modify it to remove the alias
Vector masterUser = (Vector) data.elementAt(masterIndex);
// modify the list of aliases for the master user to remove the alias being
// deleted
// if the user has not been loaded yet, need to do that to access the
// aliases list
if (masterUser.size() <= 1)
{
masterUser = loadUserAt(masterIndex);
}
// get the list of all aliases
String aliasesString = (String) masterUser.elementAt(this.ALIASES);
// remove the selected alias
String newAliases =
removeAliasFromList((String) alias.elementAt(this.GROUP_NAME),
aliasesString);
// save the new list of aliases
masterUser.setElementAt(newAliases, this.ALIASES);
// write back the the user file with the new alias list
writeBackGroupAt(masterIndex, false,
false); // aliases should not affect cpl and cl
}
// always delete the alias from the server, even if the master was not found
// delete the alias file from the server
psInterface.deleteAliasFile((String) alias.elementAt(this.GROUP_NAME));
// now update the vector of all user and all aliases stored in this table
// to not include the deleted alias
aliases.remove(alias);
return true;
}
private boolean deleteUser(Vector user) throws VPPNoSuchFileException
{
// delete the user xml file from the server
psInterface.deleteUser((String) user.elementAt(this.GROUP_NAME));
// now delete all the alias files as well
String aliasStr = (String) user.elementAt(this.ALIASES);
StringTokenizer tokenizer = new StringTokenizer(aliasStr, ";");
String alias;
while (tokenizer.hasMoreTokens())
{
alias = tokenizer.nextToken();
try
{
psInterface.deleteAliasFile(alias);
}
catch (VPPNoSuchFileException ex)
{
// This should never really happen. It means the data on the server is
// corrupted or inconsistent. But just in case it happens ....
ex.printStackTrace();
JOptionPane.showMessageDialog(null,
"The alias " + alias
+ " for this user file does not exist.\n\nYour user data is probably corrupted.",
"ERROR", JOptionPane.ERROR_MESSAGE);
}
// Even if the alias file did not really exist on the server, for some
// strange reason, it may still be in the vector of all aliases.
// It should be removed in that case (and in the regular case).
// delete the alias from the vector of all aliases
for (int i = 0; i < aliases.size(); i++)
{
Vector aliasVector = (Vector) aliases.elementAt(i);
if (aliasVector.elementAt(GROUP_NAME).equals(alias))
{
aliases.remove(aliasVector);
if (data.contains(aliasVector))
{
data.remove(aliasVector);
}
break;
}
}
}
return true;
}
public boolean aliasExists(String alias)
{
try
{
psInterface.getAliasNamed(alias);
}
catch (VPPNoSuchFileException e)
{
return false;
}
return true;
}
public boolean groupExists(String groupName)
{
Document doc;
try
{
doc = psInterface.getGroupNamed(groupName);
}
catch (VPPNoSuchFileException e)
{
return false;
}
catch (IOException e)
{
// the file could not be read but probably does not necessarily mean it
// does not exist. Ummmm ... say it doesn't exist anyway
return false;
}
catch (SAXException e)
{
// the file exists but could not be parsed. If its corrupted, say it
// doesn't exist
return false;
}
catch (VPPException ex)
{
return false;
}
if (doc == null)
{
return false;
}
return true;
}
public static String removeAliasFromList(String alias, String list)
{
int index = list.indexOf(alias); // position where alias starts
if (index != -1)
{
String newList;
newList = list.substring(0, index)
+ list.substring(index + alias.length() + 1);
list = newList;
}
return list;
}
private void removeAliasFromVectors(String alias, int row)
{
String userName = (String) getValueAt(row, GROUP_NAME);
// could not save this alias because it is not uniqe
// remove it from the list of aliases in the vector for this user
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -