-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from Pyknic/master
Fix: #54 Specify a resource bundle encoding in @FXMLView-annotation
- Loading branch information
Showing
6 changed files
with
126 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
.project | ||
/.settings/ | ||
.springBeans | ||
/.idea/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/de/felixroske/jfxsupport/ResourceBundleControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.felixroske.jfxsupport; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.charset.Charset; | ||
import java.util.Locale; | ||
import java.util.PropertyResourceBundle; | ||
import java.util.ResourceBundle; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Control that uses a custom {@link Charset} when reading resource bundles, | ||
* compared to the default charset which is ISO-8859-1. | ||
* | ||
* @author Emil Forslund | ||
* @since 2.1.6 | ||
*/ | ||
public final class ResourceBundleControl extends ResourceBundle.Control { | ||
|
||
private final Charset charset; | ||
|
||
public ResourceBundleControl(Charset charset) { | ||
this.charset = requireNonNull(charset); | ||
} | ||
|
||
@Override | ||
public ResourceBundle newBundle( | ||
final String baseName, | ||
final Locale locale, | ||
final String format, | ||
final ClassLoader loader, | ||
final boolean reload) | ||
throws IllegalAccessException, InstantiationException, IOException { | ||
|
||
final String bundleName = toBundleName(baseName, locale); | ||
final 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 { | ||
stream = loader.getResourceAsStream(resourceName); | ||
} | ||
|
||
if (stream != null) { | ||
try { | ||
bundle = new PropertyResourceBundle(new InputStreamReader( | ||
stream, charset)); | ||
} finally { | ||
stream.close(); | ||
} | ||
} | ||
|
||
return bundle; | ||
} | ||
} |