[Japi-cvs] SF.net SVN: japi: [264] libs/argparser/trunk/src
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2006-12-16 21:48:02
|
Revision: 264
http://svn.sourceforge.net/japi/?rev=264&view=rev
Author: christianhujer
Date: 2006-12-16 13:47:59 -0800 (Sat, 16 Dec 2006)
Log Message:
-----------
Improved ResourceBundle handling.
Modified Paths:
--------------
libs/argparser/trunk/src/doc/examples/Head.java
libs/argparser/trunk/src/doc/examples/Recode.java
libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java
libs/argparser/trunk/src/net/sf/japi/io/args/package.html
Added Paths:
-----------
libs/argparser/trunk/src/doc/examples/Head.properties
libs/argparser/trunk/src/doc/examples/Head_de.properties
Removed Paths:
-------------
libs/argparser/trunk/src/doc/examples/head.properties
libs/argparser/trunk/src/doc/examples/head_de.properties
Modified: libs/argparser/trunk/src/doc/examples/Head.java
===================================================================
--- libs/argparser/trunk/src/doc/examples/Head.java 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/doc/examples/Head.java 2006-12-16 21:47:59 UTC (rev 264)
@@ -6,7 +6,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
-import java.util.ResourceBundle;
import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.BasicCommand;
import net.sf.japi.io.args.Option;
@@ -18,9 +17,6 @@
*/
public class Head extends BasicCommand {
- /** The ResourceBundle for locale-specific output. */
- private final ResourceBundle resourceBundle = ResourceBundle.getBundle("examples.head");
-
/** The number of items to print. */
private int numItems = 10;
@@ -133,9 +129,4 @@
ArgParser.simpleParseAndRun(new Head(), args);
}
- /** {@inheritDoc} */
- @Override public ResourceBundle getBundle() {
- return resourceBundle;
- }
-
} // class Head
Added: libs/argparser/trunk/src/doc/examples/Head.properties
===================================================================
--- libs/argparser/trunk/src/doc/examples/Head.properties (rev 0)
+++ libs/argparser/trunk/src/doc/examples/Head.properties 2006-12-16 21:47:59 UTC (rev 264)
@@ -0,0 +1,7 @@
+net.sf.japi.io.args.OptionType.REQUIRED=required
+net.sf.japi.io.args.OptionType.OPTIONAL=optional
+net.sf.japi.io.args.OptionType.TERMINAL=terminal
+setBytes=Print the first N bytes of each file.
+setLines=Print the first N lines of each file (default: 10).
+setQuiet=Never print headers giving file names.
+setVerbose=Always print headers giving file names.
Property changes on: libs/argparser/trunk/src/doc/examples/Head.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: libs/argparser/trunk/src/doc/examples/Head_de.properties
===================================================================
--- libs/argparser/trunk/src/doc/examples/Head_de.properties (rev 0)
+++ libs/argparser/trunk/src/doc/examples/Head_de.properties 2006-12-16 21:47:59 UTC (rev 264)
@@ -0,0 +1,7 @@
+net.sf.japi.io.args.OptionType.REQUIRED=erforderlich
+net.sf.japi.io.args.OptionType.OPTIONAL=optional
+net.sf.japi.io.args.OptionType.TERMINAL=abbrechend
+setBytes=Die ersten N Bytes jeder Datei ausgeben.
+setLines=Die ersten N Zeilen jeder Datei ausgeben (Voreinstellung: 10).
+setQuiet=Niemals Dateinamen vorab ausgeben.
+setVerbose=Immer Dateinamen vorab ausgeben.
Property changes on: libs/argparser/trunk/src/doc/examples/Head_de.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: libs/argparser/trunk/src/doc/examples/Recode.java
===================================================================
--- libs/argparser/trunk/src/doc/examples/Recode.java 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/doc/examples/Recode.java 2006-12-16 21:47:59 UTC (rev 264)
@@ -2,7 +2,6 @@
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -12,6 +11,8 @@
import java.io.Reader;
import java.io.Writer;
import java.util.List;
+import java.nio.channels.FileChannel;
+import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.BasicCommand;
import net.sf.japi.io.args.Option;
import static net.sf.japi.io.args.OptionType.REQUIRED;
@@ -83,13 +84,14 @@
} finally {
out.close();
}
- if (!tmpFile.renameTo(file)) {
- tmpFile.delete();
- throw new FileNotFoundException("Couldn't open " + file + " for writing.");
- }
} finally {
in.close();
}
+ try {
+ copy(tmpFile, file);
+ } finally {
+ tmpFile.delete();
+ }
}
/**
@@ -107,4 +109,34 @@
cout.flush();
}
+ /**
+ * Copies form one file to another.
+ * @param source File to copy.
+ * @param dest File to copy to.
+ * @throws IOException In case of I/O problems.
+ */
+ public void copy(final File source, final File dest) throws IOException {
+ final FileInputStream in = new FileInputStream(source);
+ try {
+ final FileOutputStream out = new FileOutputStream(dest);
+ try {
+ final FileChannel inChannel = in.getChannel();
+ final FileChannel outChannel = out.getChannel();
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ } finally {
+ out.close();
+ }
+ } finally {
+ in.close();
+ }
+ }
+
+ /**
+ * Main method.
+ * @param args Command line arguments
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new Recode(), args);
+ }
+
} // class Recode
Deleted: libs/argparser/trunk/src/doc/examples/head.properties
===================================================================
--- libs/argparser/trunk/src/doc/examples/head.properties 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/doc/examples/head.properties 2006-12-16 21:47:59 UTC (rev 264)
@@ -1,7 +0,0 @@
-net.sf.japi.io.args.OptionType.REQUIRED=required
-net.sf.japi.io.args.OptionType.OPTIONAL=optional
-net.sf.japi.io.args.OptionType.TERMINAL=terminal
-setBytes=Print the first N bytes of each file.
-setLines=Print the first N lines of each file (default: 10).
-setQuiet=Never print headers giving file names.
-setVerbose=Always print headers giving file names.
Deleted: libs/argparser/trunk/src/doc/examples/head_de.properties
===================================================================
--- libs/argparser/trunk/src/doc/examples/head_de.properties 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/doc/examples/head_de.properties 2006-12-16 21:47:59 UTC (rev 264)
@@ -1,7 +0,0 @@
-net.sf.japi.io.args.OptionType.REQUIRED=erforderlich
-net.sf.japi.io.args.OptionType.OPTIONAL=optional
-net.sf.japi.io.args.OptionType.TERMINAL=abbrechend
-setBytes=Die ersten N Bytes jeder Datei ausgeben.
-setLines=Die ersten N Zeilen jeder Datei ausgeben (Voreinstellung: 10).
-setQuiet=Niemals Dateinamen vorab ausgeben.
-setVerbose=Immer Dateinamen vorab ausgeben.
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-16 21:47:59 UTC (rev 264)
@@ -16,8 +16,8 @@
*/
public abstract class BasicCommand implements Command {
- /** The ResourceBundle for locale-specific output. */
- private final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.japi.io.args.messages");
+ /** The ResourceBundle for locale-specific output of this class. */
+ @NotNull private final ResourceBundle ownBundle = ResourceBundle.getBundle("net.sf.japi.io.args.messages");
/**
* Whether to exit or not.
@@ -116,7 +116,7 @@
* @return ResourceBundle for default locale.
*/
public ResourceBundle getBundle() {
- return resourceBundle;
+ return ownBundle;
}
/**
@@ -152,8 +152,12 @@
private String getString(final String key) throws MissingResourceException {
try {
return getBundle().getString(key);
- } catch (MissingResourceException e) {
- return resourceBundle.getString(key);
+ } catch (final MissingResourceException e) {
+ try {
+ return ResourceBundle.getBundle(getClass().getName()).getString(key);
+ } catch (final MissingResourceException e2) {
+ return ownBundle.getString(key);
+ }
}
}
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/package.html
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/package.html 2006-12-15 21:05:19 UTC (rev 263)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/package.html 2006-12-16 21:47:59 UTC (rev 264)
@@ -50,5 +50,9 @@
The special option <code>--</code> will stop argument parsing.
All strings that follow the <code>--</code>-option are treated as command arguments, not options, even if they start with <code>-</code>.
</p>
+ <p>
+ The ArgParser library is built upon the JavaBeans concept.
+ A command is a JavaBean, the command's options are bean properties.
+ </p>
</body>
</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|