0,0 → 1,71 |
package ak.hostadmiral.struts; |
|
import java.util.HashMap; |
import java.util.List; |
import java.util.ArrayList; |
import java.util.Iterator; |
import org.apache.struts.util.PropertyMessageResources; |
|
import ak.hostadmiral.util.ResourceManager; |
import ak.hostadmiral.util.ResourceAddedListener; |
|
/** |
* Extention of PropertyMessageResources to work with multiple |
* resource files, specified as semicolomn separated list. |
* Just a hack. |
*/ |
public class MultiPropertyMessageResources |
extends PropertyMessageResources |
implements ResourceAddedListener |
{ |
private List multiLocales = new ArrayList(); // List(HashMap) |
private List multiConfig = new ArrayList(); // List(String) |
|
public MultiPropertyMessageResources(MultiPropertyMessageResourcesFactory factory, |
String config) |
{ |
super(factory, config); |
initMultiConfig(config); |
ResourceManager.getInstance().addAddedListener(this); |
} |
|
public MultiPropertyMessageResources(MultiPropertyMessageResourcesFactory factory, |
String config, boolean returnNull) |
{ |
super(factory, config, returnNull); |
initMultiConfig(config); |
ResourceManager.getInstance().addAddedListener(this); |
} |
|
protected synchronized void loadLocale(String localeKey) |
{ |
for(int i = 0; i < multiConfig.size(); i++) { |
config = (String)multiConfig.get(i); |
locales = (HashMap)multiLocales.get(i); |
super.loadLocale(localeKey); |
} |
} |
|
protected void initMultiConfig(String cfg) |
{ |
// from struts-config.xml |
String[] strs = cfg.split("\\s*;\\s*"); |
|
for(int i = 0; i < strs.length; i++) { |
this.multiConfig.add(strs[i]); |
this.multiLocales.add(new HashMap()); |
} |
|
// from resource manager |
for(Iterator i = ResourceManager.getInstance().getResources().iterator(); i.hasNext(); ) { |
this.multiConfig.add((String)i.next()); |
this.multiLocales.add(new HashMap()); |
} |
} |
|
public void resourceAdded(String resourceName) |
{ |
this.multiConfig.add(resourceName); |
this.multiLocales.add(new HashMap()); |
} |
} |