Mercurial > hg > release > icedtea-web-1.6
changeset 1246:9e24c2ff6b46
Add -defaultfile switch to PolicyEditor
2015-07-30 Andrew Azores <aazores@redhat.com>
PolicyEditor -file switch and main argument cannot be used in conjunction
* NEWS: add note
* netx/net/sourceforge/jnlp/resources/Messages.properties
(PEMainArgAndFileSwitchSpecifiedError): new message
* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
(main): die when both main arg and -file are given
(getFilePathArgument): new method
(cleanFilePathArgument): new method
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Thu, 30 Jul 2015 13:11:53 -0400 |
parents | 7fe258be550a |
children | 8da824ac7755 |
files | ChangeLog NEWS netx/net/sourceforge/jnlp/resources/Messages.properties netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java |
diffstat | 4 files changed, 42 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jul 30 14:06:57 2015 +0200 +++ b/ChangeLog Thu Jul 30 13:11:53 2015 -0400 @@ -1,3 +1,14 @@ +2015-07-30 Andrew Azores <aazores@redhat.com> + + PolicyEditor -file switch and main argument cannot be used in conjunction + * NEWS: add note + * netx/net/sourceforge/jnlp/resources/Messages.properties + (PEMainArgAndFileSwitchSpecifiedError): new message + * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java + (main): die when both main arg and -file are given + (getFilePathArgument): new method + (cleanFilePathArgument): new method + 2015-07-27 Jiri Vanek <jvanek@redhat.com> Removed last remains of BOOT_DIR
--- a/NEWS Thu Jul 30 14:06:57 2015 +0200 +++ b/NEWS Thu Jul 30 13:11:53 2015 -0400 @@ -22,6 +22,7 @@ - fixed issue with -html receiving garbage in width and height * PolicyEditor - file flag made to work when used standalone + - file flag and main argument cannot be used in combination New in release 1.6 (2015-04-29): * Massively improved offline abilities. Added Xoffline switch to force work without inet connection.
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Jul 30 14:06:57 2015 +0200 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Jul 30 13:11:53 2015 -0400 @@ -752,6 +752,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 +PEMainArgAndFileSwitchSpecifiedError=Either -file may be specified or a main argument may be specified, but not both PEHelpMenu=Help PEAboutPolicyEditorItem=About PolicyEditor
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu Jul 30 14:06:57 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu Jul 30 13:11:53 2015 -0400 @@ -59,6 +59,8 @@ import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -1628,15 +1630,7 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - String filepath = optionParser.getParam(OptionsDefinitions.OPTIONS.FILE); - if (filepath.isEmpty()) { - if (optionParser.getMainArgs().size() == 0) { - filepath = null; - } else { - // maybe the user just forgot the -file flag, so try to open anyway - filepath = optionParser.getMainArg(); - } - } + final String filepath = getFilePathArgument(optionParser); final PolicyEditorWindow frame = getPolicyEditorFrame(filepath); frame.asWindow().setVisible(true); final List<String> codebases = optionParser.getParams(OptionsDefinitions.OPTIONS.CODEBASE); @@ -1647,6 +1641,32 @@ }); } + private static String getFilePathArgument(OptionParser optionParser) { + final boolean hasFileArgument = optionParser.hasOption(OptionsDefinitions.OPTIONS.FILE); + final boolean hasMainArgument = optionParser.mainArgExists(); + if (hasFileArgument && hasMainArgument) { + throw new IllegalArgumentException(R("PEMainArgAndFileSwitchSpecifiedError")); + } + + String filepath = null; + if (hasFileArgument) { + filepath = cleanFilePathArgument(optionParser.getParam(OptionsDefinitions.OPTIONS.FILE)); + } else if (hasMainArgument) { + filepath = cleanFilePathArgument(optionParser.getMainArg()); + } + return filepath; + } + + private static String cleanFilePathArgument(String filepath) { + if (filepath == null) { + return null; + } else if (filepath.isEmpty() || filepath.trim().isEmpty()) { + return null; + } else { + return filepath; + } + } + /** * Create a new PolicyEditor instance without passing argv. The returned instance is not * yet set visible.