# HG changeset patch # User Andrew Azores # Date 1441116951 14400 # Node ID bf0ba14741fb8a23be4b9374b2a8c25783a62986 # Parent 8da824ac77552f985368494d55523c0d5e59249f 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 diff -r 8da824ac7755 -r bf0ba14741fb ChangeLog --- 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 + + 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 Add texts for PolicyEditor's -defaultfile switch diff -r 8da824ac7755 -r bf0ba14741fb netx/net/sourceforge/jnlp/resources/Messages.properties --- 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 diff -r 8da824ac7755 -r bf0ba14741fb netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java --- 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; }