You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ne...@apache.org on 2002/01/02 20:04:56 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test DefaultBundleLoaderTestCase.xtest DefaultBundleMatcherTestCase.java DefaultBundleMatcherTestCase.xtest XmlBundleTestCase.java XmlBundleTestCase.xtest
neeme 02/01/02 11:04:56
Modified: src/scratchpad/org/apache/avalon/excalibur/i18n
AbstractBundle.java Bundle.java BundleInfo.java
BundleInfoMapper.java BundleLoader.java
BundleMatcher.java BundleSelector.java
DefaultBundleMatcher.java DefaultMapper.java
DirectoryMapper.java XmlBundle.java
src/scratchpad/org/apache/avalon/excalibur/i18n/test
DefaultBundleLoaderTestCase.xtest
DefaultBundleMatcherTestCase.java
DefaultBundleMatcherTestCase.xtest
XmlBundleTestCase.java XmlBundleTestCase.xtest
Added: src/scratchpad/org/apache/avalon/excalibur/i18n
BundleFactory.java ConfigurableBundleInfo.java
DefaultBundleFactory.java
Removed: src/scratchpad/org/apache/avalon/excalibur/i18n
DefaultBundleLoader.java
Log:
another round of refactoring: made things more Excalibur-friendly and added Source capability
Revision Changes Path
1.10 +13 -2 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/AbstractBundle.java
Index: AbstractBundle.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/AbstractBundle.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractBundle.java 26 Dec 2001 21:26:05 -0000 1.9
+++ AbstractBundle.java 2 Jan 2002 19:04:56 -0000 1.10
@@ -18,6 +18,9 @@
/** bundle info */
private BundleInfo bundleInfo;
+ /** bundle info mapper */
+ private BundleInfoMapper mapper;
+
/** Parent of the current bundle */
private Bundle parent = null;
@@ -35,7 +38,15 @@
* Set the bundle info.
*/
public void setBundleInfo(BundleInfo bundleInfo) {
- this.bundleInfo = bundleInfo;
+ if (this.bundleInfo == null) this.bundleInfo = bundleInfo;
+ }
+
+ public BundleInfoMapper getMapper() {
+ return mapper;
+ }
+
+ public void setMapper(BundleInfoMapper mapper) {
+ if (this.mapper == null) this.mapper = mapper;
}
/**
@@ -53,7 +64,7 @@
* @param parent the parent bundle
*/
public void setParent(Bundle parent) {
- this.parent = parent;
+ if (this.parent == null) this.parent = parent;
}
/**
1.6 +8 -13 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/Bundle.java
Index: Bundle.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/Bundle.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Bundle.java 11 Dec 2001 09:53:35 -0000 1.5
+++ Bundle.java 2 Jan 2002 19:04:56 -0000 1.6
@@ -14,21 +14,11 @@
* This is the interface of the ResourceBundle, for used for i18n support.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public interface Bundle
-{
- /**
- * Initalize the bundle
- *
- * @param uri URI of the XML source
- */
- void init(String uri) throws Exception;
+public interface Bundle {
- /**
- * Load all the keys when initializing?
- */
- void setLoadOnInit(boolean loadOnInit);
+ String ROLE = "org.apache.avalon.excalibur.i18n.Bundle";
/**
* Get the bundle info.
@@ -39,6 +29,11 @@
* Set the bundle info.
*/
void setBundleInfo(BundleInfo bundleInfo);
+
+ /**
+ * Set the bundle info mapper.
+ */
+ void setMapper(BundleInfoMapper mapper);
/**
* Get the parent bundle of the current bundle.
1.6 +18 -85 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfo.java
Index: BundleInfo.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BundleInfo.java 11 Dec 2001 09:53:35 -0000 1.5
+++ BundleInfo.java 2 Jan 2002 19:04:56 -0000 1.6
@@ -9,73 +9,42 @@
import java.util.Locale;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.excalibur.pool.Poolable;
-import org.apache.avalon.excalibur.pool.Recyclable;
-
/**
* Used to map locale information to URI space, to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public class BundleInfo implements Component, Poolable, Recyclable
-{
-
- public static final String ROLE = "org.apache.avalon.excalibur.i18n.BundleInfo";
+public class BundleInfo {
private String name;
private Locale locale;
private String ext;
- public void configure(String name, Locale locale, String ext)
- {
+ public BundleInfo() {
+ this(null, null, null);
+ }
+
+ public BundleInfo(String name, Locale locale) {
+ this(name, locale, null);
+ }
+
+ public BundleInfo(String name, Locale locale, String ext) {
this.name = name;
this.locale = locale;
this.ext = ext;
}
- public void configure(String name, Locale locale)
- {
- configure(name, locale, null);
+ protected void setName(String name) {
+ this.name = name;
}
- public void configure(Locale locale)
- {
- configure(null, locale);
+ protected void setLocale(Locale locale) {
+ this.locale = locale;
}
- public void configure(Configuration conf)
- {
- Locale locale = null;
- try {
- Configuration localeConf = conf.getChild("locale");
- locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"));
- locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"),
- localeConf.getAttribute("variant"));
- }
- catch (ConfigurationException e) {
- // ignore
- }
-
- String bundleName = null;
- try {
- bundleName = conf.getAttribute("name");
- }
- catch (ConfigurationException e) {
- // ignore
- }
-
- String ext = null;
- try {
- ext = conf.getAttribute("ext");
- }
- catch (ConfigurationException e) {
- // ignore
- }
- configure(bundleName, locale, ext);
+ protected void setExtensionParameter(String ext) {
+ this.ext = ext;
}
public String getName()
@@ -101,11 +70,7 @@
public BundleInfo getParent()
{
if (this.locale != null && !this.locale.getLanguage().equals(""))
- {
- BundleInfo bi = new BundleInfo();
- bi.configure(this.name, this.getParentLocale(), this.ext);
- return bi;
- }
+ return new BundleInfo(this.name, this.getParentLocale(), this.ext);
else
return null;
}
@@ -132,38 +97,6 @@
newloc = new Locale(this.locale.getLanguage(), this.locale.getCountry(), "");
return newloc;
- }
-
- public boolean matches(BundleInfo info)
- {
- return
- match(this.name, info.getName()) &&
- match(this.locale, info.getLocale()) &&
- match(this.ext, info.getExtensionParameter());
- }
-
- protected boolean match(String str, String reference)
- {
- if (str == null) return true;
- if (reference == null) return false;
- return str.equals(reference);
- }
-
- protected boolean match(Locale locale, Locale reference)
- {
- if (locale == null) return true;
- if (reference == null) return false;
- return
- match(locale.getLanguage(), reference.getLanguage()) &&
- match(locale.getCountry(), reference.getCountry()) &&
- match(locale.getVariant(), reference.getVariant());
- }
-
- public void recycle()
- {
- this.name = null;
- this.locale = null;
- this.ext = null;
}
}
1.5 +5 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfoMapper.java
Index: BundleInfoMapper.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfoMapper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BundleInfoMapper.java 11 Dec 2001 09:53:35 -0000 1.4
+++ BundleInfoMapper.java 2 Jan 2002 19:04:56 -0000 1.5
@@ -12,10 +12,12 @@
* to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public interface BundleInfoMapper
-{
+public interface BundleInfoMapper {
+
+ static String ROLE = "org.apache.avalon.excalibur.i18n.BundleInfoMapper";
+
/**
* Get the string form of the bundle, based on bundle info.
*
1.5 +3 -8 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleLoader.java
Index: BundleLoader.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleLoader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BundleLoader.java 11 Dec 2001 09:53:35 -0000 1.4
+++ BundleLoader.java 2 Jan 2002 19:04:56 -0000 1.5
@@ -7,23 +7,18 @@
*/
package org.apache.avalon.excalibur.i18n;
-import org.apache.avalon.framework.configuration.Configurable;
-
/**
* Used to map locale information to URI space, to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public interface BundleLoader
- extends Configurable
-{
+public interface BundleLoader {
/**
* Load a bundle, based on bundleInfo.
*
* @return the bundle
*/
- Bundle loadBundle(BundleInfo bundleInfo);
+ void preload();
- void setBundleSelector(BundleSelector bundleSelector);
}
1.5 +5 -6 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleMatcher.java
Index: BundleMatcher.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleMatcher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BundleMatcher.java 11 Dec 2001 09:53:35 -0000 1.4
+++ BundleMatcher.java 2 Jan 2002 19:04:56 -0000 1.5
@@ -7,18 +7,17 @@
*/
package org.apache.avalon.excalibur.i18n;
-import org.apache.avalon.framework.configuration.Configurable;
-
/**
* Used to map bundle information to string representation (e.g. URI),
* to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public interface BundleMatcher
- extends Configurable
-{
+public interface BundleMatcher {
+
+ String ROLE = "org.apache.avalon.excalibur.i18n.BundleMatcher";
+
/**
* Get the string form of the bundle, based on bundle info.
*
1.10 +48 -57 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleSelector.java
Index: BundleSelector.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleSelector.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BundleSelector.java 26 Dec 2001 21:26:05 -0000 1.9
+++ BundleSelector.java 2 Jan 2002 19:04:56 -0000 1.10
@@ -12,29 +12,31 @@
import java.util.List;
import java.util.LinkedList;
import java.util.Locale;
+import java.util.Iterator;
import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.LogKitLogger;
+import org.apache.avalon.framework.activity.Initializable;
/**
* This is the method for getting instances of ResourceBundles.
*
* @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
* @author <a href="mailto:mengelhart@earthtrip.com">Mike Engelhart</a>
- * @version $Id: BundleSelector.java,v 1.9 2001/12/26 21:26:05 neeme Exp $
+ * @version $Id: BundleSelector.java,v 1.10 2002/01/02 19:04:56 neeme Exp $
*/
-public class BundleSelector
- extends ExcaliburComponentSelector
-{
+public class BundleSelector extends ExcaliburComponentSelector {
/**
* The role implemented by an <code>BundleSelector</code>.
@@ -52,14 +54,11 @@
protected Map cacheNotFound = new HashMap();
protected Map cache = new HashMap();
- /** Map of all bundle loaders */
- private Map loaders = new HashMap();
+ /** Matchers */
+ private Configuration[] matchers = null;
- /** List of matchers */
- private List matchers = new LinkedList();
-
- /** the default loader */
- private BundleLoader defaultLoader;
+ /** Default bundle type */
+ private String defaultType = null;
/**
* Configure the component.
@@ -67,37 +66,8 @@
* @param configuration the configuration
*/
public void configure(Configuration configuration) throws ConfigurationException {
- Configuration[] loaderConfs = configuration.getChild("loaders").getChildren("loader");
- for (int i = 0; i < loaderConfs.length; i++) {
- BundleLoader loader = (BundleLoader) getInstance(loaderConfs[i].getAttribute("class"));
- if (loader instanceof LogEnabled) ((LogEnabled)loader).enableLogging(new LogKitLogger(getLogger()));
- try {
- if (loader instanceof Composable) ((Composable)loader).compose(this.manager);
- }
- catch (ComponentException e) {
- throw new ConfigurationException("unable to compose loader", e);
- }
- loader.configure(loaderConfs[i]);
- loader.setBundleSelector(this);
- this.loaders.put(loaderConfs[i].getAttribute("type-name"), loader);
- }
- this.defaultLoader = (BundleLoader) this.loaders.get(configuration.getChild("matchers").getAttribute("default-type"));
- if (defaultLoader == null) throw new ConfigurationException("default loader not specified (matchers/@default-type)");
- Configuration[] matcherConfs = configuration.getChild("matchers").getChildren("matcher");
- for (int i = 0; i < matcherConfs.length; i++) {
- BundleMatcher matcher = (BundleMatcher) getInstance(matcherConfs[i].getAttribute("class"));
- matcher.configure(matcherConfs[i]);
- this.matchers.add(matcher);
- }
- }
-
- private Object getInstance(String className) throws ConfigurationException {
- try {
- return Class.forName(className).newInstance();
- }
- catch (Exception e) {
- throw new ConfigurationException("unable to load object: " + className, e);
- }
+ if (matchers == null) matchers = configuration.getChildren("bundle");
+ if (defaultType == null) defaultType = configuration.getAttribute("default");
}
/**
@@ -125,11 +95,7 @@
* @exception ComponentException if a bundle is not found
*/
public Component select(String name, String localeName) throws ComponentException {
- BundleInfo bi = (BundleInfo) this.manager.lookup(BundleInfo.ROLE);
- bi.configure(name, new Locale(localeName, localeName));
- Component result = select(bi);
- this.manager.release(bi);
- return result;
+ return select(new ConfigurableBundleInfo(name, new Locale(localeName, localeName)));
}
/**
@@ -166,17 +132,42 @@
}
private Bundle loadBundle(BundleInfo bundleInfo) {
- String type = null;
- for (int i = 0; i < matchers.size(); i++) {
- type = ((BundleMatcher) matchers.get(i)).getType(bundleInfo);
- if (type != null) break;
+ ComponentSelector matcherSelector = null;
+ ComponentSelector bundleFactorySelector = null;
+ BundleFactory bundleFactory = null;
+ Bundle bundle = null;
+ try {
+ matcherSelector = (ComponentSelector) manager.lookup(BundleMatcher.ROLE + "Selector");
+ String type = null;
+ for (int i = 0; i < matchers.length; i++) {
+ BundleMatcher matcher = null;
+ try {
+ matcher = (BundleMatcher) matcherSelector.select(matchers[i].getAttribute("matcher"));
+ type = matcher.getType(bundleInfo);
+ matcherSelector.release((Component) matcher);
+ } catch (ComponentException e) {
+ getLogger().error("Error while matching bundle!", e);
+ } finally {
+ if (matcher != null) matcherSelector.release((Component) matcher);
+ }
+ if (type != null) break;
+ }
+ if (type == null) type = defaultType;
+ bundleFactorySelector = (ComponentSelector) manager.lookup(BundleFactory.ROLE + "Selector");
+ bundleFactory = (BundleFactory) bundleFactorySelector.select(type);
+ bundle = bundleFactory.createInstance(bundleInfo);
+ } catch (ComponentException e) {
+ getLogger().error("Error while matching bundle!", e);
+ } catch (ConfigurationException e) {
+ getLogger().error("Error while matching bundle!", e);
+ } finally {
+ if (matcherSelector != null) manager.release(matcherSelector);
+ if (bundleFactorySelector != null) {
+ if (bundleFactory != null) bundleFactorySelector.release((Component) bundleFactory);
+ manager.release(bundleFactorySelector);
+ }
}
- BundleLoader loader = null;
- if (type != null)
- loader = (BundleLoader) loaders.get(type);
- if (loader == null)
- loader = defaultLoader;
- return loader.loadBundle(bundleInfo);
+ return bundle;
}
/**
1.5 +41 -13 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleMatcher.java
Index: DefaultBundleMatcher.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleMatcher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultBundleMatcher.java 11 Dec 2001 09:53:35 -0000 1.4
+++ DefaultBundleMatcher.java 2 Jan 2002 19:04:56 -0000 1.5
@@ -13,15 +13,16 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.Configurable;
/**
* Used to map bundle information to string representation (e.g. URI),
* to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public class DefaultBundleMatcher implements BundleMatcher {
+public class DefaultBundleMatcher implements BundleMatcher, Configurable {
private List bundleInfos = new LinkedList();
private String type;
@@ -34,7 +35,7 @@
public String getType(BundleInfo bundleInfo) {
if (bundleInfos != null) {
for (int i = 0; i < bundleInfos.size(); i++) {
- if (((BundleInfo) bundleInfos.get(i)).matches(bundleInfo))
+ if (match((BundleInfo) bundleInfos.get(i), bundleInfo))
return this.type;
}
return null;
@@ -52,19 +53,46 @@
Configuration[] bundleInfos = configuration.getChildren("bundle-info");
for (int i = 0; i < bundleInfos.length; i++) {
- BundleInfo bundleInfo = null;
- try {
- bundleInfo = (BundleInfo) Class.forName(bundleInfos[i].getAttribute("class")).newInstance();
+ Configurable bundleInfo = null;
+ String className = bundleInfos[i].getAttribute("class", null);
+ if (className != null) {
+ try {
+ bundleInfo = (Configurable) Class.forName(className).newInstance();
+ }
+ catch (ClassCastException e) {
+ throw new ConfigurationException("bundleinfo implementation does not implement Configurable interface! " +
+ "All bundleinfo implementations passed to matchers have to be Configurable!", e);
+ }
+ catch (Exception e) {
+ throw new ConfigurationException("unable to load bundleinfo implementation", e);
+ }
}
- catch (ConfigurationException e) {
- // ignore
- }
- catch (Exception e) {
- throw new ConfigurationException("unable to load bundleinfo implementation", e);
- }
- if (bundleInfo == null) bundleInfo = new BundleInfo();
+ if (bundleInfo == null) bundleInfo = new ConfigurableBundleInfo();
bundleInfo.configure(bundleInfos[i]);
this.bundleInfos.add(bundleInfo);
}
}
+
+ protected boolean match(BundleInfo src, BundleInfo compareTo) {
+ return
+ match(src.getName(), compareTo.getName()) &&
+ match(src.getLocale(), compareTo.getLocale()) &&
+ match(src.getExtensionParameter(), compareTo.getExtensionParameter());
+ }
+
+ protected boolean match(String str, String reference) {
+ if (str == null) return true;
+ if (reference == null) return false;
+ return str.equals(reference);
+ }
+
+ protected boolean match(Locale locale, Locale reference) {
+ if (locale == null) return true;
+ if (reference == null) return false;
+ return
+ match(locale.getLanguage(), reference.getLanguage()) &&
+ match(locale.getCountry(), reference.getCountry()) &&
+ match(locale.getVariant(), reference.getVariant());
+ }
+
}
1.6 +30 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultMapper.java
Index: DefaultMapper.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultMapper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultMapper.java 11 Dec 2001 09:53:35 -0000 1.5
+++ DefaultMapper.java 2 Jan 2002 19:04:56 -0000 1.6
@@ -9,15 +9,41 @@
import java.util.Locale;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.component.Component;
+
/**
* Maps the locale using the standard Java mapping: en-US would be mapped to
* file ending with en_US.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public class DefaultMapper implements BundleInfoMapper {
+public class DefaultMapper implements BundleInfoMapper, Component, Configurable {
+
+ public static final class ConfigurationKeys {
+ public static final String PREFIX = "prefix";
+ public static final String SUFFIX = "suffix";
+ }
+
+ private String prefix = null;
+ private String suffix = null;
+
+ public void configure(Configuration configuration) throws ConfigurationException {
+ if (prefix == null) prefix = configuration.getChild(ConfigurationKeys.PREFIX).getValue();
+ if (suffix == null) suffix = configuration.getChild(ConfigurationKeys.SUFFIX).getValue();
+ }
+
+ protected String getPrefix() {
+ return prefix;
+ }
+
+ protected String getSuffix() {
+ return suffix;
+ }
/**
* Get the URI for the bundle, based on locale and filename.
@@ -27,7 +53,7 @@
public String map(BundleInfo bundleInfo) {
String name = bundleInfo.getName();
Locale loc = bundleInfo.getLocale();
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(getPrefix());
sb.append('/').append(name);
if (loc != null)
{
@@ -47,6 +73,7 @@
sb.append(loc.getVariant());
}
}
+ sb.append(getSuffix());
String result = sb.toString();
return result;
}
1.6 +4 -4 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DirectoryMapper.java
Index: DirectoryMapper.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DirectoryMapper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DirectoryMapper.java 11 Dec 2001 09:53:35 -0000 1.5
+++ DirectoryMapper.java 2 Jan 2002 19:04:56 -0000 1.6
@@ -14,10 +14,10 @@
* file ending with en_US.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/12/11 09:53:35 $ $Author: jefft $
+ * @version CVS $Revision: 1.6 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
-public class DirectoryMapper implements BundleInfoMapper {
+public class DirectoryMapper extends DefaultMapper {
/**
* Get the URI for the bundle, based on locale and filename.
@@ -27,7 +27,7 @@
public String map(BundleInfo bundleInfo) {
String name = bundleInfo.getName();
Locale loc = bundleInfo.getLocale();
- StringBuffer sb = new StringBuffer();
+ StringBuffer sb = new StringBuffer(getPrefix());
if (loc != null) {
String lang = loc.getLanguage();
String country = loc.getCountry();
@@ -37,7 +37,7 @@
if (country.length() > 0) sb.append("/").append(country);
if (variant.length() > 0) sb.append("/").append(variant);
}
- sb.append("/").append(name);
+ sb.append("/").append(name).append(getSuffix());
String result = sb.toString();
return result;
1.5 +46 -20 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/XmlBundle.java
Index: XmlBundle.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/XmlBundle.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlBundle.java 25 Dec 2001 22:40:27 -0000 1.4
+++ XmlBundle.java 2 Jan 2002 19:04:56 -0000 1.5
@@ -9,10 +9,16 @@
/** JDK classes **/
import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.excalibur.xml.xpath.XPathProcessor;
+import org.apache.avalon.excalibur.source.Source;
+import org.apache.avalon.excalibur.source.SourceResolver;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -34,9 +40,15 @@
* @author <a href="mailto:mengelhart@earthtrip.com">Mike Engelhart</a>
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @author <a href="mailto:oleg@one.lv">Oleg Podolsky</a>
- * @version $Id: XmlBundle.java,v 1.4 2001/12/25 22:40:27 neeme Exp $
+ * @version $Id: XmlBundle.java,v 1.5 2002/01/02 19:04:56 neeme Exp $
*/
-public class XmlBundle extends AbstractBundle implements Disposable, Composable {
+public class XmlBundle extends AbstractBundle implements Configurable, Initializable, Disposable, Composable {
+
+ /** Constants for configuration keys */
+ public static class ConfigurationKeys {
+ public static final String LOAD_ON_INIT = "load-on-init";
+ public static final String USE_ROOT = "use-root-element";
+ }
/** Cache for storing string values for existing XPaths */
private Map cache = new HashMap();
@@ -53,30 +65,43 @@
/** XPath Processor */
private XPathProcessor processor = null;
+ /** bundle info mapper */
+ private BundleInfoMapper mapper;
+
+ /** bundle name prefix */
+ private String prefix;
+
+ /** bundle name suffix */
+ private String suffix;
+
+ /** Load all the keys when initializing? */
private boolean loadOnInit = true;
+
+ /** Use the XML root element in key names when pre-loading? */
private boolean useRootElement = false;
public void compose(ComponentManager manager) {
this.manager = manager;
try {
this.processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
+ this.mapper = (BundleInfoMapper)this.manager.lookup(BundleInfoMapper.ROLE);
} catch (Exception e) {
getLogger().error("cannot obtain XPathProcessor", e);
}
}
- /**
- * Load all the keys when initializing?
- */
- public void setLoadOnInit(boolean loadOnInit) {
- this.loadOnInit = loadOnInit;
+ public void configure(Configuration configuration) throws ConfigurationException {
+ this.loadOnInit = configuration.getAttributeAsBoolean(ConfigurationKeys.LOAD_ON_INIT, true);
+ this.useRootElement = configuration.getAttributeAsBoolean(ConfigurationKeys.USE_ROOT, false);
}
/**
- * Use the XML root element in key names when pre-loading?
+ * Initalize the bundle
+ *
+ * @param document XML source document (DOM)
*/
- public void setUseRootElement(boolean useRootElement) {
- this.useRootElement = useRootElement;
+ public void initialize() throws Exception {
+ initialize(getMapper().map(getBundleInfo()));
}
/**
@@ -87,8 +112,10 @@
* @exception ParserConfigurationException if no parser is configured
* @exception SAXException if an error occurs while parsing the file
*/
- public void init(String uri) throws Exception {
- this.init(getDocumentBuilder().parse(uri));
+ public void initialize(String uri) throws Exception {
+ SourceResolver resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ initialize(resolver.resolve(uri));
+ this.manager.release(resolver);
}
/**
@@ -99,8 +126,8 @@
* @exception ParserConfigurationException if no parser is configured
* @exception SAXException if an error occurs while parsing the file
*/
- public void init(File file) throws Exception {
- this.init(getDocumentBuilder().parse(file));
+ public void initialize(Source source) throws Exception {
+ initialize(source.getInputStream());
}
/**
@@ -111,18 +138,17 @@
* @exception ParserConfigurationException if no parser is configured
* @exception SAXException if an error occurs while parsing the file
*/
- public void init(InputStream inStream) throws Exception {
- this.init(getDocumentBuilder().parse(inStream));
+ public void initialize(InputStream inStream) throws Exception {
+ this.doc = getDocumentBuilder().parse(inStream);
+ load();
}
/**
- * Initalize the bundle
+ * Load (pre-cache) the contents
*
* @param document XML source document (DOM)
*/
- public void init(Document document) {
- if (getLogger().isInfoEnabled()) getLogger().info("constructing XMLResourceBundle: " + getBundleInfo());
- this.doc = document;
+ private void load() throws Exception {
if (this.loadOnInit) {
cacheAll(doc.getDocumentElement(), useRootElement ? '/' + doc.getDocumentElement().getTagName() : "");
}
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleFactory.java
Index: BundleFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.i18n;
public interface BundleFactory {
String ROLE = "org.apache.avalon.excalibur.i18n.BundleFactory";
Bundle createInstance(BundleInfo bi);
}
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/ConfigurableBundleInfo.java
Index: ConfigurableBundleInfo.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.i18n;
import java.util.Locale;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* Used to map locale information to URI space, to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
public class ConfigurableBundleInfo extends BundleInfo implements Configurable {
public ConfigurableBundleInfo() {
this(null, null, null);
}
public ConfigurableBundleInfo(String name, Locale locale) {
configure(name, locale, null);
}
public ConfigurableBundleInfo(String name, Locale locale, String ext) {
configure(name, locale, ext);
}
public void configure(String name, Locale locale, String ext) {
setName(name);
setLocale(locale);
setExtensionParameter(ext);
}
public void configure(String name, Locale locale) {
configure(name, locale, null);
}
public void configure(Locale locale) {
configure(null, locale);
}
public void configure(Configuration conf) {
Locale locale = null;
try {
Configuration localeConf = conf.getChild("locale");
locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"));
locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"),
localeConf.getAttribute("variant"));
}
catch (ConfigurationException e) {
// ignore
}
String bundleName = null;
try {
bundleName = conf.getAttribute("name");
}
catch (ConfigurationException e) {
// ignore
}
String ext = null;
try {
ext = conf.getAttribute("ext");
}
catch (ConfigurationException e) {
// ignore
}
configure(bundleName, locale, ext);
}
}
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleFactory.java
Index: DefaultBundleFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.i18n;
import java.util.Locale;
import java.io.FileNotFoundException;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.activity.Initializable;
/**
* Used to map locale information to URI space, to find the relevant bundle.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/01/02 19:04:56 $ $Author: neeme $
*/
public class DefaultBundleFactory extends AbstractLogEnabled implements BundleFactory, Configurable, Composable, Initializable {
public static final class ConfigurationKeys {
public static final String BUNDLE = "bundle";
public static final String MAPPER = "mapper";
public static final String BUNDLE_CONF = "bundle-conf";
}
/** FQCN of the returned bundles */
private String bundleClassName = null;
/** Bundle configuration */
private Configuration bundleConf = null;
/** Mapper lookup hint **/
private String mapperHint = null;
/** Component Manager */
protected ComponentManager manager = null;
public void compose(ComponentManager manager) {
this.manager = manager;
}
/**
* Configure the component.
*
* @param configuration the configuration
*/
public void configure(Configuration configuration) throws ConfigurationException {
if (bundleClassName == null) bundleClassName = configuration.getAttribute(ConfigurationKeys.BUNDLE);
if (mapperHint == null) mapperHint = configuration.getAttribute(ConfigurationKeys.MAPPER);
if (bundleConf == null) bundleConf = configuration.getChild(ConfigurationKeys.BUNDLE_CONF);
if (getLogger().isDebugEnabled()) {
getLogger().debug(
"BundleLoader configured with bundle=" + bundleClassName +
", mapper=" + mapperHint +
"");
}
}
public void initialize() throws Exception {
// TODO: implement the preloading of bundles
}
/**
* Load a bundle, based on bundleInfo.
*
* @return the bundle
*/
public Bundle createInstance(BundleInfo bi) {
Bundle bundle = null;
Bundle parentBundle = null;
BundleInfo parentBundleInfo = bi.getParent();
ComponentSelector mapperSelector = null;
BundleInfoMapper mapper = null;
ComponentSelector bundleSelector = null;
try {
mapperSelector = (ComponentSelector) manager.lookup(BundleInfoMapper.ROLE + "Selector");
mapper = (BundleInfoMapper) mapperSelector.select(mapperHint);
bundleSelector = (ComponentSelector) manager.lookup(Bundle.ROLE + "Selector");
if (getLogger().isDebugEnabled()) getLogger().debug("Loading bundle: " + bi);
if (parentBundleInfo != null)
parentBundle = (Bundle) bundleSelector.select(parentBundleInfo);
bundle = getBundleInstance();
if (bundle instanceof LogEnabled) ((LogEnabled)bundle).enableLogging(getLogger());
if (bundle instanceof Configurable) ((Configurable)bundle).configure(bundleConf);
bundle.setBundleInfo(bi);
bundle.setMapper(mapper);
bundle.setParent(parentBundle);
if (bundle instanceof Composable) ((Composable)bundle).compose(this.manager);
bundle.setLastModified(System.currentTimeMillis());
if (bundle instanceof Initializable) ((Initializable)bundle).initialize();
}
catch (FileNotFoundException e) {
getLogger().warn("File not found while loading bundle: " + bi);
bundle = null;
}
catch (Exception e) {
getLogger().error("Error while loading bundle: " + bi, e);
bundle = null;
}
finally {
if (mapperSelector != null) {
if (mapper != null) mapperSelector.release((Component) mapper);
manager.release(mapperSelector);
}
if (bundleSelector != null) manager.release(bundleSelector);
}
return bundle;
}
private Bundle getBundleInstance() {
try {
return (Bundle) Thread.currentThread().getContextClassLoader().loadClass(bundleClassName).newInstance();
} catch (InstantiationException e) {
getLogger().error("Could not create bundle instance!", e);
} catch (IllegalAccessException e) {
getLogger().error("Could not create bundle instance!", e);
} catch (ClassNotFoundException e) {
getLogger().error("Could not create bundle instance!", e);
}
return null;
}
}
1.5 +75 -30 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleLoaderTestCase.xtest
Index: DefaultBundleLoaderTestCase.xtest
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleLoaderTestCase.xtest,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultBundleLoaderTestCase.xtest 7 Dec 2001 13:48:22 -0000 1.4
+++ DefaultBundleLoaderTestCase.xtest 2 Jan 2002 19:04:56 -0000 1.5
@@ -8,40 +8,85 @@
]]></annotation>
<roles>
<role name="org.apache.avalon.excalibur.xml.xpath.XPathProcessor" shorthand="xpath-processor" default-class="org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl"/>
- <role name="org.apache.avalon.excalibur.i18n.BundleSelector" shorthand="bundle-selector" default-class="org.apache.avalon.excalibur.i18n.BundleSelector"/>
- <role name="org.apache.avalon.excalibur.i18n.BundleInfo" shorthand="bundle-info" default-class="org.apache.avalon.excalibur.i18n.BundleInfo"/>
+ <role
+ shorthand="bundles"
+ name="org.apache.avalon.excalibur.i18n.BundleSelector"
+ default-class="org.apache.avalon.excalibur.i18n.BundleSelector"
+ />
+ <role
+ shorthand="bundle-mappers"
+ name="org.apache.avalon.excalibur.i18n.BundleInfoMapperSelector"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"
+ >
+ <hint shorthand="default" class="org.apache.avalon.excalibur.i18n.DefaultMapper"/>
+ <hint shorthand="dir" class="org.apache.avalon.excalibur.i18n.DirectoryMapper"/>
+ </role>
+ <role
+ shorthand="bundle-matchers"
+ name="org.apache.avalon.excalibur.i18n.BundleMatcherSelector"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"
+ >
+ <hint shorthand="default" class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher"/>
+ </role>
+ <role
+ shorthand="bundle-loaders"
+ name="org.apache.avalon.excalibur.i18n.BundleLoaderSelector"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"
+ >
+ <hint shorthand="default" class="org.apache.avalon.excalibur.i18n.DefaultBundleLoader"/>
+ </role>
+ <role
+ shorthand="bundle-factories"
+ name="org.apache.avalon.excalibur.i18n.BundleFactorySelector"
+ default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector"
+ >
+ <hint shorthand="default" class="org.apache.avalon.excalibur.i18n.DefaultBundleFactory"/>
+ </role>
</roles>
<context/>
<logkit/>
<components>
- <bundle-info/>
- <bundle-selector>
- <loaders>
- <loader type-name="xml" bundle="org.apache.avalon.excalibur.i18n.XmlBundle" class="org.apache.avalon.excalibur.i18n.DefaultBundleLoader" mapper="org.apache.avalon.excalibur.i18n.DefaultMapper">
- <prefix>file:///root/path/to/xml/files/</prefix>
- <suffix>.xml</suffix>
- <load-on-startup>
- <!-- implementation specific parameters -->
- <all/>
- </load-on-startup>
- </loader>
- </loaders>
- <matchers default-type="xml">
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test1">
- <bundle-info name="test" ext="test-ext">
- <locale language="test-lang" country="test-country" variant="test-variant"/>
- </bundle-info>
- </matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test2">
- <bundle-info name="test"/>
- </matcher>
- <matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test3">
- <bundle-info>
- <locale language="test-lang" country="test-country"/>
- </bundle-info>
- </matcher>
- </matchers>
- </bundle-selector>
+ <bundle-mappers>
+ <default name="test">
+ <prefix>file:///root/path/to/xml/files/</prefix>
+ <suffix>.xml</suffix>
+ </default>
+ </bundle-mappers>
+ <bundle-matchers>
+ <default name="test1">
+ <bundle-info name="test" ext="test-ext">
+ <locale language="test-lang" country="test-country" variant="test-variant"/>
+ </bundle-info>
+ </default>
+ <default name="test2">
+ <bundle-info name="test"/>
+ </default>
+ <default name="test3">
+ <bundle-info>
+ <locale language="test-lang" country="test-country"/>
+ </bundle-info>
+ </default>
+ </bundle-matchers>
+ <bundle-loaders>
+ <default name="loader">
+ <scan-dir>dir/to/be/scanned</scan-dir>
+ <return-type>xml</return-type>
+ </default>
+ </bundle-loaders>
+ <bundle-factories>
+ <default name="xml" mapper="test" bundle="org.apache.avalon.excalibur.i18n.XmlBundle">
+ <bundle-conf
+ load-on-init="true"
+ use-root-element="false"
+ />
+ </default>
+ </bundle-factories>
+ <bundles default="xml">
+ <test1 matcher="test1"/>
+ <test2 matcher="test2"/>
+ <test3 matcher="test3"/>
+ <xml matcher="test4"/>
+ </bundles>
<xpath-processor/>
</components>
</testcase>
1.4 +11 -31 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.java
Index: DefaultBundleMatcherTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultBundleMatcherTestCase.java 11 Dec 2001 09:53:35 -0000 1.3
+++ DefaultBundleMatcherTestCase.java 2 Jan 2002 19:04:56 -0000 1.4
@@ -15,15 +15,17 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.component.ComponentException;
import junit.framework.TestCase;
import org.apache.avalon.excalibur.i18n.BundleInfo;
import org.apache.avalon.excalibur.i18n.BundleMatcher;
+import org.apache.avalon.excalibur.i18n.ConfigurableBundleInfo;
/**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version $Id: DefaultBundleMatcherTestCase.java,v 1.3 2001/12/11 09:53:35 jefft Exp $
+ * @version $Id: DefaultBundleMatcherTestCase.java,v 1.4 2002/01/02 19:04:56 neeme Exp $
*/
public class DefaultBundleMatcherTestCase extends TestCase {
@@ -38,7 +40,7 @@
this.matchers = new BundleMatcher[confs.length];
for (int i = 0; i < confs.length; i++) {
this.matchers[i] = (BundleMatcher) Class.forName(confs[i].getAttribute("class")).newInstance();
- this.matchers[i].configure(confs[i]);
+ if (this.matchers[i] instanceof Configurable) ((Configurable) this.matchers[i]).configure(confs[i]);
}
}
@@ -58,35 +60,13 @@
}
public void testMatching() throws Exception {
- BundleInfo bundleInfo = new BundleInfo();
-
- bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"), "test-ext");
- assertEquals("test1", matchers[0].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"), "test");
- assertTrue(null == matchers[0].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("test", new Locale("test-lang", "test-country", "test-variant"));
- assertEquals("test2", matchers[1].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("testing", new Locale("test-lang", "test-country", "test-variant"));
- assertTrue(null == matchers[1].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("test", new Locale("test-lang", "test-country"));
- assertEquals("test3", matchers[2].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("testing", new Locale("test-language", "test-country"));
- assertTrue(null == matchers[2].getType(bundleInfo));
- bundleInfo.recycle();
-
- bundleInfo.configure("testing", new Locale("test-lang", "test-count"));
- assertTrue(null == matchers[2].getType(bundleInfo));
- bundleInfo.recycle();
+ assertEquals("test1", matchers[0].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"), "test-ext")));
+ assertTrue(null == matchers[0].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"), "test")));
+ assertEquals("test2", matchers[1].getType(new BundleInfo("test", new Locale("test-lang", "test-country", "test-variant"))));
+ assertTrue(null == matchers[1].getType(new BundleInfo("testing", new Locale("test-lang", "test-country", "test-variant"))));
+ assertEquals("test3", matchers[2].getType(new BundleInfo("test", new Locale("test-lang", "test-country"))));
+ assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale("test-language", "test-country"))));
+ assertTrue(null == matchers[2].getType(new BundleInfo("testing", new Locale("test-lang", "test-count"))));
}
}
1.3 +1 -1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.xtest
Index: DefaultBundleMatcherTestCase.xtest
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/DefaultBundleMatcherTestCase.xtest,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultBundleMatcherTestCase.xtest 7 Dec 2001 13:48:22 -0000 1.2
+++ DefaultBundleMatcherTestCase.xtest 2 Jan 2002 19:04:56 -0000 1.3
@@ -9,7 +9,7 @@
<bundle-info name="test"/>
</matcher>
<matcher class="org.apache.avalon.excalibur.i18n.DefaultBundleMatcher" type="test3">
- <bundle-info class="org.apache.avalon.excalibur.i18n.BundleInfo">
+ <bundle-info class="org.apache.avalon.excalibur.i18n.ConfigurableBundleInfo">
<locale language="test-lang" country="test-country"/>
</bundle-info>
</matcher>
1.7 +18 -15 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.java
Index: XmlBundleTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XmlBundleTestCase.java 11 Dec 2001 09:53:35 -0000 1.6
+++ XmlBundleTestCase.java 2 Jan 2002 19:04:56 -0000 1.7
@@ -14,10 +14,13 @@
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.excalibur.i18n.BundleInfo;
import org.apache.avalon.excalibur.i18n.XmlBundle;
+import org.apache.avalon.excalibur.i18n.BundleInfoMapper;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
/**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
- * @version $Id: XmlBundleTestCase.java,v 1.6 2001/12/11 09:53:35 jefft Exp $
+ * @version $Id: XmlBundleTestCase.java,v 1.7 2002/01/02 19:04:56 neeme Exp $
*/
public class XmlBundleTestCase extends ExcaliburTestCase {
@@ -29,31 +32,31 @@
super(name);
}
- private BundleInfo getBundleInfoInstance(String name, Locale loc) {
- BundleInfo bi = new BundleInfo();
- bi.configure(name, loc);
- return bi;
- }
-
public void setUp() throws Exception {
this.variables.put("value", "a cat");
final String bundleFileName = this.getClass().getPackage().getName().replace( '.', '/' ) + "/XmlBundle.xml";
getLogger().debug("Test-bundle file = " + bundleFileName);
- this.bundle.setBundleInfo(getBundleInfoInstance("test", null));
+ this.bundle.setBundleInfo(new BundleInfo("test", null));
+ this.bundle.setMapper((BundleInfoMapper) this.manager.lookup(BundleInfoMapper.ROLE));
this.bundle.enableLogging(getLogEnabledLogger());
this.bundle.compose(this.manager);
- this.bundle.setLoadOnInit(true);
- this.bundleWithRoot.setUseRootElement(false);
- this.bundle.init(this.getClass().getClassLoader().getResource(bundleFileName).openStream());
+ DefaultConfiguration conf = new DefaultConfiguration("bundle-conf", "conf");
+ conf.setAttribute(XmlBundle.ConfigurationKeys.LOAD_ON_INIT, "true");
+ conf.setAttribute(XmlBundle.ConfigurationKeys.USE_ROOT, "false");
+ this.bundle.configure(conf);
+ this.bundle.initialize(this.getClass().getClassLoader().getResource(bundleFileName).openStream());
- this.bundleWithRoot.setBundleInfo(getBundleInfoInstance("test-with-root", null));
+ this.bundleWithRoot.setBundleInfo(new BundleInfo("test-with-root", null));
+ this.bundleWithRoot.setMapper((BundleInfoMapper) this.manager.lookup(BundleInfoMapper.ROLE));
this.bundleWithRoot.enableLogging(getLogEnabledLogger());
this.bundleWithRoot.compose(super.manager);
- this.bundleWithRoot.setLoadOnInit(true);
- this.bundleWithRoot.setUseRootElement(true);
- this.bundleWithRoot.init(this.getClass().getClassLoader().getResource(bundleFileName).openStream());
+ conf = new DefaultConfiguration("bundle-conf", "conf");
+ conf.setAttribute(XmlBundle.ConfigurationKeys.LOAD_ON_INIT, "true");
+ conf.setAttribute(XmlBundle.ConfigurationKeys.USE_ROOT, "true");
+ this.bundleWithRoot.configure(conf);
+ this.bundleWithRoot.initialize(this.getClass().getClassLoader().getResource(bundleFileName).openStream());
}
public void testGetString() {
1.5 +9 -0 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.xtest
Index: XmlBundleTestCase.xtest
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/test/XmlBundleTestCase.xtest,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlBundleTestCase.xtest 31 Oct 2001 22:06:08 -0000 1.4
+++ XmlBundleTestCase.xtest 2 Jan 2002 19:04:56 -0000 1.5
@@ -8,10 +8,19 @@
]]></annotation>
<roles>
<role name="org.apache.avalon.excalibur.xml.xpath.XPathProcessor" shorthand="xpath-processor" default-class="org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl"/>
+ <role
+ shorthand="bundle-mapper"
+ name="org.apache.avalon.excalibur.i18n.BundleInfoMapper"
+ default-class="org.apache.avalon.excalibur.i18n.DefaultMapper"
+ />
</roles>
<context/>
<logkit/>
<components>
<xpath-processor/>
+ <bundle-mapper>
+ <prefix>file:///root/path/to/xml/files/</prefix>
+ <suffix>.xml</suffix>
+ </bundle-mapper>
</components>
</testcase>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>