📄 accreditgroupmodel.java
字号:
NodeList authPasswords = dom
.getElementsByTagName("authenticationPassword");
Element authPassword = (Element) authPasswords.item(0);
authPassword.setAttribute("value", (String) user
.elementAt(AccreditGroupModel.AUTHENTICATION_PASSWORD));
// set the static registration
NodeList statRegs = dom.getElementsByTagName("staticRegistration");
Element statReg = (Element) statRegs.item(0);
statReg.setAttribute("value", (String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.MARSHAL));
terminatingContacts.appendChild(contact);
contact = dom.createElement("contact");
String contactStr = user.elementAt(AccreditGroupModel.TERMINATING_HOST)
+ ":" + user.elementAt(AccreditGroupModel.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(AccreditGroupModel.PASSWORD));
}
} else {
if (!user.elementAt(AccreditGroupModel.PASSWORD).equals(
"not loaded from xml")) {
try {
Element password = dom.createElement("password");
Text passwordText = dom.createTextNode((String) user
.elementAt(AccreditGroupModel.PASSWORD));
password.appendChild(passwordText);
dom.appendChild(password);
} catch (DOMException e) {
e.printStackTrace();
return null;
}
}
}
} else {
if (!user.elementAt(AccreditGroupModel.PASSWORD).equals(
"not loaded from xml")) {
Element password = dom.createElement("password");
Text passwordText = dom.createTextNode((String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.CALL_BLOCK_PREFIX));
} else {
Node value = dom.createTextNode((String) user
.elementAt(AccreditGroupModel.CALL_BLOCK_PREFIX));
clblPrefixNode.appendChild(value);
clblNode.appendChild(clblPrefixNode);
}
} else {
Element clblPrefixNode = dom.createElement("prefix");
Node value = dom.createTextNode((String) user
.elementAt(AccreditGroupModel.CALL_BLOCK_PREFIX));
clblPrefixNode.appendChild(value);
clblNode.appendChild(clblPrefixNode);
}
try {
Element block900Node = XMLUtils.getChildByName(clblNode,
"nineHundredBlocked");
block900Node.setAttribute("adminSet", (String) user
.elementAt(AccreditGroupModel.BLOCK_900_ADMIN_ENABLED));
block900Node.setAttribute("userSet", (String) user
.elementAt(AccreditGroupModel.BLOCK_900_USER_SET));
Element blockLongDist = XMLUtils.getChildByName(clblNode,
"longDistanceBlocked");
blockLongDist
.setAttribute(
"adminSet",
(String) user
.elementAt(AccreditGroupModel.BLOCK_LONG_DISTANCE_ADMIN_ENABLED));
blockLongDist.setAttribute("userSet", (String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.CALL_BLOCK_GROUP));
XMLUtils
.getChildByName(csNode, "featuregroup")
.getChildNodes()
.item(0)
.setNodeValue(
(String) user
.elementAt(AccreditGroupModel.CALL_SCREEN_GROUP));
XMLUtils
.getChildByName(cfaNode, "featuregroup")
.getChildNodes()
.item(0)
.setNodeValue(
(String) user
.elementAt(AccreditGroupModel.FORWARD_ALL_GROUP));
XMLUtils
.getChildByName(fnabNode, "featuregroup")
.getChildNodes()
.item(0)
.setNodeValue(
(String) user
.elementAt(AccreditGroupModel.FORWARD_BUSY_GROUP));
XMLUtils
.getChildByName(cfaNode, "setfeat")
.getChildNodes()
.item(0)
.setNodeValue(
(String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.FORWARD_BUSY_DESTINATION));
cfbNode.setAttribute("set", (String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.FORWARD_UNANSWERED_DESTINATION));
fnaNode.setAttribute("set", (String) user
.elementAt(AccreditGroupModel.FORWARD_UNANSWERED_USER_SET));
// set forward to field for call forward all
XMLUtils.getChildByName(cfaNode, "forwardto").getChildNodes().item(
0).setNodeValue(
(String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.FORWARD_BUSY_USER_SET).equals(
"true")
|| user.elementAt(
AccreditGroupModel.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(AccreditGroupModel.FORWARD_ALL_ADMIN_ENABLED));
fnabNode.setAttribute("enabled", (String) user
.elementAt(AccreditGroupModel.FORWARD_BUSY_ADMIN_ENABLED));
csNode.setAttribute("enabled", (String) user
.elementAt(AccreditGroupModel.CALL_SCREEN_ADMIN_ENABLED));
clblNode.setAttribute("enabled", (String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.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) {
NodeList nodeList = parent.getElementsByTagName("setfeat");
if (nodeList.getLength() > 0) {
Node node = nodeList.item(0);
if (node.hasChildNodes()) {
Node value = node.getFirstChild();
data.set(dataId, value.getNodeValue());
}
}
return data;
}
public static Vector convertGroupToVector(Document group) {
String temp = "not loaded from xml";
// alocate enough space for all data elements
Vector groupData = new Vector(MAX_COLUMN_ID + 6);
for (int i = 0; i <= MAX_COLUMN_ID; i++) {
groupData.addElement(temp);
}
// group name
NodeList elements = group.getElementsByTagName("groupname");
if (elements.getLength() > 0) {
Element element = (Element) elements.item(0);
if (element.hasChildNodes()) {
groupData.set(GROUP_NAME, element.getFirstChild().getNodeValue());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -