#SJAR_FLAGS += a list of things to pack, each usually prefixed with "-C src/", for *-sources.jar files
JAVAC = javac
-JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/ -Xdiags:verbose
+JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/
JAVA = java
JAVA_FLAGS += -cp ./bin/
JAR = jar
mkdir -p "$(PREFIX)/lib" "$(PREFIX)/bin"
cp $(NAME).jar "$(PREFIX)/lib/"
echo "#!/bin/sh" > "$(PREFIX)/bin/$(NAME)"
- echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"$$@\"" >> "$(PREFIX)/bin/$(NAME)"
+ echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" >> "$(PREFIX)/bin/$(NAME)"
chmod a+rx "$(PREFIX)/bin/$(NAME)"
+Version 0.9.5
+-------------
+
+Resource bundle bug
+ UTF-8 strings were sometimes wrangled
+ It is fixed by using a Bundle#Control, whih sadly is only available in
+ Java 1.6+
+
Version 0.9.4
-------------
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
-import be.nikiroo.utils.resources.Bundles;
-import be.nikiroo.utils.resources.Meta;
-
/**
* This class encapsulate a {@link ResourceBundle} in UTF-8. It only allows to
* retrieve values associated to an enumeration, and allows some additional
}
/**
- * Get the value for the given key if it exists in the internal map.
+ * Get the value for the given key if it exists in the internal map, or NULL
+ * if not.
*
* @param key
* the key to check for
*
- * @return true if it does
+ * @return the value, or NULL
*/
protected String getString(String key) {
if (containsKey(key)) {
- try {
- // Note: it is also possible to fix the borked charset issue
- // with a custom ResourceBundle#Control class, but this one,
- // while a workaround, depend less upon the JRE classes, which
- // may change
- return new String(map.getString(key).getBytes("ISO-8859-1"),
- "UTF-8");
- } catch (UnsupportedEncodingException e) {
- // Those 2 encodings are always supported
- e.printStackTrace();
- }
+ return map.getString(key);
}
return null;
if (map == null) {
map = ResourceBundle.getBundle(type.getPackage().getName() + "."
- + name.name(), locale);
+ + name.name(), locale, new FixedResourceBundleControl());
}
}
--- /dev/null
+package be.nikiroo.utils.resources;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Locale;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import java.util.ResourceBundle.Control;
+
+/**
+ * Fixed ResourceBundle.Control class. It will use UTF-8 for the files to load.
+ *
+ * Also support an option to first check into the given path before looking into
+ * the resources.
+ *
+ * @author niki
+ *
+ */
+class FixedResourceBundleControl extends Control {
+ @Override
+ public ResourceBundle newBundle(String baseName, Locale locale,
+ String format, ClassLoader loader, boolean reload)
+ throws IllegalAccessException, InstantiationException, IOException {
+ // The below is a copy of the default implementation.
+ String bundleName = toBundleName(baseName, locale);
+ String resourceName = toResourceName(bundleName, "properties");
+
+ ResourceBundle bundle = null;
+ InputStream stream = null;
+ if (reload) {
+ URL url = loader.getResource(resourceName);
+ if (url != null) {
+ URLConnection connection = url.openConnection();
+ if (connection != null) {
+ connection.setUseCaches(false);
+ stream = connection.getInputStream();
+ }
+ }
+ } else {
+ if (stream == null)
+ stream = loader.getResourceAsStream(resourceName);
+ }
+ if (stream != null) {
+ try {
+ // This line is changed to make it to read properties files
+ // as UTF-8.
+ // How can someone use an archaic encoding such as ISO 8859-1 by
+ // *DEFAULT* is beyond me...
+ bundle = new PropertyResourceBundle(new InputStreamReader(
+ stream, "UTF-8"));
+ } finally {
+ stream.close();
+ }
+ }
+ return bundle;
+ }
+}
\ No newline at end of file