提交 a7315add 编写于 作者: M mduigou

Merge

......@@ -49,7 +49,7 @@ import javax.security.auth.x500.X500Principal;
/**
* PolicyTool may be used by users and administrators to configure the
* overall java security policy (currently stored in the policy file).
* Using PolicyTool administators may add and remove policies from
* Using PolicyTool administrators may add and remove policies from
* the policy file. <p>
*
* @see java.security.Policy
......@@ -1343,11 +1343,6 @@ class ToolDialog extends Dialog {
PolicyTool.rb.getString
("Actions.");
/* gridbag index for display OverWriteFile (OW) components */
public static final int OW_LABEL = 0;
public static final int OW_OK_BUTTON = 1;
public static final int OW_CANCEL_BUTTON = 2;
/* gridbag index for display PolicyEntry (PE) components */
public static final int PE_CODEBASE_LABEL = 0;
public static final int PE_CODEBASE_TEXTFIELD = 1;
......@@ -1522,44 +1517,6 @@ class ToolDialog extends Dialog {
return null;
}
/**
* ask user if they want to overwrite an existing file
*/
void displayOverWriteFileDialog(String filename, int nextEvent) {
// find where the PolicyTool gui is
Point location = tw.getLocationOnScreen();
setBounds(location.x + 75, location.y + 100, 400, 150);
setLayout(new GridBagLayout());
// ask the user if they want to over write the existing file
MessageFormat form = new MessageFormat(PolicyTool.rb.getString
("OK.to.overwrite.existing.file.filename."));
Object[] source = {filename};
Label label = new Label(form.format(source));
tw.addNewComponent(this, label, OW_LABEL,
0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
tw.TOP_PADDING);
// OK button
Button button = new Button(PolicyTool.rb.getString("OK"));
button.addActionListener(new OverWriteFileOKButtonListener
(tool, tw, this, filename, nextEvent));
tw.addNewComponent(this, button, OW_OK_BUTTON,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
tw.TOP_PADDING);
// Cancel button
// -- if the user hits cancel, do NOT go on to the next event
button = new Button(PolicyTool.rb.getString("Cancel"));
button.addActionListener(new CancelButtonListener(this));
tw.addNewComponent(this, button, OW_CANCEL_BUTTON,
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
tw.TOP_PADDING);
setVisible(true);
}
/**
* pop up a dialog so the user can enter info to add a new PolicyEntry
* - if edit is TRUE, then the user is editing an existing entry
......@@ -2339,47 +2296,39 @@ class ToolDialog extends Dialog {
return;
// get the entered filename
String filename = new String(fd.getDirectory() + fd.getFile());
File saveAsFile = new File(fd.getDirectory(), fd.getFile());
String filename = saveAsFile.getPath();
fd.dispose();
// see if the file already exists
File saveAsFile = new File(filename);
if (saveAsFile.exists()) {
// display a dialog box for the user to enter policy info
ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Overwrite.File"), tool, tw, true);
td.displayOverWriteFileDialog(filename, nextEvent);
} else {
try {
// save the policy entries to a file
tool.savePolicy(filename);
try {
// save the policy entries to a file
tool.savePolicy(filename);
// display status
MessageFormat form = new MessageFormat(PolicyTool.rb.getString
("Policy.successfully.written.to.filename"));
Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source));
// display status
MessageFormat form = new MessageFormat(PolicyTool.rb.getString
("Policy.successfully.written.to.filename"));
Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source));
// display the new policy filename
TextField newFilename = (TextField)tw.getComponent
(tw.MW_FILENAME_TEXTFIELD);
newFilename.setText(filename);
tw.setVisible(true);
// display the new policy filename
TextField newFilename = (TextField)tw.getComponent
(tw.MW_FILENAME_TEXTFIELD);
newFilename.setText(filename);
tw.setVisible(true);
// now continue with the originally requested command
// (QUIT, NEW, or OPEN)
userSaveContinue(tool, tw, this, nextEvent);
// now continue with the originally requested command
// (QUIT, NEW, or OPEN)
userSaveContinue(tool, tw, this, nextEvent);
} catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.rb.getString("null.filename")));
} else {
tw.displayErrorDialog(null, fnfe);
}
} catch (Exception ee) {
tw.displayErrorDialog(null, ee);
} catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.rb.getString("null.filename")));
} else {
tw.displayErrorDialog(null, fnfe);
}
} catch (Exception ee) {
tw.displayErrorDialog(null, ee);
}
}
......@@ -2494,7 +2443,7 @@ class ToolDialog extends Dialog {
return;
// get the entered filename
String policyFile = new String(fd.getDirectory() + fd.getFile());
String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath();
try {
// open the policy file
......@@ -2861,67 +2810,6 @@ class MainWindowListener implements ActionListener {
}
}
/**
* Event handler for OverWriteFileOKButton button
*/
class OverWriteFileOKButtonListener implements ActionListener {
private PolicyTool tool;
private ToolWindow tw;
private ToolDialog td;
private String filename;
private int nextEvent;
OverWriteFileOKButtonListener(PolicyTool tool, ToolWindow tw,
ToolDialog td, String filename, int nextEvent) {
this.tool = tool;
this.tw = tw;
this.td = td;
this.filename = filename;
this.nextEvent = nextEvent;
}
public void actionPerformed(ActionEvent e) {
try {
// save the policy entries to a file
tool.savePolicy(filename);
// display status
MessageFormat form = new MessageFormat
(PolicyTool.rb.getString
("Policy.successfully.written.to.filename"));
Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source));
// display the new policy filename
TextField newFilename = (TextField)tw.getComponent
(tw.MW_FILENAME_TEXTFIELD);
newFilename.setText(filename);
tw.setVisible(true);
// now continue with the originally requested command
// (QUIT, NEW, or OPEN)
td.setVisible(false);
td.dispose();
td.userSaveContinue(tool, tw, td, nextEvent);
} catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.rb.getString("null.filename")));
} else {
tw.displayErrorDialog(null, fnfe);
}
td.setVisible(false);
td.dispose();
} catch (Exception ee) {
tw.displayErrorDialog(null, ee);
td.setVisible(false);
td.dispose();
}
}
}
/**
* Event handler for AddEntryDoneButton button
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册