Archive

Archive for July, 2009

Using a ResourceBundle for localization

July 27th, 2009 No comments

There is a nice java tutorial from Sun how to use ReseouceBundle for localization: http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html.

It’s actually rather simple: Just create a new ResourceBundle object by invoking the getBundle method, specifying the base name and Locale:

ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);

The getBundle method first looks for a class file that matches the base name and the Locale. If it can’t find a class file, it then checks for properties files. When the getBundle method locates the correct properties file, it returns a PropertyResourceBundle object containing the key-value pairs from the properties file.

To retrieve the translated value from the ResourceBundle, invoke the getString method as follows:

String value = labels.getString(key);
Categories: Uncategorized Tags:

Automating GnuPG

July 1st, 2009 No comments

If you want to use GnuPG in a script and don’t want to be prompted for the passphrase, put the passphrase in a file called passphrase.txt and use this to encrypt:

gpg --passphrase-fd 3 -c 3< passphrase.txt < filename > filename.gpg

Of course, you can also use echo to specify your passphrase

gpg --passphrase-fd 3 -c 3< <(echo "secret") < filename > filename.gpg

or you can pipe a tarball into gpg

tar -cf - dir/ | gpg --passphrase-fd 3 -c 3< <(echo "pass") > backup.tar.gpg

or even send a gpg encrypted tarball via e-mail

tar c dir/ | gpg --force-mdc -ac -o - --passphrase-fd 3 -c 3< <(echo "pass") | mail user@domain.tld

Note that you have to use the --batch flag if you want to run gpg from a cron script. (Otherwise gpg tries to read from /dev/tty that doesn’t exist for cron jobs)1.

More GnuPG hacks can be found here: http://www.linuxjournal.com/article/8732



[1] http://stackoverflow.com/questions/39867/how-to-run-gpg-from-a-script-run-by-cron


Categories: Uncategorized Tags: