001: package org.enhydra.jawe;
002:
003: import java.util.ArrayList;
004: import java.util.Iterator;
005: import java.util.List;
006: import java.util.Locale;
007: import java.util.Properties;
008: import java.util.ResourceBundle;
009:
010: /**
011: * Utility for implementing multi language support.
012: *
013: * @author Sasa Bojanic
014: */
015: public class AdditionalResourceManager {
016: public static final String ADDITIONAL_LANGUAGE_PROPERTY_FILE = "AdditionalLanguagePropertyFile.";
017:
018: protected List propertyFiles = new ArrayList();
019:
020: public AdditionalResourceManager(Properties props) {
021: List apfs = ResourceManager.getResourceStrings(props,
022: ADDITIONAL_LANGUAGE_PROPERTY_FILE);
023: if (apfs != null) {
024: for (int i = 0; i < apfs.size(); i++) {
025: String pf = (String) apfs.get(i);
026: try {
027: ResourceBundle bundle = ResourceBundle.getBundle(
028: pf, ResourceManager.getChoosenLocale());
029: propertyFiles.add(bundle);
030: } catch (Exception mre) {
031: Properties eps = new Properties();
032: try {
033: Utils.manageProperties(eps,
034: getCurrentConfigFolder(), pf);
035: } catch (Exception ex) {
036: }
037: String locStrOrig = pf.substring(0, pf
038: .indexOf(".properties"));
039: Locale loc = ResourceManager.getChoosenLocale();
040: if (loc.getLanguage().length() > 0) {
041: try {
042: Utils.manageProperties(eps,
043: getCurrentConfigFolder(),
044: locStrOrig + "_"
045: + loc.getLanguage()
046: + ".properties");
047: } catch (Exception ex) {
048: }
049: if (loc.getCountry().length() > 0) {
050: try {
051: Utils.manageProperties(eps,
052: getCurrentConfigFolder(),
053: locStrOrig + "_"
054: + loc.getLanguage()
055: + "_"
056: + loc.getCountry()
057: + ".properties");
058: } catch (Exception ex) {
059: }
060: if (loc.getVariant().length() > 0) {
061: try {
062: Utils.manageProperties(eps,
063: getCurrentConfigFolder(),
064: locStrOrig + "_"
065: + loc.getLanguage()
066: + "_"
067: + loc.getCountry()
068: + "_"
069: + loc.getVariant()
070: + ".properties");
071: } catch (Exception ex) {
072: }
073: }
074: }
075: }
076: propertyFiles.add(eps);
077: }
078:
079: }
080: }
081:
082: }
083:
084: public String getLanguageDependentString(String nm) {
085: String str = null;
086: Iterator it = propertyFiles.iterator();
087: while (it.hasNext()) {
088: Object o = it.next();
089: if (o instanceof ResourceBundle) {
090: try {
091: ResourceBundle bundle = (ResourceBundle) o;
092: str = bundle.getString(nm);
093: if (str != null)
094: break;
095: } catch (Exception mre) {
096: }
097: } else {
098: Properties eps = (Properties) o;
099: str = eps.getProperty(nm);
100: }
101: }
102: return str;
103: }
104:
105: protected String getCurrentConfigFolder() {
106: String currentConfig = JaWEConstants.JAWE_USER_HOME;
107: String cch = System
108: .getProperty(JaWEConstants.JAWE_CURRENT_CONFIG_HOME);
109: if (cch != null) {
110: currentConfig = cch;
111: }
112: return currentConfig;
113: }
114:
115: }
|