Author: ekoneil
Date: Fri Mar 25 10:43:00 2005
New Revision: 159042
URL: http://svn.apache.org/viewcvs?view=rev&rev=159042
Log:
Cleanup and repackaging in the way that resource bundles are data bound with
${bundle}.
This renames and package scopes some internal classes and clarifies some of the
APIs a bit. Still lots of documentation to do. Also need to cache the Map
wrappers atop the resource bundles where possible.
BB: self
DRT: NetUI pass
BVT: NetUI pass
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java
(with props)
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java
(with props)
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java
(with props)
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java
(with props)
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java
(with props)
Removed:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleContext.java
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/AbstractScriptableMap.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/bundle/DeclareBundle.java
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/BundleScriptTest.java
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/AbstractScriptableMap.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/AbstractScriptableMap.java?view=diff&r1=159041&r2=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/AbstractScriptableMap.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/AbstractScriptableMap.java
Fri Mar 25 10:43:00 2005
@@ -17,19 +17,13 @@
*/
package org.apache.beehive.netui.script.common;
-// java imports
-
-import org.apache.beehive.netui.util.iterator.IteratorFactory;
-
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-// internal imports
-
-// external imports
+import org.apache.beehive.netui.util.iterator.IteratorFactory;
/**
* Base [EMAIL PROTECTED] java.util.Map} implementation that can be used by
@@ -39,9 +33,6 @@
public abstract class AbstractScriptableMap
extends AbstractMap {
- public AbstractScriptableMap() {
- }
-
/**
* Default implementation of a [EMAIL PROTECTED] java.util.Set} that can
be returned by the
* entrySet method of [EMAIL PROTECTED] java.util.Map}. This
implementation simply takes an
@@ -61,7 +52,7 @@
}
public int size() {
- return (_entries != null ? _entries.length : 0);
+ return _entries != null ? _entries.length : 0;
}
public boolean add(Object object) {
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=159041&r2=159042
==============================================================================
---
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 25 10:43:00 2005
@@ -22,6 +22,8 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
@@ -31,26 +33,31 @@
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.MessageResources;
-import org.apache.beehive.netui.script.common.BundleContext.BundleNode;
+import org.apache.beehive.netui.script.common.bundle.BundleNode;
+import org.apache.beehive.netui.script.common.bundle.BundleNodeFactory;
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
+ * Provide a [EMAIL PROTECTED] java.util.Map} of [EMAIL PROTECTED]
BundleNodeMap} objects that can
+ * expose various implementations of [EMAIL PROTECTED] 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
+ * entrySet does not contain all possible BundleNodeMap objects as named
* "message-resources" bundles are discovered at runtime and requested by name.
* <p/>
*/
-public class BundleMap extends AbstractScriptableMap {
+public class BundleMap
+ extends AbstractScriptableMap {
+
+ public static final String DEFAULT_STRUTS_BUNDLE_NAME = "default";
private static final Logger LOGGER = Logger.getInstance(BundleMap.class);
+ private HashMap _registeredBundles = null;
+
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
@@ -59,28 +66,42 @@
* @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) {
+ public BundleMap(HttpServletRequest servletRequest, ServletContext
servletContext) {
assert servletRequest != null;
assert servletContext != null;
_servletRequest = servletRequest;
_httpSession = servletRequest.getSession(false);
_servletContext = servletContext;
- _bundleContext = bundleContext;
+
+ _registeredBundles = new HashMap();
}
- public BundleContext getBundleContext() {
- return _bundleContext;
+ public void registerResourceBundle(String name, String resourcePath,
Locale forcedLocale) {
+ if(_registeredBundles == null)
+ _registeredBundles = new HashMap();
+
+ if(_registeredBundles.containsKey(name))
+ LOGGER.info("The bundle map already contains a key \"" + name +
"\" overwriting the previous value.");
+
+ Locale locale = (forcedLocale != null ? forcedLocale :
Locale.getDefault());
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(resourcePath,
locale);
+ BundleNode bundle =
BundleNodeFactory.getInstance().getResourceBundleNode(name, resourceBundle,
locale);
+ _registeredBundles.put(name, bundle);
}
public Object get(Object key) {
if(key == null)
- throw new NullPointerException("Bundle data binding does not
accept a null key");
+ throw new NullPointerException("Binding to a resource bundle does
not accept a null key");
- return createScriptableBundle(key.toString());
+ BundleNodeMap map = lookupScriptableBundle(key.toString());
+ if(map == null) {
+ /* handleBundleNotFound will throw an exception when the message
key isn't found */
+ handleBundleNotFound(key.toString());
+ return null;
+ }
+ else return map;
}
/**
@@ -95,102 +116,68 @@
*/
public boolean containsKey(Object key) {
if(key == null)
- 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 = 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 {
- 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;
- }
- }
- }
+ throw new NullPointerException("Binding to a resource bundle does
not accept a null key");
- return false;
+ BundleNodeMap map = lookupScriptableBundle(key.toString());
+ return map != null;
}
public Set entrySet() {
ArrayList entries = new ArrayList();
- /* add BundleNode objects that have been accessed */
- if(_bundleContext != null) {
- Iterator iterator = _bundleContext.getBundleNames();
+ /* add BundleNode objects that have been accessed */
+ if(_registeredBundles != null) {
+ Iterator iterator = _registeredBundles.keySet().iterator();
while(iterator.hasNext()) {
- String name =(String) iterator.next();
- BundleNode node = _bundleContext.getBundle(name);
- entries.add(new Entry(name, node));
+ Object key = iterator.next();
+ entries.add(new BundleNodeEntry(key));
}
}
MessageResources resources = null;
- // add the default JPF bundle if one exists
- resources = getDefaultStrutsModuleBundle();
+ resources = lookupDefaultStrutsBundle();
if(resources != null)
- entries.add(new Entry(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
-
BundleContext.createBundleNode(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
- resources,
- retrieveUserLocale())));
+ entries.add(new BundleNodeEntry(DEFAULT_STRUTS_BUNDLE_NAME));
- ModuleConfig moduleConfig = lookupModuleConfig();
+ ModuleConfig moduleConfig = lookupCurrentModuleConfig();
if(moduleConfig != null) {
- MessageResourcesConfig[] mrs = moduleConfig
- .findMessageResourcesConfigs();
+ MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
for(int i = 0; i < mrs.length; i++) {
String resourceKey = mrs[i].getKey() +
moduleConfig.getPrefix();
- resources = getNamedStrutsModuleBundle(resourceKey);
- entries.add(new Entry(mrs[i].getKey(),
-
BundleContext.createBundleNode(mrs[i].getKey(), resources,
- retrieveUserLocale())));
+ resources = lookupStrutsBundle(resourceKey);
+ entries.add(new BundleNodeEntry(mrs[i].getKey()));
}
}
- // 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;
- LOGGER.error(msg, e);
- throw new RuntimeException(msg, e);
- }
- } else if(name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME)) {
- MessageResources resources = getDefaultStrutsModuleBundle();
+ /*
+ */
+ private BundleNodeMap lookupScriptableBundle(String name) {
+ BundleNodeMap map = null;
+ /* check to see if the bundle was explicitly registered */
+ if(_registeredBundles != null && _registeredBundles.containsKey(name))
{
+ map = new BundleNodeMap(name,
(BundleNode)_registeredBundles.get(name));
+ }
+ else if(name.equals(DEFAULT_STRUTS_BUNDLE_NAME)) {
+ MessageResources resources = lookupDefaultStrutsBundle();
if(resources != null) {
- BundleNode bundleNode = BundleContext.createBundleNode(name,
resources, retrieveUserLocale());
- return new ScriptableBundle(name, bundleNode);
+ BundleNode bundleNode =
BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources,
retrieveUserLocale());
+ map = new BundleNodeMap(name, bundleNode);
}
- } else if(_servletContext.getAttribute(name) != null) {
- MessageResources resources = getNamedStrutsModuleBundle(name);
-
+ }
+ else if(_servletContext.getAttribute(name) != null) {
+ MessageResources resources = lookupStrutsBundle(name);
if(resources != null) {
- BundleNode bundleNode = BundleContext.createBundleNode(name,
resources, retrieveUserLocale());
- return new ScriptableBundle(name, bundleNode);
+ BundleNode bundleNode =
BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources,
retrieveUserLocale());
+ map = new BundleNodeMap(name, bundleNode);
}
- } else {
- ModuleConfig moduleConfig = lookupModuleConfig();
+ }
+ else {
+ ModuleConfig moduleConfig = lookupCurrentModuleConfig();
if(moduleConfig != null) {
MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
if(mrs != null) {
@@ -200,33 +187,26 @@
continue;
else if(mrs[i].getKey().equals(name)) {
String resourceKey = mrs[i].getKey() +
moduleConfig.getPrefix();
- MessageResources resources =
getNamedStrutsModuleBundle(resourceKey);
- BundleNode bundleNode =
BundleContext.createBundleNode(name, resources, retrieveUserLocale());
- return new ScriptableBundle(name, bundleNode);
+ MessageResources resources =
lookupStrutsBundle(resourceKey);
+ BundleNode bundleNode =
BundleNodeFactory.getInstance().getStrutsBundleNode(name, resources,
retrieveUserLocale());
+ map = new BundleNodeMap(name, bundleNode);
+ break;
}
}
}
}
}
- 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 + ".";
-
- LOGGER.error(msg);
-
- throw new RuntimeException(msg);
+ return map;
}
/**
* Lookup the "default" resource bundle for the current Struts module.
- *
+ *
* @return a MessageResources object if a "default" bundle exists.
* <code>null</code> otherwise
*/
- private MessageResources getDefaultStrutsModuleBundle() {
+ private MessageResources lookupDefaultStrutsBundle() {
Object value = _servletRequest.getAttribute(Globals.MESSAGES_KEY);
if(value instanceof MessageResources)
return (MessageResources)value;
@@ -234,8 +214,7 @@
if(value != 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"));
+ +(value != null ? value.getClass().toString()
: "null"));
return null;
}
}
@@ -248,25 +227,85 @@
* @return a MessageResources object if a bundle matching the given name
* exists. <code>null</code> otherwise.
*/
- private MessageResources getNamedStrutsModuleBundle(String name) {
+ private MessageResources lookupStrutsBundle(String name) {
Object value = _servletContext.getAttribute(name);
if(value instanceof MessageResources)
return (MessageResources)value;
else {
if(value != null)
- LOGGER.warn("Can not resolve module bundle with name \""
- + name
+ LOGGER.warn("Can not resolve module bundle with name \"" + name
+ "\". The object resolved from
ServletContext is of type "
- +(value != null ? value.getClass().toString()
- : "null"));
+ +(value != null ? value.getClass().toString()
: "null"));
return null;
}
}
+ private final ModuleConfig lookupCurrentModuleConfig() {
+ return (ModuleConfig)_servletRequest.getAttribute(Globals.MODULE_KEY);
+ }
+
+ private void handleBundleNotFound(String name) {
+
+ /* At this point, no message bundle could be found. Throw an error
that contains a
+ descriptive message about the bundles that are available
+ */
+ String registeredBundles = formatBundleNames(createBundleList());
+ String strutsBundles = formatBundleNames(createStrutsBundleList());
+
+ String msg = "The bundle named \"" + name + "\" was not found in the
list of registered bundles with names "
+ + registeredBundles + " or implicit bundle names " +
strutsBundles + ".";
+
+ LOGGER.error(msg);
+ throw new RuntimeException(msg);
+ }
+
+ private final String formatBundleNames(String[] names) {
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("[");
+ for(int i = 0; i < names.length; i++) {
+ if(i > 0)
+ sb.append(", ");
+ sb.append(names[i]);
+ }
+ sb.append("]");
+
+ return sb.toString();
+ }
+
+ private final String[] createBundleList() {
+ String[] names = null;
+ if(_registeredBundles != null) {
+ names = new String[_registeredBundles.size()];
+ Iterator iterator = _registeredBundles.keySet().iterator();
+ for(int i = 0; iterator.hasNext(); i++) {
+ names[i] = iterator.next().toString();
+ }
+ }
+
+ return names;
+ }
+
+ private final String[] createStrutsBundleList() {
+ String[] names = null;
+ ModuleConfig config = lookupCurrentModuleConfig();
+ if(config != null) {
+ MessageResourcesConfig[] mrs =
config.findMessageResourcesConfigs();
+ names = new String[mrs.length];
+ if(mrs != null) {
+ for(int i = 0; i < mrs.length; i++) {
+ if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
+ names[i] = DEFAULT_STRUTS_BUNDLE_NAME;
+ else names[i] = mrs[i].getKey() + config.getPrefix();
+ }
+ }
+ }
+ return names;
+ }
+
/**
* 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
*/
@@ -275,81 +314,52 @@
String locale = null;
Locale userLocale = null;
- if(locale == null) {
+ if(locale == null)
locale = Globals.LOCALE_KEY;
- }
// Only check session if sessions are enabled
- if(_httpSession != null) {
+ if(_httpSession != null)
userLocale =(Locale) _httpSession.getAttribute(locale);
- }
- if(userLocale == null) {
+ if(userLocale == null)
// Returns Locale based on Accept-Language header or the server
// default
userLocale = _servletRequest.getLocale();
- }
return userLocale;
}
- private final String createBundleList() {
- StringBuilder nameList = new StringBuilder(32);
- nameList.append("[");
- if(_bundleContext != null) {
- Iterator iterator = _bundleContext.getBundleNames();
- for(int i = 0; iterator.hasNext(); i++) {
- if(i > 0)
- nameList.append(", ");
- nameList.append(iterator.next().toString());
- }
+ final class BundleNodeEntry
+ extends Entry
+ {
+ BundleNodeEntry(Object key) {
+ super(key, null);
}
- nameList.append("]");
-
- return nameList.toString();
- }
- private final String createStrutsBundleList() {
- StringBuilder strutsNameList = new StringBuilder(32);
- strutsNameList.append("[");
- ModuleConfig config = lookupModuleConfig();
- if(config != null) {
- MessageResourcesConfig[] mrs =
config.findMessageResourcesConfigs();
- if(mrs != null) {
- for(int i = 0; i < mrs.length; i++) {
- if(i > 0)
- strutsNameList.append(", ");
+ public Object getValue() {
+ assert getKey() instanceof String;
- if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
- strutsNameList.append("default");
- else strutsNameList.append(mrs[i].getKey() +
config.getPrefix());
- }
- }
+ String key = (String)getKey();
+ return lookupScriptableBundle(key);
}
- strutsNameList.append("]");
-
- return strutsNameList.toString();
- }
-
- private ModuleConfig lookupModuleConfig() {
- return (ModuleConfig)_servletRequest.getAttribute(Globals.MODULE_KEY);
}
/**
* Provide a [EMAIL PROTECTED] java.util.Map} implementation that exposes a
- * [EMAIL PROTECTED]
org.apache.beehive.netui.script.common.BundleContext.BundleNode}
+ * [EMAIL PROTECTED]
org.apache.beehive.netui.script.common.bundle.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
+ final class BundleNodeMap
extends AbstractScriptableMap {
private String _propertiesName = null;
private BundleNode _bundle = null;
+ private Set _entrySet = null;
- ScriptableBundle(String propertiesName, BundleNode bundle) {
+ BundleNodeMap(String propertiesName, BundleNode bundle) {
assert bundle != null;
assert propertiesName != null;
@@ -358,14 +368,18 @@
}
public Set entrySet() {
- ArrayList list = new ArrayList();
- Enumeration enumeration = _bundle.getKeys();
- while(enumeration.hasMoreElements()) {
- String key =(String)enumeration.nextElement();
- String msg = _bundle.getString(key);
- list.add(new Entry(key, msg));
+ if(_entrySet == null) {
+ ArrayList list = new ArrayList();
+ Enumeration enumeration = _bundle.getKeys();
+ while(enumeration.hasMoreElements()) {
+ String key =(String)enumeration.nextElement();
+ String msg = _bundle.getString(key);
+ list.add(new Entry(key, msg));
+ }
+ _entrySet = new EntrySet((Entry[])list.toArray(new Entry[]
{}));
}
- return new EntrySet((Entry[])list.toArray(new Entry[] {}));
+
+ return _entrySet;
}
public Object get(Object key) {
@@ -373,17 +387,18 @@
throw new NullPointerException("Bundle data binding does not
accept a null key");
String result = _bundle.getString(key.toString());
-
if(result == null) {
String msg = "The bundle property name \"" + key + "\" could
not be found in the properties bundle \"" + _propertiesName + "\".";
LOGGER.error(msg);
- throw new RuntimeException(msg);
+ throw new IllegalArgumentException(msg);
}
else return result;
}
public boolean containsKey(Object key) {
- return _bundle.getString(key.toString()) != null;
+ if(key == null)
+ return false;
+ else return _bundle.getString(key.toString()) != null;
}
}
}
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java?view=diff&r1=159041&r2=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
Fri Mar 25 10:43:00 2005
@@ -167,7 +167,7 @@
}
// @todo: need to move bundleMap creation to a BundleMapFactory
- BundleMap bundleMap = new BundleMap(request, servletContext, null);
+ BundleMap bundleMap = new BundleMap(request, servletContext);
loadBundleMap(request, bundleMap);
}
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java?view=auto&rev=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java
(added)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java
Fri Mar 25 10:43:00 2005
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.script.common.bundle;
+
+import java.util.Locale;
+import java.util.Enumeration;
+
+/**
+ */
+public abstract class BundleNode {
+
+ public abstract boolean containsKey(String key);
+
+ public abstract String getString(String key);
+
+ public abstract Enumeration getKeys();
+}
Propchange:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java?view=auto&rev=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java
(added)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java
Fri Mar 25 10:43:00 2005
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.script.common.bundle;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.apache.struts.util.MessageResources;
+
+/**
+ *
+ */
+public class BundleNodeFactory {
+
+ private static final BundleNodeFactory FACTORY = new BundleNodeFactory();
+
+ public static final BundleNodeFactory getInstance() {
+ return FACTORY;
+ }
+
+ private BundleNodeFactory() {}
+
+ public final BundleNode getStrutsBundleNode(String name, MessageResources
messageResources, Locale locale) {
+ return new StrutsBundleNode(locale, messageResources);
+ }
+
+ public final BundleNode getResourceBundleNode(String name, ResourceBundle
resourceBundle, Locale locale) {
+ return new ResourceBundleNode(resourceBundle);
+ }
+}
Propchange:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/BundleNodeFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java?view=auto&rev=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java
(added)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java
Fri Mar 25 10:43:00 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.script.common.bundle;
+
+import java.util.ResourceBundle;
+import java.util.Locale;
+import java.util.Enumeration;
+
+import org.apache.beehive.netui.script.common.bundle.BundleNode;
+
+/**
+ */
+class ResourceBundleNode
+ extends BundleNode {
+
+ private ResourceBundle _bundle;
+
+ ResourceBundleNode(ResourceBundle resourceBundle) {
+ _bundle = resourceBundle;
+ }
+
+ public boolean containsKey(String key) {
+ if(_bundle == null)
+ return false;
+ else return _bundle.getString(key) != null;
+ }
+
+ public String getString(String key) {
+ if(_bundle == null)
+ return null;
+ else return _bundle.getString(key);
+ }
+
+ public Enumeration getKeys() {
+ if(_bundle == null)
+ return null;
+ else return _bundle.getKeys();
+ }
+}
Propchange:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/ResourceBundleNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java?view=auto&rev=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java
(added)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java
Fri Mar 25 10:43:00 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.script.common.bundle;
+
+import java.util.Locale;
+import java.util.Enumeration;
+
+import org.apache.beehive.netui.script.common.bundle.BundleNode;
+import org.apache.struts.util.MessageResources;
+
+/**
+ */
+class StrutsBundleNode
+ extends BundleNode {
+
+ private Locale _locale;
+ private MessageResources _messageResource;
+
+ StrutsBundleNode(Locale locale, MessageResources messageResource) {
+ _locale = locale;
+ _messageResource = messageResource;
+ }
+
+ public boolean containsKey(String key) {
+ return _messageResource.getMessage(_locale, key) != null;
+ }
+
+ public String getString(String key) {
+ return _messageResource.getMessage(_locale, key);
+ }
+
+ public Enumeration getKeys() {
+ throw new UnsupportedOperationException("The getKeys() method is not
supported on the MessageResources type.");
+ }
+}
Propchange:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/bundle/StrutsBundleNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/bundle/DeclareBundle.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/bundle/DeclareBundle.java?view=diff&r1=159041&r2=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/bundle/DeclareBundle.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/bundle/DeclareBundle.java
Fri Mar 25 10:43:00 2005
@@ -19,7 +19,6 @@
import org.apache.beehive.netui.tags.AbstractClassicTag;
import org.apache.beehive.netui.util.Bundle;
-import org.apache.beehive.netui.script.common.BundleContext;
import org.apache.beehive.netui.script.common.BundleMap;
import javax.servlet.jsp.JspException;
@@ -41,8 +40,8 @@
* files that are accessed are located in the package
<code>com/foobar/resources</code> with the root
* properties file name of <code>WebAppMessages</code>. The naming
conventions for properties can be found
* in [EMAIL PROTECTED] java.util.ResourceBundle#getBundle(String, Locale,
ClassLoader)}. These files must be located
- * in a classpath that is available to the web application. Often, they are
stored in
- * <code>WEB-INF/classes</code>. If the properties file contains a key called
<code>helloWorld</code>,
+ * in a classpath that is available to the web application; often, this is
WEB-INF/classes.
+ * If the properties file contains a key called <code>helloWorld</code>,
* then the expression <code>{bundle.someMessages.helloWorld}</code>
* would be look-up the message matching the Locale specified on the tag.
Bundle binding expressions can be
* used in any expression bindable NetUI tag attribute.</p>
@@ -289,7 +288,21 @@
*/
public int doEndTag()
throws JspException {
- verifyAttributes();
+
+ if(_name.length() == 0) {
+ String msg =
Bundle.getErrorString("Tags_DeclareBundle_invalidName", new Object[]{_name});
+ registerTagError(msg, null);
+ }
+
+ if(_name.equals(BundleMap.DEFAULT_STRUTS_BUNDLE_NAME)) {
+ String msg =
Bundle.getErrorString("Tags_DeclareBundle_defaultIsReservedWord", null);
+ registerTagError(msg, null);
+ }
+
+ if(_bundlePath.length() == 0) {
+ String msg =
Bundle.getErrorString("Tags_DeclareBundle_invalidResourcePath", new
Object[]{_bundlePath});
+ registerTagError(msg, null);
+ }
Locale locale = getCurrentLocale();
@@ -298,26 +311,24 @@
return EVAL_PAGE;
}
+ BundleMap bundleMap = null;
Object obj = pageContext.getAttribute("bundle");
if(obj == null) {
- BundleContext bc = new BundleContext();
- bc.addBundle(_name, _bundlePath, locale);
-
// NetUI v2 -- in JSP 2.0 EL, the BundleMap is dropped into the
PageContext so that
// it's available to the EL runtime.
- BundleMap bundleMap = new
BundleMap((HttpServletRequest)pageContext.getRequest(),
pageContext.getServletContext(), bc);
+ bundleMap = new
BundleMap((HttpServletRequest)pageContext.getRequest(),
pageContext.getServletContext());
pageContext.setAttribute("bundle", bundleMap);
- } else if(obj != null && obj instanceof BundleMap) {
- BundleMap bundleMap = (BundleMap)obj;
- BundleContext bc = bundleMap.getBundleContext();
- bc.addBundle(_name, _bundlePath, locale);
- } else {
+ }
+ else if(!(obj instanceof BundleMap)) {
String msg =
Bundle.getErrorString("Tags_DeclareBundle_wrongContextType", new
Object[]{obj.getClass().getName()});
registerTagError(msg, null);
+ if(hasErrors())
+ reportErrors();
+ return EVAL_PAGE;
}
+ else bundleMap = (BundleMap)obj;
- if(hasErrors())
- reportErrors();
+ bundleMap.registerResourceBundle(_name, _bundlePath, locale);
return EVAL_PAGE;
}
@@ -362,23 +373,5 @@
}
return getUserLocale();
- }
-
- private void verifyAttributes()
- throws JspException {
- if(_name.length() == 0) {
- String msg =
Bundle.getErrorString("Tags_DeclareBundle_invalidName", new Object[]{_name});
- registerTagError(msg, null);
- }
-
- if(_name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME)) {
- String msg =
Bundle.getErrorString("Tags_DeclareBundle_defaultIsReservedWord", null);
- registerTagError(msg, null);
- }
-
- if(_bundlePath.length() == 0) {
- String msg =
Bundle.getErrorString("Tags_DeclareBundle_invalidResourcePath", new
Object[]{_bundlePath});
- registerTagError(msg, null);
- }
}
}
Added:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java?view=auto&rev=159042
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java
(added)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java
Fri Mar 25 10:43:00 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.tags.databinding.datagrid;
+
+import javax.servlet.jsp.JspContext;
+
+import org.apache.beehive.netui.tags.AbstractSimpleTag;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfig;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridStateFactory;
+import org.apache.beehive.netui.databinding.datagrid.api.DataGridState;
+
+/**
+ * @netui:tag name="getDataGridState"
+ * description="Get a DataGridState object and add it to the PageContext under
a given variable name "
+ * body-content="scriptless"
+ * @netui.tldx:tag whitespace="indent"
+ */
+public class GetDataGridState
+ extends AbstractSimpleTag {
+
+ private String _var = null;
+ private String _name = null;
+ private DataGridConfig _config = null;
+
+ public final String getTagName() {
+ return "getDataGridStateService";
+ }
+
+ /**
+ * @netui:attribute name="name"
+\ */
+ public void setGridName(String name) {
+ _name = name;
+ }
+
+ /**
+ * @netui:attribute name="var"
+ */
+ public void setVar(String var) {
+ _var = var;
+ }
+
+ /**
+ * @netui:attribute name="name"
+\ */
+ public void setDataGridConfig(DataGridConfig config) {
+ _config = config;
+ }
+
+ public void doTag() {
+ JspContext jspContext = getJspContext();
+ DataGridStateFactory factory =
DataGridStateFactory.getInstance(getJspContext());
+ DataGridState state = null;
+ if(_config != null)
+ state = factory.getDataGridState(_name, _config);
+ else state = factory.getDataGridState(_name);
+
+ jspContext.setAttribute(_var, state);
+ }
+}
Propchange:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/GetDataGridState.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/BundleScriptTest.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/BundleScriptTest.java?view=diff&r1=159041&r2=159042
==============================================================================
---
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/BundleScriptTest.java
(original)
+++
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/BundleScriptTest.java
Fri Mar 25 10:43:00 2005
@@ -20,7 +20,6 @@
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
-import org.apache.beehive.netui.script.common.BundleContext;
import org.apache.beehive.netui.script.common.BundleMap;
/**
@@ -29,16 +28,18 @@
public abstract class BundleScriptTest
extends AbstractExpressionTest {
+ private BundleMap createBundleMap() {
+ return new BundleMap((HttpServletRequest)getPageContext().getRequest(),
+ getPageContext().getServletContext());
+ }
+
public void testSimple()
throws Exception {
- BundleContext bc = createBundleContext();
- BundleMap bundleMap = new
BundleMap((HttpServletRequest)getPageContext().getRequest(),
- getPageContext().getServletContext(),
- bc);
+ BundleMap bundleMap = createBundleMap();
getPageContext().setAttribute("bundle", bundleMap);
- bc.addBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1");
- bc.addBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2");
+ bundleMap.registerResourceBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1", null);
+ bundleMap.registerResourceBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2", null);
String val = (String)evaluateExpression("{bundle.bundle1.simpleKey}",
getPageContext());
assertEquals("This is a simple message.", val);
@@ -50,14 +51,10 @@
public void testLocaleSupport()
throws Exception {
Locale germany = Locale.GERMAN;
- BundleContext bc = createBundleContext();
+ BundleMap bundleMap = createBundleMap();
+ bundleMap.registerResourceBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1", germany);
+ bundleMap.registerResourceBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2", null);
- bc.addBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1", germany);
- bc.addBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2");
-
- BundleMap bundleMap = new
BundleMap((HttpServletRequest)getPageContext().getRequest(),
- getPageContext().getServletContext(),
- bc);
getPageContext().setAttribute("bundle", bundleMap);
String val = (String)evaluateExpression("{bundle.bundle1.localHello}",
getPageContext());
@@ -77,28 +74,21 @@
*/
public void testToString()
throws Exception {
- BundleContext bc = createBundleContext();
- BundleMap bundleMap = new
BundleMap((HttpServletRequest)getPageContext().getRequest(),
- getPageContext().getServletContext(),
- bc);
+ BundleMap bundleMap = createBundleMap();
+
// toString an empty map
System.out.println("budleMap.toString(): " + bundleMap.toString());
getPageContext().setAttribute("bundle", bundleMap);
- bc.addBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1");
- bc.addBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2");
+ bundleMap.registerResourceBundle("bundle1",
"org/apache/beehive/netui/test/databinding/testdata/bundle1", null);
+ bundleMap.registerResourceBundle("bundle2",
"org/apache/beehive/netui/test/databinding/testdata/bundle2", null);
String val = (String)evaluateExpression("{bundle.bundle1.simpleKey}",
getPageContext());
assertEquals("This is a simple message.", val);
// toString a BundleMap that has bundles
System.out.println("bundleMap.toString(): " + bundleMap.toString());
- }
-
- private BundleContext createBundleContext()
- throws Exception {
- return new BundleContext();
}
public BundleScriptTest(String name) {