From: <cr...@us...> - 2008-06-29 03:53:46
|
Revision: 4285 http://jnode.svn.sourceforge.net/jnode/?rev=4285&view=rev Author: crawley Date: 2008-06-28 20:53:45 -0700 (Sat, 28 Jun 2008) Log Message: ----------- Change URLArgument from an Argument<String> to an Argument<URL> Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java trunk/shell/src/shell/org/jnode/shell/syntax/URLArgument.java Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -71,23 +71,19 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws IOException { File[] files = ARG_FILE.getValues(); - String[] urls = ARG_URL.getValues(); + URL[] urls = ARG_URL.getValues(); boolean ok = true; if (urls != null && urls.length > 0) { - for (String urlString : urls) { + for (URL url : urls) { InputStream is = null; - try { - URL url = new URL(urlString); - is = url.openStream(); + try {is = url.openStream(); if (is == null) { ok = false; } else { process(is, out); } - } catch (MalformedURLException ex) { - err.println("Malformed url '" + urlString + "': " + ex.getMessage()); } catch (IOException ex) { - err.println("Can't fetch url '" + urlString + "': " + ex.getMessage()); + err.println("Can't fetch url '" + url + "': " + ex.getMessage()); } finally { if (is != null) { try { Modified: trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/fs/src/fs/org/jnode/fs/command/HexdumpCommand.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -54,15 +54,11 @@ exit(1); } } else if (ARG_URL.isSet()) { - String urlStr = ARG_URL.getValue(); + URL url = ARG_URL.getValue(); try { - URL url = new URL(urlStr); is = url.openStream(); - } catch (MalformedURLException ex) { - err.println("Malformed URL '" + urlStr + "': " + ex.getMessage()); - exit(1); } catch (IOException ex) { - err.println("Cannot access URL '" + urlStr + "': " + ex.getMessage()); + err.println("Cannot access URL '" + url + "': " + ex.getMessage()); exit(1); } } else { Modified: trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/shell/src/shell/org/jnode/shell/command/ClasspathCommand.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -61,7 +61,7 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { if (ARG_ADD.isSet()) { - addToClassPath(ARG_ADD.getValueAsURL()); + addToClassPath(ARG_ADD.getValue()); } else if (ARG_CLEAR.isSet()) { clearClassPath(); } else if (ARG_REFRESH.isSet()) { Modified: trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/shell/src/shell/org/jnode/shell/command/log4j/Log4jCommand.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -26,7 +26,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; -import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; import java.util.Properties; @@ -104,13 +103,8 @@ } } else if (ARG_URL.isSet()) { // Set configuration from a URL - try { - final URL configURL = new URL(ARG_URL.getValue()); - PropertyConfigurator.configure(configURL); - } catch (MalformedURLException ex) { - err.println("Malformed configuration URL: " + ex.getMessage()); - exit(1); - } + final URL configURL = ARG_URL.getValue(); + PropertyConfigurator.configure(configURL); } else if (FLAG_LIST.isSet()) { // List current loggers and their levels. Effective levels are shown // in parentheses. Modified: trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/shell/src/shell/org/jnode/shell/command/plugin/PluginCommand.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -74,7 +74,7 @@ private final StringArgument ARG_VERSION = new StringArgument("version", Argument.OPTIONAL, "plugin version"); - private PrintStream out, err; + private PrintStream out; private PluginManager mgr; @@ -94,7 +94,6 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { this.out = out; - this.err = err; try { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { @@ -107,18 +106,13 @@ } } - private void doRun() throws NameNotFoundException, SyntaxMultiplicityException, PluginException { + private void doRun() + throws NameNotFoundException, SyntaxMultiplicityException, PluginException, MalformedURLException { mgr = (PluginManager) InitialNaming.lookup(PluginManager.NAME); final String version = ARG_VERSION.isSet() ? ARG_VERSION.getValue() : Vm.getVm().getVersion(); final String pluginId = ARG_PLUGIN_ID.getValue(); if (ARG_LOADER_URL.isSet()) { - try { - final URL url = new URL(ARG_LOADER_URL.getValue()); - addPluginLoader(url); - } catch (MalformedURLException ex) { - err.println("Malformed plugin loader URL"); - exit(1); - } + addPluginLoader(ARG_LOADER_URL.getValue()); } else if (FLAG_LOAD.isSet()) { loadPlugin(pluginId, version); } else if (FLAG_RELOAD.isSet()) { Modified: trunk/shell/src/shell/org/jnode/shell/syntax/URLArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/syntax/URLArgument.java 2008-06-29 02:03:53 UTC (rev 4284) +++ trunk/shell/src/shell/org/jnode/shell/syntax/URLArgument.java 2008-06-29 03:53:45 UTC (rev 4285) @@ -23,16 +23,18 @@ import java.net.MalformedURLException; import java.net.URL; +import org.jnode.shell.CommandLine.Token; + /** * This class implements URL-valued command line arguments. At the moment, it performs * no special syntax checking and does no completion. * * @author cr...@jn... */ -public class URLArgument extends StringArgument { +public class URLArgument extends Argument<URL> { public URLArgument(String label, int flags, String description) { - super(label, flags, description); + super(label, flags, new URL[0], description); } public URLArgument(String label, int flags) { @@ -43,12 +45,21 @@ this(label, 0, null); } - public URL getValueAsURL() throws MalformedURLException { - return new URL(getValue()); - } +// public URL getValueAsURL() throws MalformedURLException { +// return getValue(); +// } @Override protected String argumentKind() { return "url"; } + + @Override + protected URL doAccept(Token value) throws CommandSyntaxException { + try { + return new URL(value.token); + } catch (MalformedURLException ex) { + throw new CommandSyntaxException(ex.getMessage(), ex); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |