📄 accredittable.java
字号:
// usr group
NodeList userGroups = dom.getElementsByTagName("userGroup");
Element userGroup = (Element) userGroups.item(0);
userGroup.getFirstChild().setNodeValue((String) user.elementAt(USER_GROUP));
// call return
NodeList callReturns = dom.getElementsByTagName("callReturn");
Element callReturn = (Element) callReturns.item(0);
callReturn.setAttribute("enabled",
(String) user.elementAt(UserTableModel.CALL_RETURN_ADMIN_ENABLED));
setfeats = callReturn.getElementsByTagName("setfeat");
setfeat = (Element) setfeats.item(0);
// There is no "user set" gui element for the call return feature since
// this is not something that the user sets for himself. (To keep the xml
// consistent) the user setfeat is set to the same state as the admin
// enabled field
if (user.elementAt(UserTableModel.CALL_RETURN_ADMIN_ENABLED).equals("true"))
{
setfeat.getFirstChild().setNodeValue("ON");
}
else
{
setfeat.getFirstChild().setNodeValue("OFF");
}
groups = callReturn.getElementsByTagName("featuregroup");
group = (Element) groups.item(0);
group.getFirstChild().setNodeValue((String) user.elementAt(UserTableModel.CALL_RETURN_GROUP));
// set the authentication type
NodeList authTypes = dom.getElementsByTagName("authenticationType");
Element authType = (Element) authTypes.item(0);
authType.setAttribute("value",
(String) user.elementAt(UserTableModel.AUTHENTICATION_TYPE));
NodeList authPasswords =
dom.getElementsByTagName("authenticationPassword");
Element authPassword = (Element) authPasswords.item(0);
authPassword.setAttribute("value",
(String) user.elementAt(UserTableModel.AUTHENTICATION_PASSWORD));
// set the static registration
NodeList statRegs = dom.getElementsByTagName("staticRegistration");
Element statReg = (Element) statRegs.item(0);
statReg.setAttribute("value",
(String) user.elementAt(UserTableModel.STATIC_REGISTRATION_ENABLED));
Element oldTerminatingContacts =
(Element) statReg.getElementsByTagName("terminatingContactList").item(0);
Element terminatingContacts = dom.createElement("terminatingContactList");
statReg.replaceChild(terminatingContacts, oldTerminatingContacts);
statReg.appendChild(terminatingContacts);
Element contact = dom.createElement("contact");
contact.setAttribute("value",
(String) user.elementAt(UserTableModel.MARSHAL));
terminatingContacts.appendChild(contact);
contact = dom.createElement("contact");
String contactStr = user.elementAt(UserTableModel.TERMINATING_HOST) + ":"
+ user.elementAt(UserTableModel.TERMINATING_PORT);
contact.setAttribute("value", contactStr);
terminatingContacts.appendChild(contact);
// set the password element
NodeList passwords = dom.getElementsByTagName("password");
if (passwords != null)
{
if (passwords.getLength() > 0)
{
Node password = passwords.item(0);
if (password.hasChildNodes())
{
password.getFirstChild().setNodeValue((String) user.elementAt(UserTableModel.PASSWORD));
}
}
else
{
if (!user.elementAt(UserTableModel.PASSWORD).equals("not loaded from xml"))
{
try
{
Element password = dom.createElement("password");
Text passwordText = dom.createTextNode(
(String) user.elementAt(UserTableModel.PASSWORD));
password.appendChild(passwordText);
dom.appendChild(password);
}
catch(DOMException e)
{
e.printStackTrace();
return null;
}
}
}
}
else
{
if (!user.elementAt(UserTableModel.PASSWORD).equals("not loaded from xml"))
{
Element password = dom.createElement("password");
Text passwordText = dom.createTextNode(
(String) user.elementAt(UserTableModel.PASSWORD));
password.appendChild(passwordText);
dom.appendChild(password);
}
}
// create/set the alias list
// create a new "aliases" element
Element newAliases = dom.createElement("aliases");
// replace the existing "aliases" element with
// the one just created above, or if it does not exist, insert it into the
// dom
NodeList aliasesList = dom.getElementsByTagName("aliases");
if (aliasesList != null)
{
if (aliasesList.getLength() > 0)
{
Element aliases = (Element) aliasesList.item(0);
// an "aliases" element existed -> replace it
dom.getDocumentElement().replaceChild(newAliases, aliases);
}
else // the "aliases" element did not exist...
{
if (!user.elementAt(ALIASES).equals("not loaded from xml"))
{
// add it to the document
dom.getDocumentElement().appendChild(newAliases);
}
}
}
else // the "aliases" element was null
{
if (!user.elementAt(ALIASES).equals("not loaded from xml"))
{
// add it to the document
dom.appendChild(newAliases);
}
}
// create a new "alias" element for each alias
String aliasString = (String) user.elementAt(ALIASES);
while (aliasString.length() > 0)
{
String alias = aliasString.substring(0, aliasString.indexOf(";"));
aliasString = aliasString.substring(aliasString.indexOf(";") + 1);
Element element = dom.createElement("alias");
element.setAttribute("value", alias);
newAliases.appendChild(element);
}
Element clblNode = (Element) dom.getElementsByTagName("clbl").item(0);
Element csNode = (Element) dom.getElementsByTagName("cs").item(0);
Element fnabNode = (Element) dom.getElementsByTagName("fnab").item(0);
Element cfaNode = (Element) dom.getElementsByTagName("cfa").item(0);
NodeList clblPrefixNodes = clblNode.getElementsByTagName("prefix");
if (clblPrefixNodes.getLength() > 0)
{
Element clblPrefixNode = (Element)clblPrefixNodes.item(0);
if (clblPrefixNode.hasChildNodes())
{
clblPrefixNode.getFirstChild().setNodeValue((String)user.elementAt(UserTableModel.CALL_BLOCK_PREFIX));
}
else
{
Node value = dom.createTextNode((String)user.elementAt(UserTableModel.CALL_BLOCK_PREFIX));
clblPrefixNode.appendChild(value);
clblNode.appendChild(clblPrefixNode);
}
}
else
{
Element clblPrefixNode = dom.createElement("prefix");
Node value = dom.createTextNode((String)user.elementAt(UserTableModel.CALL_BLOCK_PREFIX));
clblPrefixNode.appendChild(value);
clblNode.appendChild(clblPrefixNode);
}
try
{
Element block900Node = XMLUtils.getChildByName(clblNode,
"nineHundredBlocked");
block900Node.setAttribute("adminSet",
(String) user.elementAt(UserTableModel.BLOCK_900_ADMIN_ENABLED));
block900Node.setAttribute("userSet",
(String) user.elementAt(UserTableModel.BLOCK_900_USER_SET));
Element blockLongDist = XMLUtils.getChildByName(clblNode,
"longDistanceBlocked");
blockLongDist.setAttribute("adminSet",
(String) user.elementAt(UserTableModel.BLOCK_LONG_DISTANCE_ADMIN_ENABLED));
blockLongDist.setAttribute("userSet",
(String) user.elementAt(UserTableModel.BLOCK_LONG_DISTANCE_USER_SET));
// set the userset field of the clbl feature based on the values of userSet
// for block900 and blockLongDist
// if either nineHundredBlocked or LongDistanceBlocked are set true by the
// user, or the admin the setfeat should be ON. Otherwise, it should be OFF
if (user.elementAt(BLOCK_900_USER_SET).equals("true")
|| user.elementAt(BLOCK_LONG_DISTANCE_USER_SET).equals("true")
|| user.elementAt(BLOCK_900_ADMIN_ENABLED).equals("true")
|| user.elementAt(BLOCK_LONG_DISTANCE_ADMIN_ENABLED).equals("true"))
{
clblNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("ON");
}
else
{
clblNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("OFF");
}
// Set feature groups for all features
XMLUtils.getChildByName(clblNode,
"featuregroup").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.CALL_BLOCK_GROUP));
XMLUtils.getChildByName(csNode,
"featuregroup").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.CALL_SCREEN_GROUP));
XMLUtils.getChildByName(cfaNode,
"featuregroup").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_ALL_GROUP));
XMLUtils.getChildByName(fnabNode,
"featuregroup").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_BUSY_GROUP));
XMLUtils.getChildByName(cfaNode,
"setfeat").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_ALL_USER_SET));
// set forward to field for call forward busy
Element cfbNode = XMLUtils.getChildByName(fnabNode, "cfb");
XMLUtils.getChildByName(cfbNode,
"forwardto").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_BUSY_DESTINATION));
cfbNode.setAttribute("set",
(String) user.elementAt(UserTableModel.FORWARD_BUSY_USER_SET));
// set forward to field for forward no answer
Element fnaNode = XMLUtils.getChildByName(fnabNode, "fna");
XMLUtils.getChildByName(fnaNode,
"forwardto").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_UNANSWERED_DESTINATION));
fnaNode.setAttribute("set",
(String) user.elementAt(UserTableModel.FORWARD_UNANSWERED_USER_SET));
// set forward to field for call forward all
XMLUtils.getChildByName(cfaNode,
"forwardto").getChildNodes().item(0).setNodeValue((String) user.elementAt(UserTableModel.FORWARD_ALL_DESTINATION));
// chose the setfeat value for the forward no answer blocking feature based
// on the values of the forward no answer and forward blocking nodes
// if either cfb or fna is enabled, the setfeat is ON. Otherwise, it is OFF
if (user.elementAt(UserTableModel.FORWARD_BUSY_USER_SET).equals("true")
|| user.elementAt(UserTableModel.FORWARD_UNANSWERED_USER_SET).equals("true"))
{
fnabNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("ON");
}
else
{
fnabNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("OFF");
}
}
catch (NoSuchNodeException e)
{
System.out.println("Could not convert user data to a Document because:");
e.printStackTrace();
}
// set whether each feature is enabled
cfaNode.setAttribute("enabled",
(String) user.elementAt(UserTableModel.FORWARD_ALL_ADMIN_ENABLED));
fnabNode.setAttribute("enabled",
(String) user.elementAt(UserTableModel.FORWARD_BUSY_ADMIN_ENABLED));
csNode.setAttribute("enabled",
(String) user.elementAt(UserTableModel.CALL_SCREEN_ADMIN_ENABLED));
clblNode.setAttribute("enabled",
(String) user.elementAt(UserTableModel.CALL_BLOCK_ADMIN_ENABLED));
// save the data about who to screen calls from
// deleting the "screenfrom" child nodes does not seem to work, so instead
// create a whole new node so it has not "screenfrom" children and then use
// it to replace the original csNode.
Element newCsNode = dom.createElement("cs");
newCsNode.setAttribute("enabled", csNode.getAttribute("enabled"));
newCsNode.appendChild(csNode.getElementsByTagName("setfeat").item(0));
newCsNode.appendChild(csNode.getElementsByTagName("featuregroup").item(0));
dom.getDocumentElement().replaceChild(newCsNode, csNode);
csNode = newCsNode;
// get the list of numbers to screen
String screenFrom =
(String) user.elementAt(UserTableModel.CALL_SCREEN_NUMBERS);
if (user.elementAt(CALL_SCREEN_ADMIN_ENABLED).equals("true"))
{
// if the administrator has enabled this feature, then
// if the list contains some numbers, that means that the user has enabled
// that feature
if (screenFrom.length() > 0)
{
csNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("ON");
}
else
{
csNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("OFF");
}
}
else
{
// if the administrator set the feature to disabled, set the feature off for
// the user even if there are some numbers to screen on the list
csNode.getElementsByTagName("setfeat").item(0).getFirstChild().setNodeValue("OFF");
}
// for each entry in the call screen list, create a new element named "screenfrom",
// create and attribute named "name" and another attribute named "number" then
// add the new node as a child of the csNode
while (screenFrom.length() > 0)
{
String name = screenFrom.substring(0, screenFrom.indexOf(","));
String number = screenFrom.substring(screenFrom.indexOf(",") + 1,
screenFrom.indexOf(";"));
screenFrom = screenFrom.substring(screenFrom.indexOf(";") + 1);
Element element = dom.createElement("screenfrom");
element.setAttribute("name", name);
element.setAttribute("number", number);
csNode.appendChild(element);
}
return dom;
}
private static Vector setFeatureGroup(Vector data, int dataId,
Element parent)
{
NodeList nodeList = parent.getElementsByTagName("featuregroup");
if (nodeList.getLength() > 0)
{
Node node = nodeList.item(0);
if (node.hasChildNodes())
{
data.set(dataId, node.getFirstChild().getNodeValue());
}
}
return data;
}
private static Vector setSetfeat(Vector data, int dataId, Element parent)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -