# HG changeset patch # User Andrew Azores # Date 1438276313 14400 # Node ID 9e24c2ff6b4682527cd73f7386e4deafa9320628 # Parent 7fe258be550af1f242066694e4d4c65d3a95783f Add -defaultfile switch to PolicyEditor 2015-07-30 Andrew Azores 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 diff -r 7fe258be550a -r 9e24c2ff6b46 ChangeLog --- 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 + + 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 Removed last remains of BOOT_DIR diff -r 7fe258be550a -r 9e24c2ff6b46 NEWS --- 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. diff -r 7fe258be550a -r 9e24c2ff6b46 netx/net/sourceforge/jnlp/resources/Messages.properties --- 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 diff -r 7fe258be550a -r 9e24c2ff6b46 netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java --- 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 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.