Top Description Fields Constructors Methods
org.hsqldb.lib

public Class RefCapablePropertyResourceBundle

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.nio.charset.Charset, .StandardCharsets, java.util.Enumeration, .HashMap, .Locale, .Map, .MissingResourceException, .PropertyResourceBundle, .ResourceBundle, java.util.regex.Matcher, .Pattern

Just like PropertyResourceBundle, except keys mapped to nothing in the properties file will load the final String value from a text file. The use case is where one wants to use a ResourceBundle for Strings, but some of the Strings are long-- too long to maintain in a Java .properties file. By using this class, you can put each such long String in its own separate file, yet all keys mapped to (non-empty) values in the .properties file will behave just like regular PropertyResourceBundle properties. In this documentation, I call these values read in atomically from other files referenced values, because the values are not directly in the .properties file, but are "referenced" in the .properties file by virtue of the empty value for the key. You use this class in the same way as you would traditionally use ResourceBundle:
 import org.hsqldb.util..RefCapablePropertyResourceBundle;
 ...
     RefCapablePropertyResourceBundle bundle =
             RefCapablePropertyResourceBundle.getBundle("subdir.xyz");
     System.out.println("Value for '1' = (" + bundle.getString("1") + ')');
Just like PropertyResourceBundle, the .properties file and the referenced files are read in from the classpath by a class loader, according to the normal ResourceBundle rules. To eliminate the need to prohibit the use of any strings in the .properties values, and to enforce consistency, you must use the following rules to when putting your referenced files into place.

REFERENCED FILE DIRECTORY is a directory named with the base name of the properties file, and in the same parent directory. So, the referenced file directory /a/b/c/greentea is used to hold all reference files for properties files /a/b/c/greentea_en_us.properties, /a/b/c/greentea_de.properties, /a/b/c/greentea.properties, etc. (BTW, according to ResourceBundle rules, this resource should be looked up with name "a.b.c.greentea", not "/a/b/c..." or "a/b/c"). REFERENCED FILES themselves all have the base name of the property key, with locale appendages exactly as the referring properties files has, plus the suffix .text.

So, if we have the following line in /a/b/c/greentea_de.properties:

    1: eins
then you must have a reference text file /a/b/c/greentea/1_de.properties:

In reference text files, sequences of "\r", "\n" and "\r\n" are all translated to the line delimiter for your platform (System property line.separator). If one of those sequences exists at the very end of the file, it will be eliminated (so, if you really want getString() to end with a line delimiter, end your file with two of them). (The file itself is never modified-- I'm talking about the value returned by getString(String)).

To prevent throwing at runtime due to unset variables, use a wrapper class like SqltoolRB (use SqltoolRB.java as a template). To prevent throwing at runtime due to unset System Properties, or insufficient parameters passed to getString(String, String[]), set the behavior values appropriately.

Just like all Properties files, referenced files must use ISO-8859-1 encoding, with unicode escapes for characters outside of ISO-8859-1 character set. But, unlike Properties files, \ does not need to be escaped for normal usage.

The getString() methods with more than one parameter substitute for "positional" parameters of the form "%{1}". The getExpandedString() methods substitute for System Property names of the form "${1}". In both cases, you can interpose :+ and a string between the variable name and the closing }. This works just like the Bourne shell ${x:+y} feature. If "x" is set, then "y" is returned, and "y" may contain references to the original variable without the curly braces. In this file, I refer to the y text as the "conditional string". One example of each type:

    Out val = (${condlSysProp:+Prop condlSysProp is set to $condlSysProp.})
    Out val = (%{2:+Pos Var #2 is set to %2.})
OUTPUT if neither are set:
    Out val = ()
    Out val = ()
OUTPUT if condlSysProp=alpha and condlPLvar=beta:
    Out val = (Prop condlSysProp is set to alpha.)
    Out val = (Pos Var #2 is set to beta.)
This feature has the following limitations. The conditional string may span newlines, and it is often very useful to do so.
Author
Blaine Simpson (blaine dot simpson at admc dot com)
See Also
java.util.PropertyResourceBundle, java.util.ResourceBundle

Field Summary

Modifier and TypeField and Description
private static Map<ResourceBundle, RefCapablePropertyResourceBundle>
private String
private String
public static final int
private String
private Class<? extends Enum<?>>
public static final String
public static final int
private Pattern
private Pattern
public static final int
private String
private PropertyResourceBundle

Constructor Summary

AccessConstructor and Description
private
RefCapablePropertyResourceBundle(String baseName, PropertyResourceBundle wrappedBundle, Class<? extends Enum<?>> loaderClass)

Method Summary

Modifier and TypeMethod and Description
public static RefCapablePropertyResourceBundle

Returns:

RefCapablePropertyResourceBundle
getBundle
(String
String
baseName
,
ClassLoader
ClassLoader
loader
,
Class<? extends Enum<?>>
Class
loaderClass
)

Use like java.util.ResourceBundle.getBundle(String).

public static RefCapablePropertyResourceBundle

Returns:

RefCapablePropertyResourceBundle
getBundle
(String
String
baseName
,
Locale
Locale
locale
,
ClassLoader
ClassLoader
loader
,
Class<? extends Enum<?>>
Class
loaderClass
)

Use exactly like java.util.ResourceBundle.get(String, Locale, ClassLoader).

public String

Returns:

String
getExpandedString
(String
String
key
,
int
int
behavior
)

Same as getString(), but expands System Variables specified in property values like ${sysvarname}.

public String
getExpandedString(String key, String[] subs, int missingPropertyBehavior, int missingPosValueBehavior)

public Enumeration<String>
private InputStream
private static RefCapablePropertyResourceBundle

Returns:

RefCapablePropertyResourceBundle
getRef
(String
String
baseName
,
ResourceBundle
ResourceBundle
rb
,
Class<? extends Enum<?>>
Class
loaderClass
)

Return a ref to a new or existing RefCapablePropertyResourceBundle, or throw a MissingResourceException.

public String
getString(String key, String[] subs, int behavior)

public String

Returns:

String
getString
(String
String
key
)

Returns value defined in this RefCapablePropertyResourceBundle's .properties file, unless that value is empty.

private String
public String

Returns:

String
posSubst
(String
String
s
,
String[]
String[]
subs
,
int
int
behavior
)

Replaces positional substitution patterns of the form %{\d} with corresponding element of the given subs array.

public static String
toNativeLs(String
Input string with \n definitively indicating desired position for line separators.
inString
)

Returns: If platform's line-separator is \n, then just returns inString.

public String

Returns:

String
toString
()

Overrides java.lang.Object.toString.

Just identifies this RefCapablePropertyResourceBundle instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

allBundlesback to summary
private static Map<ResourceBundle, RefCapablePropertyResourceBundle> allBundles
baseNameback to summary
private String baseName
countryback to summary
private String country
EMPTYSTRING_BEHAVIORback to summary
public static final int EMPTYSTRING_BEHAVIOR
languageback to summary
private String language
loaderClassback to summary
private Class<? extends Enum<?>> loaderClass
LSback to summary
public static final String LS
NOOP_BEHAVIORback to summary
public static final int NOOP_BEHAVIOR
posPatternback to summary
private Pattern posPattern
sysPropVarPatternback to summary
private Pattern sysPropVarPattern
THROW_BEHAVIORback to summary
public static final int THROW_BEHAVIOR
variantback to summary
private String variant
wrappedBundleback to summary
private PropertyResourceBundle wrappedBundle

Constructor Detail

RefCapablePropertyResourceBundleback to summary
private RefCapablePropertyResourceBundle(String baseName, PropertyResourceBundle wrappedBundle, Class<? extends Enum<?>> loaderClass)

Method Detail

getBundleback to summary
public static RefCapablePropertyResourceBundle getBundle(String baseName, ClassLoader loader, Class<? extends Enum<?>> loaderClass)

Use like java.util.ResourceBundle.getBundle(String). ClassLoader is required for our getBundles()s, since it is impossible to get the "caller's" ClassLoader without using JNI (i.e., with pure Java).

Parameters
baseName:String

String

loader:ClassLoader

ClassLoader

loaderClass:Class<? extends Enum<?>>

Class

Returns:RefCapablePropertyResourceBundle

RefCapablePropertyResourceBundle

See Also
ResourceBundle#getBundle(String)
getBundleback to summary
public static RefCapablePropertyResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader, Class<? extends Enum<?>> loaderClass)

Use exactly like java.util.ResourceBundle.get(String, Locale, ClassLoader).

Parameters
baseName:String

String

locale:Locale

Locale

loader:ClassLoader

ClassLoader

loaderClass:Class<? extends Enum<?>>

Class

Returns:RefCapablePropertyResourceBundle

RefCapablePropertyResourceBundle

See Also
ResourceBundle#getBundle(String, Locale, ClassLoader)
getExpandedStringback to summary
public String getExpandedString(String key, int behavior)

Same as getString(), but expands System Variables specified in property values like ${sysvarname}.

Parameters
key:String

String

behavior:int

int

Returns:String

String

getExpandedStringback to summary
public String getExpandedString(String key, String[] subs, int missingPropertyBehavior, int missingPosValueBehavior)
getKeysback to summary
public Enumeration<String> getKeys()
getMostSpecificStreamback to summary
private InputStream getMostSpecificStream(String key, String l, String c, String v)

Recursive. For consistency we do not allow paths relative to anything other than root. Even though we load via Class, baseNames are resolved as if absolute, just like ClassLoader lookups.

getRefback to summary
private static RefCapablePropertyResourceBundle getRef(String baseName, ResourceBundle rb, Class<? extends Enum<?>> loaderClass)

Return a ref to a new or existing RefCapablePropertyResourceBundle, or throw a MissingResourceException.

Parameters
baseName:String

String

rb:ResourceBundle

ResourceBundle

loaderClass:Class<? extends Enum<?>>

Class

Returns:RefCapablePropertyResourceBundle

RefCapablePropertyResourceBundle

getStringback to summary
public String getString(String key, String[] subs, int behavior)
getStringback to summary
public String getString(String key)

Returns value defined in this RefCapablePropertyResourceBundle's .properties file, unless that value is empty. If the value in the .properties file is empty, then this returns the entire contents of the referenced text file.

Parameters
key:String

String

Returns:String

String

See Also
ResourceBundle#getString(String)
getStringFromFileback to summary
private String getStringFromFile(String key)
posSubstback to summary
public String posSubst(String s, String[] subs, int behavior)

Replaces positional substitution patterns of the form %{\d} with corresponding element of the given subs array. Note that %{\d} numbers are 1-based, so we lok for subs[x-1].

Parameters
s:String

String

subs:String[]

String[]

behavior:int

int

Returns:String

String

toNativeLsback to summary
public static String toNativeLs(String inString)
Parameters
inString:String

Input string with \n definitively indicating desired position for line separators.

Returns:String

If platform's line-separator is \n, then just returns inString. Otherwise returns a copy of inString, with all \n's transformed to the platform's line separators.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Just identifies this RefCapablePropertyResourceBundle instance.

Returns:String

String