📄 accreditgroupmodel.java
字号:
/*
* ====================================================================
*
*
* ====================================================================
*
*
*/
package vocal.userEditor;
import vocal.util.Logger;
import vocal.comm.VPPException;
import vocal.comm.VPPNoSuchFileException;
import vocal.data.XMLUtils;
import vocal.data.CplGenerator;
import vocal.data.ContactListGenerator;
import vocal.data.NoSuchNodeException;
import vocal.data.NotTextNodeException;
import javax.swing.table.AbstractTableModel;
import javax.swing.JOptionPane;
import java.util.Vector;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.DOMException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class AccreditGroupModel extends AbstractTableModel {
// NOTE: these have to be in the same order as the columns displayed in the
// table in Editor.java. Also, any data elements that are not displayed in
// that table (such as the list of call screen numbers) must be entered here
// at the end, after those that are in the table.
public static final int GROUP_NAME = 0;
public static final int FORWARD_ALL_ADMIN_ENABLED = 1;
public static final int FORWARD_ALL_GROUP = 2;
public static final int FORWARD_ALL_USER_SET = 3;
public static final int FORWARD_ALL_DESTINATION = 4;
public static final int FORWARD_BUSY_ADMIN_ENABLED = 5;
public static final int FORWARD_BUSY_GROUP = 6;
public static final int FORWARD_BUSY_USER_SET = 7;
public static final int FORWARD_BUSY_DESTINATION = 8;
public static final int FORWARD_UNANSWERED_USER_SET = 9;
public static final int FORWARD_UNANSWERED_DESTINATION = 10;
public static final int FAILURE_CASE = 11;
public static final int CALL_SCREEN_ADMIN_ENABLED = 12;
public static final int CALL_SCREEN_GROUP = 13;
public static final int CALL_BLOCK_PREFIX = 14;
public static final int CALL_BLOCK_ADMIN_ENABLED = 15;
public static final int CALL_BLOCK_GROUP = 16;
public static final int BLOCK_LONG_DISTANCE_ADMIN_ENABLED = 17;
public static final int BLOCK_LONG_DISTANCE_USER_SET = 18;
public static final int BLOCK_900_ADMIN_ENABLED = 19;
public static final int BLOCK_900_USER_SET = 20;
public static final int CALL_RETURN_ADMIN_ENABLED = 21;
public static final int CALL_RETURN_GROUP = 22;
public static final int CALLER_ID_BLOCKING_ADMIN_ENABLED = 23;
public static final int CALLER_ID_BLOCKING_GROUP = 24;
public static final int CALLER_ID_BLOCKING_USER_SET = 25;
public static final int AUTHENTICATION_TYPE = 26;
public static final int AUTHENTICATION_PASSWORD = 27;
public static final int STATIC_REGISTRATION_ENABLED = 28;
public static final int TERMINATING_HOST = 29;
public static final int TERMINATING_PORT = 30;
public static final int PASSWORD = 31;
public static final int CALL_SCREEN_NUMBERS = 32;
public static final int IS_ALIAS = 33;
public static final int MASTER_NAME = 34;
public static final int MASTER_INDEX = 35;
public static final int ALIASES = 36;
public static final int MAX_COLUMN_ID = ALIASES;
// public static final int MAX_COLUMN_ID = USER_IDENTITY;
private static BufferedReader sampleUserXML = new BufferedReader(
new StringReader("<group>"
+ "<groupname>group1</groupname>"
+ "<oisp>"
+ "<failurecase>unknown</failurecase>"
+ "<cfa enabled=\"false\"><setfeat>OFF</setfeat> "
+ "<featuregroup>ForwardAllCallsGroup</featuregroup>"
+ "<forwardto>none</forwardto>"
+ "</cfa>"
+ "<fnab enabled=\"false\"><setfeat>OFF</setfeat>"
+ "<featuregroup>ForwardNoAnswerBusyGroup</featuregroup>"
+ "<fna set=\"false\">"
+ "<forwardto>none</forwardto>"
+ "</fna>"
+ "<cfb set=\"false\">"
+ "<forwardto>none</forwardto>"
+ "</cfb>"
+ "</fnab>"
+ "<cs enabled=\"false\"><setfeat>OFF</setfeat>"
+ "<featuregroup>CallScreeningGroup</featuregroup>"
+ "</cs>"
+ "<clbl enabled=\"false\"><setfeat>OFF</setfeat>"
+ "<prefix></prefix>"
+ "<featuregroup>CallBlockingGroup</featuregroup>"
+ "<nineHundredBlocked adminSet=\"false\" userSet=\"false\"></nineHundredBlocked>"
+ "<longDistanceBlocked adminSet=\"false\" userSet=\"false\"></longDistanceBlocked>"
+ "</clbl>"
+ "<callReturn enabled=\"false\"><setfeat>OFF</setfeat>"
+ "<featuregroup>CallReturnGroup</featuregroup>"
+ "</callReturn>"
+ "<callerIdBlocking enabled=\"false\"><setfeat>OFF</setfeat>"
+ "<featuregroup>CallerIdBlockingGroup</featuregroup>"
+ "</callerIdBlocking>"
+ "<voicemail enabled =\"false\"><setfeat>OFF</setfeat>"
+ "<featuregroup>VoiceMailGroup</featuregroup>"
+ "</voicemail>" + "<userGroup>none</userGroup>"
+ "</oisp>"
+ "<dvr host=\"000.000.000.000\" port=\"8001\"><hostname value=\"none\"></hostname>"
+ "<group value=\"DvrGroup\"></group>"
+ "<Camera1 Name=\"Camera1\" Control=\"false\" History=\"false\"></Camera1>"
+ "<Camera2 Name=\"Camera2\" Control=\"false\" History=\"false\"></Camera2>"
+ "<Camera3 Name=\"Camera3\" Control=\"false\" History=\"false\"></Camera3>"
+ "<Camera4 Name=\"Camera4\" Control=\"false\" History=\"false\"></Camera4>"
+ "<Camera5 Name=\"Camera5\" Control=\"false\" History=\"false\"></Camera5>"
+ "<Camera6 Name=\"Camera6\" Control=\"false\" History=\"false\"></Camera6>"
+ "<Camera7 Name=\"Camera7\" Control=\"false\" History=\"false\"></Camera7>"
+ "<Camera8 Name=\"Camera8\" Control=\"false\" History=\"false\"></Camera8>"
+ "</dvr>"
+ "</group>"));
private static Document dom;
private static Vector dummyGroup;
private boolean isShowingAliases = false;
private boolean aliasesLoadedFromServer = false;
private Vector userColumnIndices = new Vector();
private Vector adminColumnIndices = new Vector();
private static ColumnInfo[] columns = new ColumnInfo[] {
new ColumnInfo("GroupName", 150, GROUP_NAME),
new ColumnInfo("Forward All Enabled", 150,
FORWARD_ALL_ADMIN_ENABLED),
new ColumnInfo("Forward All Group", 150, FORWARD_ALL_GROUP),
new ColumnInfo("Forward All Set", 150, FORWARD_ALL_USER_SET),
new ColumnInfo("Forward All To", 150, FORWARD_ALL_DESTINATION),
new ColumnInfo("Forward Busy/No Ans Enabled", 150,
FORWARD_BUSY_ADMIN_ENABLED),
new ColumnInfo("Forward Busy/No Ans Group", 150, FORWARD_BUSY_GROUP),
new ColumnInfo("Forward Busy Set", 150, FORWARD_BUSY_USER_SET),
new ColumnInfo("Forward Busy To", 150, FORWARD_BUSY_DESTINATION),
new ColumnInfo("Forward No Ans Set", 150,
FORWARD_UNANSWERED_USER_SET),
new ColumnInfo("Forward No Ans To", 150,
FORWARD_UNANSWERED_DESTINATION),
new ColumnInfo("Failure Case", 150, FAILURE_CASE),
new ColumnInfo("Call Screen Enabled", 150,
CALL_SCREEN_ADMIN_ENABLED),
new ColumnInfo("Call Screen Group", 150, CALL_SCREEN_GROUP),
new ColumnInfo("Call Block Prefix", 150, CALL_BLOCK_PREFIX),
new ColumnInfo("Call Block Enabled", 150, CALL_BLOCK_ADMIN_ENABLED),
new ColumnInfo("Call Block Group", 150, CALL_BLOCK_GROUP),
new ColumnInfo("Long Distance Admin Block", 150,
BLOCK_LONG_DISTANCE_ADMIN_ENABLED),
new ColumnInfo("Long Distance User Block", 150,
BLOCK_LONG_DISTANCE_USER_SET),
new ColumnInfo("900 # Admin Block", 150, BLOCK_900_ADMIN_ENABLED),
new ColumnInfo("900 # User Block", 150, BLOCK_900_USER_SET),
new ColumnInfo("Call Return Enabled", 150,
CALL_RETURN_ADMIN_ENABLED),
new ColumnInfo("Call Return Group", 150, CALL_RETURN_GROUP),
new ColumnInfo("Caller ID Block Enabled", 150,
CALLER_ID_BLOCKING_ADMIN_ENABLED),
new ColumnInfo("Caller ID Group", 150, CALLER_ID_BLOCKING_GROUP),
new ColumnInfo("Caller ID Set", 150, CALLER_ID_BLOCKING_USER_SET)};
/**
* Stores the list of users (as a vector of vectors)
*/
private Vector data = new Vector();
/**
* Stores the list of aliases (as a vector of vectors). The each alias would
* be stored in a vector of the same form as the master user names.
*/
private Vector aliases = new Vector();
/**
* Handles communication with pServer
*/
PServerAccrInterface psInterface;
/**
* Used to find paths and generate cpl files
*/
private CplGenerator cplGen;
static {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = null;
try {
parser = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null,
"Could not configure XML parser", "ERROR",
JOptionPane.ERROR_MESSAGE);
}
try {
dom = parser.parse(new InputSource(sampleUserXML));
} catch (Exception e) {
// If this happens, there was an error parsing the hard coded sample
// user
// XML. That should never happen. It would suggest a coding error.
e.printStackTrace();
JOptionPane.showMessageDialog(null,
"Could not parse sample user XML", "ERROR",
JOptionPane.ERROR_MESSAGE);
}
}
public AccreditGroupModel(PServerAccrInterface con) {
psInterface = con;
dummyGroup = convertGroupToVector(dom);
userColumnIndices.add(new Integer(FORWARD_ALL_USER_SET));
userColumnIndices.add(new Integer(FORWARD_ALL_DESTINATION));
userColumnIndices.add(new Integer(FORWARD_BUSY_USER_SET));
userColumnIndices.add(new Integer(FORWARD_BUSY_DESTINATION));
userColumnIndices.add(new Integer(FORWARD_UNANSWERED_USER_SET));
userColumnIndices.add(new Integer(FORWARD_UNANSWERED_DESTINATION));
userColumnIndices.add(new Integer(BLOCK_LONG_DISTANCE_USER_SET));
userColumnIndices.add(new Integer(BLOCK_900_USER_SET));
userColumnIndices.add(new Integer(CALLER_ID_BLOCKING_USER_SET));
adminColumnIndices.add(new Integer(FORWARD_ALL_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(FORWARD_ALL_GROUP));
adminColumnIndices.add(new Integer(FORWARD_BUSY_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(FORWARD_BUSY_GROUP));
adminColumnIndices.add(new Integer(FAILURE_CASE));
adminColumnIndices.add(new Integer(CALL_SCREEN_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(CALL_SCREEN_GROUP));
adminColumnIndices.add(new Integer(CALL_BLOCK_PREFIX));
adminColumnIndices.add(new Integer(CALL_BLOCK_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(CALL_BLOCK_GROUP));
adminColumnIndices.add(new Integer(BLOCK_LONG_DISTANCE_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(BLOCK_900_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(CALL_RETURN_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(CALL_RETURN_GROUP));
adminColumnIndices.add(new Integer(CALLER_ID_BLOCKING_ADMIN_ENABLED));
adminColumnIndices.add(new Integer(CALLER_ID_BLOCKING_GROUP));
}
public Vector getUserColumnIndices() {
return userColumnIndices;
}
public Vector getAdminColumnIndices() {
return adminColumnIndices;
}
public void addGroup(Vector user) {
data.addElement(user);
}
public void addGroup(Document doc) {
Vector user = convertGroupToVector(doc);
data.addElement(user);
}
private Document convertUserAtToDocument(int row) {
return convertUserToDocument(getGroupAt(row));
}
public static Document convertUserToDocument(Vector user) {
dom.getElementsByTagName("groupname").item(0).getFirstChild().setNodeValue(
(String) user.elementAt(AccreditGroupModel.GROUP_NAME));
/*
dom.getElementsByTagName("ipaddr").item(0).getFirstChild()
.setNodeValue((String) user.elementAt(AccreditGroupModel.IP));
dom.getElementsByTagName("identity").item(0).getFirstChild()
.setNodeValue(
(String) user.elementAt(AccreditGroupModel.USER_IDENTITY));
dom.getElementsByTagName("userpassword").item(0).getFirstChild()
.setNodeValue(
(String) user.elementAt(AccreditGroupModel.USER_PASSWD));
dom.getElementsByTagName("marshalgroup").item(0).getFirstChild()
.setNodeValue((String) user.elementAt(AccreditGroupModel.MARSHAL));
*/
dom.getElementsByTagName("failurecase").item(0).getFirstChild()
.setNodeValue(
(String) user.elementAt(AccreditGroupModel.FAILURE_CASE));
// caller id blocking
NodeList idBlockings = dom.getElementsByTagName("callerIdBlocking");
Element idBlocking = (Element) idBlockings.item(0);
idBlocking.setAttribute("enabled", (String) user
.elementAt(CALLER_ID_BLOCKING_ADMIN_ENABLED));
NodeList setfeats = idBlocking.getElementsByTagName("setfeat");
Element setfeat = (Element) setfeats.item(0);
setfeat.getFirstChild().setNodeValue(
(String) user.elementAt(CALLER_ID_BLOCKING_USER_SET));
NodeList groups = idBlocking.getElementsByTagName("featuregroup");
Element group = (Element) groups.item(0);
group.getFirstChild().setNodeValue(
(String) user.elementAt(CALLER_ID_BLOCKING_GROUP));
// call return
NodeList callReturns = dom.getElementsByTagName("callReturn");
Element callReturn = (Element) callReturns.item(0);
callReturn.setAttribute("enabled", (String) user
.elementAt(AccreditGroupModel.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(AccreditGroupModel.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(AccreditGroupModel.CALL_RETURN_GROUP));
/*
// set the authentication type
NodeList authTypes = dom.getElementsByTagName("authenticationType");
Element authType = (Element) authTypes.item(0);
authType.setAttribute("value", (String) user
.elementAt(AccreditGroupModel.AUTHENTICATION_TYPE));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -