pwizardpanel4b.java
来自「一个完整的XACML工程,学习XACML技术的好例子!」· Java 代码 · 共 631 行 · 第 1/2 页
JAVA
631 行
}
public void itemStateChanged(ItemEvent e)
{
if (urlRbutton.isSelected()) {
urlTextField.setEnabled(true);
urlTextField.grabFocus();
shibTextField.setEnabled(false);
shibTextField.setText("");
ldapTextField.setEnabled(false);
ldapTextField.setText("");
LDAP_Component.setEnabled(false);
} else if (ldapRButton.isSelected()) {
urlTextField.setEnabled(false);
urlTextField.setText("");
shibTextField.setEnabled(false);
shibTextField.setText("");
ldapTextField.setEnabled(true);
ldapTextField.grabFocus();
LDAP_Component.setEnabled(true);
} else if (shibRButton.isSelected()) {
urlTextField.setEnabled(false);
urlTextField.setText("");
shibTextField.setEnabled(true);
shibTextField.grabFocus();
ldapTextField.setEnabled(false);
ldapTextField.setText("");
LDAP_Component.setEnabled(false);
}
checkAddButton();
}
public void doubleclick(LDAP_DIT ldap)
{
}
public void select(LDAP_DIT ldap)
{
try
{
if (urlRbutton.isSelected()) return;
String ldapdn = ldap.getSelectedNode().getNameInNamespace();
ldapTextField.setText(ldapdn);
ldapTextField.grabFocus();
checkAddButton();
if (getSelectedIndex()>-1)
replaceButton.setEnabled(true);
}
catch(NamingException ne)
{
}
}
public void unselect(LDAP_DIT ldap)
{
}
public void communicationError(Throwable tce)
{
}
public void deleteItem()
{
if (this.getSelectedNode() != null)
{
PWizard.finishWizard.policyDocument.deleteItem((Element)this.getSelectedNode(), ((Element)getParentNode()));
nameTextField.setText("");
urlTextField.setText("");
ldapTextField.setText("");
shibTextField.setText("");
refreshView();
}
}
public void replaceItem()
{
if (this.getSelectedNode() != null)
{
if (!nameTextField.getText().equals(""))
{
if (urlRbutton.isSelected() && !urlTextField.getText().equals("")) {
String attrib[] = { "ID", "URL" };
String newID = nameTextField.getText();
try {
String urlpath = urlTextField.getText();
URLPrincipal urlprin = new URLPrincipal(urlpath);
} catch (BadURLException burl) {
JOptionPane.showMessageDialog(this, errorMSGInvalidURL, errorHeader, JOptionPane.ERROR_MESSAGE);
urlTextField.grabFocus();
return;
}
String value[] = { newID, urlTextField.getText() };
String oldID = ((Element)getSelectedNode()).getAttribute("ID");
xmlED.setAttributeValue((Element)getSelectedNode(), attrib, value);
} else if (ldapRButton.isSelected() && !ldapTextField.getText().equals("")) {
String attrib[] = { "ID", "LDAPDN" };
String newID = nameTextField.getText();
String value[] = { newID, ldapTextField.getText() };
String oldID = ((Element)getSelectedNode()).getAttribute("ID");
xmlED.setAttributeValue((Element)getSelectedNode(), attrib, value);
} else if (shibRButton.isSelected() && !shibTextField.getText().equals("")) {
String attrib[] = { "ID", "URL" };
String newID = nameTextField.getText();
String value[] = { newID, "shib:"+shibTextField.getText() };
String oldID = ((Element)getSelectedNode()).getAttribute("ID");
xmlED.setAttributeValue((Element)getSelectedNode(), attrib, value);
}
else
{
JOptionPane.showMessageDialog(xmlED, errorMSG4, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
}
else
{
JOptionPane.showMessageDialog(xmlED, errorMSG1, errorHeader, JOptionPane.ERROR_MESSAGE);
}
}
refreshView();
}
/**
* Checks if the administrator passed is in the policy or not.
*
* @param name the administrator name to check.
*
* @return true - if the administrator exists already.
* false - if the administrator is not in the policy already.
*/
public boolean adminExists(String name)
{
NodeList nlist = ((Element)getParentNode()).getElementsByTagName("SOASpec");
for (int i=0; i<nlist.getLength() ; i++)
{
Element e = (Element)nlist.item(i);
if (e.getAttribute("ID").equals(name))
return true;
}
return false;
}
/**
* Method that adds an administrator. Performs checks to see that all
* fields are entered.
*/
public void addItem()
{
//check if name exists already in hashtable;
if (adminExists(nameTextField.getText())) {
JOptionPane.showMessageDialog(this, errorMSG1, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
Element child = PWizard.finishWizard.policyDocument.DOM.createElement("SOASpec");
child.setAttribute("ID", nameTextField.getText());
if (urlRbutton.isSelected()) {
try {
URL url = new URL(urlTextField.getText());
} catch (MalformedURLException m) {
JOptionPane.showMessageDialog(this, errorMSG2, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
child.setAttribute("URL", urlTextField.getText());
} else if (ldapRButton.isSelected()) {
try {
LDAPDNPrincipal urlprin = new LDAPDNPrincipal(ldapTextField.getText());
child.setAttribute("LDAPDN", ldapTextField.getText());
} catch (RFC2253ParsingException burl) {
JOptionPane.showMessageDialog(xmlED, errorMSG3, errorHeader, JOptionPane.ERROR_MESSAGE);
ldapTextField.grabFocus();
return;
}
} else if (shibRButton.isSelected()) {
child.setAttribute("URL", "shib:"+shibTextField.getText());
}
PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
refreshView();
refreshFields();
addButton.setEnabled(false);
setSelectedNode(null);
}
/**
* @return The SOAPolicy Tag from the Policy.
*/
public Node getParentNode()
{
return PWizard.finishWizard.policyDocument.DOM.getElementsByTagName("SOAPolicy").item(0);
}
/**
* Called when something is selected from the list of administrators. It
* will refresh the text fields, and populate the right one with the
* selected value.
*/
public void itemSelected()
{
super.itemSelected();
if (getSelectedNode() == null) {
refreshFields();
return;
}
Element name = (Element)getSelectedNode();
nameTextField.setText(name.getAttribute("ID"));
String urlAttrib = name.getAttribute("URL");
String ldapdnAttrib = name.getAttribute("LDAPDN");
int shibIndex = urlAttrib.indexOf("shib:");
if (shibIndex > -1) {
shibRButton.setSelected(true);
urlTextField.setText("");
ldapTextField.setText("");
shibTextField.setText(urlAttrib.substring(shibIndex+5));
} else if (!urlAttrib.equals("")) {
urlRbutton.setSelected(true);
shibTextField.setText("");
ldapTextField.setText("");
urlTextField.setText(name.getAttribute("URL"));
} else if (!ldapdnAttrib.equals("")) {
ldapRButton.setSelected(true);
urlTextField.setText("");
shibTextField.setText("");
ldapTextField.setText(name.getAttribute("LDAPDN"));
}
replaceButton.setEnabled(false);
addButton.setEnabled(false);
}
/**
* Clears all textfields.
*/
public void refreshFields()
{
nameTextField.setText("");
nameTextField.grabFocus();
urlTextField.setText("");
shibTextField.setText("");
ldapTextField.setText("");
}
/**
* Refreshes the View of the list.
*/
public void refreshView()
{
NodeList nlist = ((Element)getParentNode()).getElementsByTagName("SOASpec");
Node n;
String soaSpec[] = new String[nlist.getLength()];
for (int i = 0 ; i < nlist.getLength(); i++)
{
n = nlist.item(i);
soaSpec[i] = (((Element)n).getAttribute("ID") + " (" + ((Element)n).getAttribute("URL") + ((Element)n).getAttribute("LDAPDN") + ")");
}
setNodeList(nlist, soaSpec);
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
checkAddButton();
if (getSelectedIndex()>-1)
replaceButton.setEnabled(true);
}
/**
* Checks whether to light up the Add and Replace Button.
*/
public void checkAddButton()
{
if (urlRbutton.isSelected() &&
!urlTextField.getText().equals("") &&
!nameTextField.getText().equals(""))
{
addButton.setEnabled(true);
} else if (ldapRButton.isSelected() &&
!ldapTextField.getText().equals("") &&
!nameTextField.getText().equals(""))
{
addButton.setEnabled(true);
} else if (shibRButton.isSelected() &&
!shibTextField.getText().equals("") &&
!nameTextField.getText().equals(""))
{
addButton.setEnabled(true);
} else addButton.setEnabled(false);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==nameTextField && !nameTextField.getText().equals("")) {
if (urlRbutton.isSelected()) urlTextField.grabFocus();
else if (shibRButton.isSelected()) shibTextField.grabFocus();
else if (ldapRButton.isSelected()) ldapTextField.grabFocus();
} else if (e.getSource() == urlTextField && !urlTextField.getText().equals("") && !nameTextField.getText().equals("")) {
addItem();
} else if (e.getSource() == shibTextField && !shibTextField.getText().equals("") && !nameTextField.getText().equals("")) {
addItem();
} else if (e.getSource() == ldapTextField && !ldapTextField.getText().equals("") && !nameTextField.getText().equals("")) {
addItem();
}
else super.actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?