Author: ekoneil
Date: Fri Mar 18 12:44:27 2005
New Revision: 158136
URL: http://svn.apache.org/viewcvs?view=rev&rev=158136
Log:
Fix a bug in BundleMap. The JSP 2.0 EL spec mandates that in order for a map
lookup to be performed on:
${bundle.fooBundle.barMessage}
the call bundle.containsKey("fooBundle") must return true. Apparently,
commons-el doesn't call containsKey and thus this works on Tomcat.
Fixing this in NetUI so that we're spec compliant.
BB: self
DRT: NetUI pass
BVT: NetUI pass
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java?view=diff&r1=158135&r2=158136
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
Fri Mar 18 12:44:27 2005
@@ -35,33 +35,31 @@
import org.apache.beehive.netui.util.logging.Logger;
/**
- * Provide a [EMAIL PROTECTED] java.util.Map} of [EMAIL PROTECTED]
ScriptableBundle} objects that can expose
- * various implementations of [EMAIL PROTECTED] BundleContext.BundleNode} to
expression languages.
+ * Provide a [EMAIL PROTECTED] java.util.Map} of [EMAIL PROTECTED]
ScriptableBundle} objects that can
+ * expose various implementations of [EMAIL PROTECTED]
BundleContext.BundleNode} to
+ * expression languages. <p/> This [EMAIL PROTECTED] java.util.Map}
implementation is
+ * optimized for read as the entrySet() is created lazily. In addition, the
+ * entrySet does not contain all possible ScriptableBundle objects as named
+ * "message-resources" bundles are discovered at runtime and requested by name.
* <p/>
- * This [EMAIL PROTECTED] java.util.Map} implementation is optimized for read
as the entrySet()
- * is created lazily. In addition, the entrySet does not contain all possible
ScriptableBundle
- * objects as named "message-resources" bundles are discovered at runtime and
requested by name.
- * <p/>
- * todo: need to implement Serializable here as this ends up in the request
*/
-public class BundleMap
- extends AbstractScriptableMap {
+public class BundleMap extends AbstractScriptableMap {
private static final Logger LOGGER = Logger.getInstance(BundleMap.class);
private HttpServletRequest _servletRequest = null;
private HttpSession _httpSession = null;
private ServletContext _servletContext = null;
-
private BundleContext _bundleContext = null;
/**
- * Create a BundleMap object that is used for data binding to resource
bundles.
- *
- * @param servletRequest the current [EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest} object
- * @param servletContext a [EMAIL PROTECTED]
javax.servlet.ServletContext} object that facilitates binding to
- * resource bundles declared in Struts modules
- * @param bundleContext optional [EMAIL PROTECTED] BundleContext} object
that describes any existing, data bindable
+ * Create a BundleMap object that is used for data binding to resource
+ * bundles.
+ *
+ * @param servletRequest the current [EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest} object
+ * @param servletContext a [EMAIL PROTECTED] javax.servlet.ServletContext}
object that facilitates binding to resource bundles
+ * declared in Struts modules
+ * @param bundleContext optional [EMAIL PROTECTED] BundleContext} object
that describes any existing, data bindable
* resource bundles
*/
public BundleMap(HttpServletRequest servletRequest, ServletContext
servletContext, BundleContext bundleContext) {
@@ -78,84 +76,103 @@
return _bundleContext;
}
- public Object get(Object name) {
- assert name instanceof String;
- return createScriptableBundle((String)name);
+ public Object get(Object key) {
+ if(key == null)
+ throw new NullPointerException("Bundle data binding does not
accept a null key");
+
+ return createScriptableBundle(key.toString());
}
/**
* Implementation of Map.containsKey for the bundle implicit object.
- *
- * This method is required by JSP 2.0 EL and performs the lookups of
- * the various available bundles which have been registered either
- * explicitly or implicitly.
- *
+ *
+ * This method is required by JSP 2.0 EL and performs the lookups of the
+ * various available bundles which have been registered either explicitly
or
+ * implicitly.
+ *
* @param key The name of a bundle to lookup
* @return <code>true</code> if the bundle is available;
<code>false</code> otherwise
*/
public boolean containsKey(Object key) {
if(key == null)
- return false;
-
- assert key instanceof String;
+ throw new NullPointerException(
+ "Bundle data binding does not accept a null key");
// this logic needs to match the logic used to perform the "get" call
// it is coded twice so that the containsKey call doesn't do extraneous
// object creation and checks only what it needs to
- String name = (String)key;
+ String name = key.toString();
+
if(_bundleContext != null && _bundleContext.containsBundle(name))
return true;
else if(name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME))
return getDefaultStrutsModuleBundle() != null;
else if(_servletContext.getAttribute(name) != null)
return getNamedStrutsModuleBundle(name) != null;
- else return false;
+ else {
+ ModuleConfig moduleConfig = lookupModuleConfig();
+ if(moduleConfig != null) {
+ MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
+ for(int i = 0; i < mrs.length; i++) {
+ if(mrs[i].getKey().equals(name))
+ return true;
+ }
+ }
+ }
+
+ return false;
}
public Set entrySet() {
ArrayList entries = new ArrayList();
- // add BundleNode objects that have been explicitly declared
+ /* add BundleNode objects that have been accessed */
if(_bundleContext != null) {
Iterator iterator = _bundleContext.getBundleNames();
while(iterator.hasNext()) {
- String name = (String)iterator.next();
+ String name =(String) iterator.next();
BundleNode node = _bundleContext.getBundle(name);
entries.add(new Entry(name, node));
}
}
+ MessageResources resources = null;
+
// add the default JPF bundle if one exists
- MessageResources resources = getDefaultStrutsModuleBundle();
+ resources = getDefaultStrutsModuleBundle();
if(resources != null)
entries.add(new Entry(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
-
BundleContext.createBundleNode(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
resources, retrieveUserLocale())));
-
- resources = null;
+
BundleContext.createBundleNode(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
+ resources,
+ retrieveUserLocale())));
ModuleConfig moduleConfig = lookupModuleConfig();
if(moduleConfig != null) {
- MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
+ MessageResourcesConfig[] mrs = moduleConfig
+ .findMessageResourcesConfigs();
for(int i = 0; i < mrs.length; i++) {
- resources = getNamedStrutsModuleBundle(mrs[i].getKey() +
moduleConfig.getPrefix());
- entries.add(new Entry(mrs[i].getKey(),
- BundleContext.createBundleNode(mrs[i].getKey(), resources,
retrieveUserLocale())));
+ String resourceKey = mrs[i].getKey() +
moduleConfig.getPrefix();
+ resources = getNamedStrutsModuleBundle(resourceKey);
+ entries.add(new Entry(mrs[i].getKey(),
+
BundleContext.createBundleNode(mrs[i].getKey(), resources,
+ retrieveUserLocale())));
}
}
- // todo: the named "message-resource" bundles aren't supported here
yet; need a way from the JPF runtime to look them up
-
- return new EntrySet((Entry[])entries.toArray(new Entry[]{}));
+ // todo: the named "message-resource" bundles aren't supported here
yet;
+ // need a way from the JPF runtime to look them up
+ return new EntrySet((Entry[])entries.toArray(new Entry[] {}));
}
private Object createScriptableBundle(String name) {
if(_bundleContext != null && _bundleContext.containsBundle(name)) {
try {
return new ScriptableBundle(name,
_bundleContext.getBundle(name));
- } catch(Exception e) {
- String msg = "Unable to load bundle named \"" + name + "\";
Cause: " + e.getMessage() + ". Cause: " + e;
- if(LOGGER.isErrorEnabled())
- LOGGER.error(msg, e);
+ }
+ catch(Exception e) {
+ String msg = "Unable to load bundle named \"" + name
+ + "\"; Cause: " + e.getMessage() + ". Cause: " + e;
+ LOGGER.error(msg, e);
throw new RuntimeException(msg, e);
}
} else if(name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME)) {
@@ -172,8 +189,7 @@
BundleNode bundleNode = BundleContext.createBundleNode(name,
resources, retrieveUserLocale());
return new ScriptableBundle(name, bundleNode);
}
- }
- else {
+ } else {
ModuleConfig moduleConfig = lookupModuleConfig();
if(moduleConfig != null) {
MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
@@ -183,7 +199,8 @@
if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
continue;
else if(mrs[i].getKey().equals(name)) {
- MessageResources resources =
getNamedStrutsModuleBundle(mrs[i].getKey() + moduleConfig.getPrefix());
+ String resourceKey = mrs[i].getKey() +
moduleConfig.getPrefix();
+ MessageResources resources =
getNamedStrutsModuleBundle(resourceKey);
BundleNode bundleNode =
BundleContext.createBundleNode(name, resources, retrieveUserLocale());
return new ScriptableBundle(name, bundleNode);
}
@@ -195,19 +212,19 @@
String bundleList = createBundleList();
String strutsBundleList = createStrutsBundleList();
- String msg = "The bundle named \"" + name + "\" was not found in the
list of registered bundles with names " +
- bundleList + " or implicit bundle names " + strutsBundleList + ".";
+ String msg = "The bundle named \"" + name + "\" was not found in the
list of registered bundles with names "
+ + bundleList + " or implicit bundle names " +
strutsBundleList + ".";
- if(LOGGER.isErrorEnabled())
- LOGGER.error(msg);
+ LOGGER.error(msg);
throw new RuntimeException(msg);
}
/**
* Lookup the "default" resource bundle for the current Struts module.
- *
- * @return a MessageResources object if a "default" bundle exists.
<code>null</code> otherwise
+ *
+ * @return a MessageResources object if a "default" bundle exists.
+ * <code>null</code> otherwise
*/
private MessageResources getDefaultStrutsModuleBundle() {
Object value = _servletRequest.getAttribute(Globals.MESSAGES_KEY);
@@ -215,18 +232,21 @@
return (MessageResources)value;
else {
if(value != null)
- if(LOGGER.isWarnEnabled())
- LOGGER.warn("Can not resolve the default module bundle." +
- " The object resolved from the request is of type " +
(value != null ? value.getClass().toString() : "null"));
+ LOGGER.warn("Can not resolve the default module bundle."
+ + " The object resolved from the request is
of type "
+ +(value != null ? value.getClass().toString()
+ : "null"));
return null;
}
}
/**
* Lookup a specific resource bundle for the current Struts module.
- *
- * @param name the name of the resource bundle to lookup
- * @return a MessageResources object if a bundle matching the given name
exists. <code>null</code> otherwise.
+ *
+ * @param name
+ * the name of the resource bundle to lookup
+ * @return a MessageResources object if a bundle matching the given name
+ * exists. <code>null</code> otherwise.
*/
private MessageResources getNamedStrutsModuleBundle(String name) {
Object value = _servletContext.getAttribute(name);
@@ -234,21 +254,27 @@
return (MessageResources)value;
else {
if(value != null)
- if(LOGGER.isWarnEnabled())
- LOGGER.warn("Can not resolve module bundle with name \"" +
name +
- "\". The object resolved from ServletContext is of
type " + (value != null ? value.getClass().toString() : "null"));
+ LOGGER.warn("Can not resolve module bundle with name \""
+ + name
+ + "\". The object resolved from
ServletContext is of type "
+ +(value != null ? value.getClass().toString()
+ : "null"));
return null;
}
}
/**
- * Utility method that discovers the [EMAIL PROTECTED] java.util.Locale}
for the current request.
- * <p/>
- *
- * @return the [EMAIL PROTECTED] java.util.Locale} to use when doing
bundle data binding
+ * Utility method that discovers the [EMAIL PROTECTED] java.util.Locale}
for the
+ * current request. <p/>
+ *
+ * @return the [EMAIL PROTECTED] java.util.Locale} to use when doing
bundle data
+ * binding
*/
private final Locale retrieveUserLocale() {
- /* todo: this code is duped in the codebase and needs to be localized
into a utility */
+ /*
+ * todo: this code is duped in the codebase and needs to be localized
+ * into a utility
+ */
String locale = null;
Locale userLocale = null;
@@ -258,11 +284,12 @@
// Only check session if sessions are enabled
if(_httpSession != null) {
- userLocale = (Locale)_httpSession.getAttribute(locale);
+ userLocale =(Locale) _httpSession.getAttribute(locale);
}
if(userLocale == null) {
- // Returns Locale based on Accept-Language header or the server
default
+ // Returns Locale based on Accept-Language header or the server
+ // default
userLocale = _servletRequest.getLocale();
}
@@ -275,7 +302,8 @@
if(_bundleContext != null) {
Iterator iterator = _bundleContext.getBundleNames();
for(int i = 0; iterator.hasNext(); i++) {
- if(i > 0) nameList.append(", ");
+ if(i > 0)
+ nameList.append(", ");
nameList.append(iterator.next().toString());
}
}
@@ -297,8 +325,7 @@
if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
strutsNameList.append("default");
- else
- strutsNameList.append(mrs[i].getKey() +
config.getPrefix());
+ else strutsNameList.append(mrs[i].getKey() +
config.getPrefix());
}
}
}
@@ -313,17 +340,17 @@
/**
* Provide a [EMAIL PROTECTED] java.util.Map} implementation that exposes a
- * [EMAIL PROTECTED]
org.apache.beehive.netui.script.common.BundleContext.BundleNode} object
- * to an expression language as a Map. Access to the values in the map is
by
- * key and depends on the implementation of the BundleNode.
- * <p/>
- * Access is read optimized and the complete entrySet() is only
constructed when needed.
+ * [EMAIL PROTECTED]
org.apache.beehive.netui.script.common.BundleContext.BundleNode}
+ * object to an expression language as a Map. Access to the values in the
+ * map is by key and depends on the implementation of the BundleNode. <p/>
+ * Access is read optimized and the complete entrySet() is only constructed
+ * when needed.
*/
- public class ScriptableBundle
+ public class ScriptableBundle
extends AbstractScriptableMap {
- private BundleNode _bundle = null;
private String _propertiesName = null;
+ private BundleNode _bundle = null;
ScriptableBundle(String propertiesName, BundleNode bundle) {
assert bundle != null;
@@ -337,24 +364,25 @@
ArrayList list = new ArrayList();
Enumeration enumeration = _bundle.getKeys();
while(enumeration.hasMoreElements()) {
- String key = (String)enumeration.nextElement();
+ String key =(String)enumeration.nextElement();
String msg = _bundle.getString(key);
list.add(new Entry(key, msg));
}
- return new EntrySet((Entry[])list.toArray(new Entry[]{}));
+ return new EntrySet((Entry[])list.toArray(new Entry[] {}));
}
- public Object get(Object name) {
- assert name instanceof String;
+ public Object get(Object key) {
+ if(key == null)
+ throw new NullPointerException("Bundle data binding does not
accept a null key");
- String result = _bundle.getString((String)name);
+ String result = _bundle.getString(key.toString());
if(result == null) {
- String msg = "The bundle property name \"" + name + "\" could
not be found in the properties bundle \"" + _propertiesName + "\".";
- if(LOGGER.isErrorEnabled()) LOGGER.error(msg);
+ String msg = "The bundle property name \"" + key + "\" could
not be found in the properties bundle \"" + _propertiesName + "\".";
+ LOGGER.error(msg);
throw new RuntimeException(msg);
- } else
- return result;
+ }
+ else return result;
}
public boolean containsKey(Object key) {
@@ -362,3 +390,4 @@
}
}
}
+
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java?view=diff&r1=158135&r2=158136
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
Fri Mar 18 12:44:27 2005
@@ -208,7 +208,7 @@
else addParam(key, values);
}
- /* todo: -- there are wireup issues here! */
+ /* ensure that there is something created for the grid state model
objects */
if(_state.getSortModel() == null)
_state.setSortModel(_config.createSortModel(null));
if(_state.getFilterModel() == null)