📄 ldapconfiguration.java
字号:
xmlED.addItem(child, (Element)getParentNode());
}
/**
* Deletes the Currently Selected node from the NodeList.
*/
public void deleteItem()
{
if (this.getSelectedNode() != null)
{
xmlED.deleteItem((Element)this.getSelectedNode(), ((Element)getParentNode()));
//Set the TextFields to an empty value
clearTextFields();
}
}
/**
* Method that resets all the Textfields to empty or a predefined value.
*/
public void clearTextFields()
{
nameTextField.setText("");
hostTextField.setText("");
portTextField.setText("389");
baseDNTextField.setText("");
usernameTextField.setText("");
passwordTextField.setText("");
acTypeTextField.setText("");
anonCheckBox.setSelected(false);
}
/**
* Method that replaces a Selected Node with the contents of the textfields,
* Provided that the required fields to have a valid LDAP Directory are not
* empty.
*/
public void replaceItem()
{
if (this.getSelectedNode() != null)
{
if (!nameTextField.getText().equals("") && !hostTextField.getText().equals("")
&& !portTextField.getText().equals(""))
{
//Setting the New Attributes to Replace --
String attribs[] = { "Name", "Host", "Version", "Login", "Password", "Port", "BaseDN", "ACType" };
String username;
String password;
if(anonCheckBox.isSelected())
{
password = "";
username = "";
}
else
{
password = new String(passwordTextField.getPassword());
username = usernameTextField.getText();
}
String values[] = { nameTextField.getText(), hostTextField.getText(), (String)versionComboBox.getSelectedItem(),
username, password, portTextField.getText(), baseDNTextField.getText(), acTypeTextField.getText() };
Element child = xmlED.DOM.createElement("LDAPDirectory");
child.setAttribute("Name", nameTextField.getText());
if (isInPolicy(child) && !((Element)this.getSelectedNode()).getAttribute("Name").equals(nameTextField.getText()))
{
JOptionPane.showMessageDialog(xmlED, ldapConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
xmlED.setAttributeValue((Element)this.getSelectedNode(), attribs, values);
//----------------------------------------
}
else
{
JOptionPane.showMessageDialog(xmlED, ldapConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
}
}
/**
* Method That Populates the NodeList with the current Connections.
*/
public void refreshView()
{
if (xmlED == null || xmlED.DOM == null) return;
if (getParentNode() != null)
{
NodeList nlist = ((Element)getParentNode()).getElementsByTagName("LDAPDirectory");
Node n;
String ldapSpec[] = new String[nlist.getLength()];
for (int i = 0 ; i < nlist.getLength(); i++)
{
n = nlist.item(i);
ldapSpec[i] = (((Element)n).getAttribute("Name"));
}
setNodeList(nlist, ldapSpec);
}
}
/**
* When the NodeItemList has a selected Element, the contents of that node,
* will populate the textfields, so the user will see exactly what is
* is the LDAP connection.
* <p>
* Users might then want to modify the Selected node, and therefore the
* refreshed textfields, would just need to be modified.
* <p>
* If nothing is selected in the NodeItemList, the textfields are reset
* using the clearTextFields() method.
*/
public void itemSelected()
{
Element selectedNode;
super.itemSelected();
testConnButton.setEnabled(true);
addButton.setEnabled(false);
replaceButton.setEnabled(false);
if (getSelectedNode() == null)
{
usernameTextField.setEnabled(true);
passwordTextField.setEnabled(true);
testConnButton.setEnabled(false);
clearTextFields();
return;
}
else
{
testConnButton.setEnabled(true);
selectedNode = (Element)getSelectedNode();
nameTextField.setText(selectedNode.getAttribute("Name"));
hostTextField.setText(selectedNode.getAttribute("Host"));
portTextField.setText(selectedNode.getAttribute("Port"));
versionComboBox.setSelectedItem(selectedNode.getAttribute("Version"));
if (selectedNode.getAttribute("BaseDN")!=null || !selectedNode.getAttribute("BaseDN").equals("")) baseDNTextField.setText(selectedNode.getAttribute("BaseDN"));
if (selectedNode.getAttribute("Login")!=null || !selectedNode.getAttribute("Login").equals("")) usernameTextField.setText(selectedNode.getAttribute("Login"));
if (selectedNode.getAttribute("Password")!=null || !selectedNode.getAttribute("Password").equals("")) passwordTextField.setText(selectedNode.getAttribute("Password"));
if (selectedNode.getAttribute("ACType")!=null || !selectedNode.getAttribute("ACType").equals("")) acTypeTextField.setText(selectedNode.getAttribute("ACType"));
if (selectedNode.getAttribute("Password").equals("") && selectedNode.getAttribute("Login").equals(""))
{
anonCheckBox.setSelected(true);
passwordTextField.setEnabled(false);
usernameTextField.setEnabled(false);
}
else
{
anonCheckBox.setSelected(false);
passwordTextField.setEnabled(true);
usernameTextField.setEnabled(true);
}
}
}
/**
* The root node of the Current Document.
*
* @return a node with the LDAPConfiguration Element of the 'pe.cfg' XML file.
*/
public Node getParentNode()
{
return xmlED.DOM.getElementsByTagName("LDAPConfiguration").item(0);
}
public void keyTyped(KeyEvent e)
{
}
/**
* Method That enables/disables the appropriate buttons when the Text Fields
* are being typed into.
*/
public void keyPressed(KeyEvent e)
{
if (e.getSource() == hostTextField || e.getSource() == nameTextField ||
e.getSource() == usernameTextField || e.getSource() == passwordTextField ||
e.getSource() == baseDNTextField || e.getSource() == portTextField ||
e.getSource() == acTypeTextField)
{
if (this.listBox.getSelectedValue() == null)
{
addButton.setEnabled(true);
testConnButton.setEnabled(false);
}
else
{
replaceButton.setEnabled(true);
addButton.setEnabled(true);
testConnButton.setEnabled(false);
}
}
}
public void keyReleased(KeyEvent e)
{
}
/**
* Method that Performs the required Actions when the Checkbox is
* set/cleared, and when the test Connection Button is clicked.
*/
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == anonCheckBox)
{
if (((JCheckBox)e.getSource()).isSelected())
{
usernameTextField.setEnabled(false);
passwordTextField.setEnabled(false);
}
else
{
usernameTextField.setEnabled(true);
passwordTextField.setEnabled(true);
}
addButton.setEnabled(true);
replaceButton.setEnabled(true);
}
else if (e.getSource() == testConnButton)
{
Element selectedNode = (Element)getSelectedNode();
String name = selectedNode.getAttribute("Name");
try
{
String host = selectedNode.getAttribute("Host");
String port = selectedNode.getAttribute("Port");
String baseDN = selectedNode.getAttribute("BaseDN");
testLdap.setRoot("ldap://" + host + ":" + port + "/" + baseDN);
JOptionPane.showMessageDialog(xmlED, ldapConfigSuccess1 + " " + name, infoHeader, JOptionPane.INFORMATION_MESSAGE);
}
catch(NamingException ne)
{
JOptionPane.showMessageDialog(xmlED, ldapConfigError3 + " " + name + " " + ldapConfigError4, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
}
else super.actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -