Mercurial > hg > release > icedtea-web-1.6
changeset 1248:bf0ba14741fb
Add -defaultfile switch to PolicyEditor
* netx/net/sourceforge/jnlp/resources/Messages.properties
(PBODefaultFileFilePathSpecifiedError): new message
* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
(openDefaultButtonAction): refactor to use getDefaultPolicyFilePath
(getDefaultPolicyFilePath): new method
(getFilePathArgument): add -defaultfile switch support
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Tue, 01 Sep 2015 10:15:51 -0400 |
parents | 8da824ac7755 |
children | 0fabdba696d8 |
files | ChangeLog netx/net/sourceforge/jnlp/resources/Messages.properties netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java |
diffstat | 3 files changed, 38 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Sep 01 09:55:42 2015 -0400 +++ b/ChangeLog Tue Sep 01 10:15:51 2015 -0400 @@ -1,3 +1,13 @@ +2015-09-01 Andrew Azores <aazores@redhat.com> + + Add -defaultfile switch to PolicyEditor + * netx/net/sourceforge/jnlp/resources/Messages.properties + (PBODefaultFileFilePathSpecifiedError): new message + * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java + (openDefaultButtonAction): refactor to use getDefaultPolicyFilePath + (getDefaultPolicyFilePath): new method + (getFilePathArgument): add -defaultfile switch support + 2015-09-01 Andrew Azores <aazores@redhat.com> Add texts for PolicyEditor's -defaultfile switch
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Tue Sep 01 09:55:42 2015 -0400 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Tue Sep 01 10:15:51 2015 -0400 @@ -754,6 +754,7 @@ PEClipboardError=Clipboard does not appear to contain properly formatted policy entries PEInvalidPolicy=Paste Failed: Could not read policy entry for codebase {0} from system clipboard PEClipboardAccessError=Could not read from clipboard +PEDefaultFileFilePathSpecifiedError=Either -file (or simply a main argument) or -defaultfile may be specified, but not both PEMainArgAndFileSwitchSpecifiedError=Either -file may be specified or a main argument may be specified, but not both PEHelpMenu=Help
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Tue Sep 01 09:55:42 2015 -0400 +++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Tue Sep 01 10:15:51 2015 -0400 @@ -335,9 +335,18 @@ openDefaultButtonAction = new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { - if (!promptOnSaveChangesMade(true)) return; - PolicyEditor.this.setFile(PathsAndFiles.JAVA_POLICY.getFullPath()); - openAndParsePolicyFile(); + if (!promptOnSaveChangesMade(true)) { + return; + } + try { + PolicyEditor.this.setFile(getDefaultPolicyFilePath()); + PolicyEditor.this.getFile().createNewFile(); + } catch (final IOException ex) { + OutputController.getLogger().log(ex); + } catch (final URISyntaxException ex) { + OutputController.getLogger().log(ex); + } + openAndParsePolicyFile(); } }; @@ -472,6 +481,10 @@ setupLayout(); } + + private static String getDefaultPolicyFilePath() throws URISyntaxException { + return new File(new URI(PathsAndFiles.JAVA_POLICY.getFullPath())).getAbsolutePath(); + } private boolean getModality() { boolean modal = false; @@ -1642,9 +1655,12 @@ } private static String getFilePathArgument(OptionParser optionParser) { + final boolean openDefaultFile = optionParser.hasOption(OptionsDefinitions.OPTIONS.DEFAULTFILE); final boolean hasFileArgument = optionParser.hasOption(OptionsDefinitions.OPTIONS.FILE); final boolean hasMainArgument = optionParser.mainArgExists(); - if (hasFileArgument && hasMainArgument) { + if ((hasFileArgument && openDefaultFile) || (hasMainArgument && openDefaultFile)) { + throw new IllegalArgumentException(R("PEDefaultFileFilePathSpecifiedError")); + } else if (hasFileArgument && hasMainArgument) { throw new IllegalArgumentException(R("PEMainArgAndFileSwitchSpecifiedError")); } @@ -1653,6 +1669,13 @@ filepath = cleanFilePathArgument(optionParser.getParam(OptionsDefinitions.OPTIONS.FILE)); } else if (hasMainArgument) { filepath = cleanFilePathArgument(optionParser.getMainArg()); + } else if (openDefaultFile) { + try { + filepath = getDefaultPolicyFilePath(); + } catch (URISyntaxException e) { + OutputController.getLogger().log(e); + throw new RuntimeException(e); + } } return filepath; }