Author: ekoneil
Date: Sun Jan 30 12:35:58 2005
New Revision: 149153
URL: http://svn.apache.org/viewcvs?view=rev&rev=149153
Log:
Add support for inferring the full path to Struts message resource objects.
In the past for explicitly named message bundles, one needed to use the module
path to reference the messages from the "bundle" implicit object. For example:
${bundle.['myresources/foomodule'].messageKey
Now, these are implicitly available via:
${bundle.myresources.messagekey}
Names registered via @Jpf.MessageBundle will be available to pages unless the
names have been overridded by the <netui-data:declareBundle> tag.
Includes simple test.
Also deletes the ContextFactory interface which is no longer used in the
expression language.
BB: self
DRT: NetUI / databinding pass
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf
(with props)
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp
(with props)
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml
(with props)
Removed:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ContextFactory.java
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/BundleMap.java
incubator/beehive/trunk/netui/src/util/build.xml
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
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=149152&r2=149153
==============================================================================
---
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
Sun Jan 30 12:35:58 2005
@@ -26,14 +26,14 @@
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
-import org.apache.beehive.netui.script.common.BundleContext.BundleNode;
-import org.apache.beehive.netui.util.logging.Logger;
-
import org.apache.struts.Globals;
import org.apache.struts.config.MessageResourcesConfig;
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.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.
@@ -47,29 +47,30 @@
public class BundleMap
extends AbstractScriptableMap {
- private static final Logger _logger = Logger.getInstance(BundleMap.class);
+ 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;
- private HttpServletRequest _request = null;
- private HttpSession _session = null;
- private ServletContext _application = null;
/**
* Create a BundleMap object that is used for data binding to resource
bundles.
*
- * @param request the current [EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest} object
- * @param application a [EMAIL PROTECTED] javax.servlet.ServletContext}
object that facilitates binding to
+ * @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 request, ServletContext application,
BundleContext bundleContext) {
- assert request != null;
- assert application != null;
-
- _request = request;
- _session = request.getSession(false);
- _application = application;
+ public BundleMap(HttpServletRequest servletRequest, ServletContext
servletContext, BundleContext bundleContext) {
+ assert servletRequest != null;
+ assert servletContext != null;
+
+ _servletRequest = servletRequest;
+ _httpSession = servletRequest.getSession(false);
+ _servletContext = servletContext;
_bundleContext = bundleContext;
}
@@ -82,6 +83,16 @@
return createScriptableBundle((String)name);
}
+ /**
+ * 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.
+ *
+ * @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;
@@ -96,10 +107,9 @@
return true;
else if(name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME))
return getDefaultStrutsModuleBundle() != null;
- else if(_application.getAttribute(name) != null)
+ else if(_servletContext.getAttribute(name) != null)
return getNamedStrutsModuleBundle(name) != null;
- else
- return false;
+ else return false;
}
public Set entrySet() {
@@ -121,6 +131,18 @@
entries.add(new Entry(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
BundleContext.createBundleNode(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME,
resources, retrieveUserLocale())));
+ resources = null;
+
+ ModuleConfig moduleConfig = lookupModuleConfig();
+ if(moduleConfig != null) {
+ 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())));
+ }
+ }
+
// 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[]{}));
@@ -132,7 +154,8 @@
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);
+ if(LOGGER.isErrorEnabled())
+ LOGGER.error(msg, e);
throw new RuntimeException(msg, e);
}
} else if(name.equals(BundleContext.DEFAULT_STRUTS_BUNDLE_NAME)) {
@@ -142,7 +165,7 @@
BundleNode bundleNode = BundleContext.createBundleNode(name,
resources, retrieveUserLocale());
return new ScriptableBundle(name, bundleNode);
}
- } else if(_application.getAttribute(name) != null) {
+ } else if(_servletContext.getAttribute(name) != null) {
MessageResources resources = getNamedStrutsModuleBundle(name);
if(resources != null) {
@@ -150,6 +173,24 @@
return new ScriptableBundle(name, bundleNode);
}
}
+ else {
+ ModuleConfig moduleConfig = lookupModuleConfig();
+ if(moduleConfig != null) {
+ MessageResourcesConfig[] mrs =
moduleConfig.findMessageResourcesConfigs();
+ if(mrs != null) {
+ for(int i = 0; i < mrs.length; i++) {
+ /* skip the default bundle */
+ if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
+ continue;
+ else if(mrs[i].getKey().equals(name)) {
+ MessageResources resources =
getNamedStrutsModuleBundle(mrs[i].getKey() + moduleConfig.getPrefix());
+ BundleNode bundleNode =
BundleContext.createBundleNode(name, resources, retrieveUserLocale());
+ return new ScriptableBundle(name, bundleNode);
+ }
+ }
+ }
+ }
+ }
String bundleList = createBundleList();
String strutsBundleList = createStrutsBundleList();
@@ -157,7 +198,9 @@
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);
+ if(LOGGER.isErrorEnabled())
+ LOGGER.error(msg);
+
throw new RuntimeException(msg);
}
@@ -167,14 +210,14 @@
* @return a MessageResources object if a "default" bundle exists.
<code>null</code> otherwise
*/
private MessageResources getDefaultStrutsModuleBundle() {
- Object value = _request.getAttribute(Globals.MESSAGES_KEY);
+ Object value = _servletRequest.getAttribute(Globals.MESSAGES_KEY);
if(value instanceof MessageResources)
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() : "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"));
return null;
}
}
@@ -186,14 +229,14 @@
* @return a MessageResources object if a bundle matching the given name
exists. <code>null</code> otherwise.
*/
private MessageResources getNamedStrutsModuleBundle(String name) {
- Object value = _application.getAttribute(name);
+ Object value = _servletContext.getAttribute(name);
if(value instanceof MessageResources)
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() : "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"));
return null;
}
}
@@ -201,11 +244,11 @@
/**
* Utility method that discovers the [EMAIL PROTECTED] java.util.Locale}
for the current request.
* <p/>
- * todo: this code is duped in the codebase and needs to be localized into
a utility
*
* @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 */
String locale = null;
Locale userLocale = null;
@@ -214,13 +257,13 @@
}
// Only check session if sessions are enabled
- if(_session != null) {
- userLocale = (Locale)_session.getAttribute(locale);
+ if(_httpSession != null) {
+ userLocale = (Locale)_httpSession.getAttribute(locale);
}
if(userLocale == null) {
// Returns Locale based on Accept-Language header or the server
default
- userLocale = _request.getLocale();
+ userLocale = _servletRequest.getLocale();
}
return userLocale;
@@ -244,12 +287,13 @@
private final String createStrutsBundleList() {
StringBuilder strutsNameList = new StringBuilder(32);
strutsNameList.append("[");
- ModuleConfig config =
(ModuleConfig)_request.getAttribute(Globals.MODULE_KEY);
+ 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(", ");
+ if(i > 0)
+ strutsNameList.append(", ");
if(mrs[i].getKey().equals(Globals.MESSAGES_KEY))
strutsNameList.append("default");
@@ -263,6 +307,10 @@
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} object
@@ -303,7 +351,7 @@
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);
+ if(LOGGER.isErrorEnabled()) LOGGER.error(msg);
throw new RuntimeException(msg);
} else
return result;
Modified: incubator/beehive/trunk/netui/src/util/build.xml
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/build.xml?view=diff&r1=149152&r2=149153
==============================================================================
--- incubator/beehive/trunk/netui/src/util/build.xml (original)
+++ incubator/beehive/trunk/netui/src/util/build.xml Sun Jan 30 12:35:58 2005
@@ -26,7 +26,7 @@
<ant antfile="${netui.ant.dir}/xmlBean.xml">
<property name="xsd.root.dir" value="${module.dir}/schema/"/>
<property name="class.output.dir"
value="${classes.dir}/${module.name}"/>
- <property name="xbean.inputs"
value="${module.dir}/schema/netui-config/.xsd*"/>
+ <property name="xbean.inputs"
value="${module.dir}/schema/**/*.xsd*"/>
<property name="xbean.output"
value="${build.lib.dir}/${util.jar.name}"/>
</ant>
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf?view=auto&rev=149153
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf
Sun Jan 30 12:35:58 2005
@@ -0,0 +1,43 @@
+/*
+ * 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 databinding.bundle.inferredstruts;
+
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+import org.apache.struts.Globals;
+
[EMAIL PROTECTED](
+ forwards = {
+ @Jpf.Forward(name = "index", path = "index.jsp")
+ },
+ messageBundles = {
+ @Jpf.MessageBundle(
+ bundlePath = "properties.struts.StrutsMessages"),
+ @Jpf.MessageBundle(
+ bundleName = "namedStrutsMessages",
+ bundlePath = "properties.struts.NamedStrutsMessages")
+ })
+public class Controller
+ extends PageFlowController
+{
+ @Jpf.Action()
+ public Forward begin() {
+ return new Forward("index");
+ }
+}
Propchange:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/Controller.jpf
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp?view=auto&rev=149153
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp
Sun Jan 30 12:35:58 2005
@@ -0,0 +1,20 @@
+<%@ page language="java" %>
+<%@ page
import="org.apache.beehive.netui.script.common.BundleMap,org.apache.struts.Globals"%>
+<%@ taglib uri="beehive-netui-tags-html.tld" prefix="netui"%>
+<%@ taglib uri="beehive-netui-tags-databinding.tld" prefix="netui-data"%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <title>Struts Interop i18n Tests</title>
+ </head>
+ <body>
+ <b>Struts Interop i18n Tests</b>
+ <p>
+ default bundle: <netui:span
value="${bundle.default.myStrutsMessage}"/><br/>
+ registered bundle using short-name: <netui:span
value="${bundle.namedStrutsMessages.myStrutsMessage}"/><br/>
+ <br/>
+ <br/>
+ </p>
+ </body>
+</html>
Propchange:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/databinding/bundle/inferredstruts/index.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml?view=diff&r1=149152&r2=149153
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
Sun Jan 30 12:35:58 2005
@@ -1567,6 +1567,20 @@
</features>
</test>
<test>
+ <name>BundleInferredStrutsModuleConfig</name>
+ <description>Test binding to a Struts message resource with the short
name rather than long name.</description>
+ <webapp>coreWeb</webapp>
+ <categories>
+ <category>bvt</category>
+ <category>bvt.struts11</category>
+ <category>drt</category>
+ <category>databinding</category>
+ </categories>
+ <features>
+ <feature>Bundle Binding</feature>
+ </features>
+ </test>
+ <test>
<name>BundleStrutsBinding</name>
<description>Binding to message resources declared in a
JPF</description>
<webapp>coreWeb</webapp>
Added:
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml?view=auto&rev=149153
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml
Sun Jan 30 12:35:58 2005
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ses:recorderSession
xmlns:ses="http://beehive.apache.org/netui/tools/testrecorder/2004/session">
+ <ses:sessionName>BundleInferredStrutsModuleConfig</ses:sessionName>
+ <ses:tester>ekoneil</ses:tester>
+ <ses:startDate>30 Jan 2005, 12:23:34.274 PM MST</ses:startDate>
+ <ses:description>Test that uses the bundle implicit object to reference a
message resource registered in the JPF. The reference is done using the name
only -- the module config path is inferred by the runtime to complete the
bundle name.</ses:description>
+ <ses:tests>
+ <ses:test>
+ <ses:testNumber>1</ses:testNumber>
+ <ses:request>
+ <ses:protocol>HTTP</ses:protocol>
+ <ses:protocolVersion>1.1</ses:protocolVersion>
+ <ses:host>localhost</ses:host>
+ <ses:port>8080</ses:port>
+
<ses:uri>/coreWeb/databinding/bundle/inferredstruts/Controller.jpf</ses:uri>
+ <ses:method>GET</ses:method>
+ <ses:parameters/>
+ <ses:cookies>
+ <ses:cookie>
+ <ses:name>JSESSIONID</ses:name>
+ <ses:value>276212788E3C40E81E47596F77C0DFD5</ses:value>
+ </ses:cookie>
+ </ses:cookies>
+ <ses:headers>
+ <ses:header>
+ <ses:name>accept</ses:name>
+
<ses:value>text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>accept-charset</ses:name>
+ <ses:value>ISO-8859-1,utf-8;q=0.7,*;q=0.7</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>accept-encoding</ses:name>
+ <ses:value>gzip,deflate</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>accept-language</ses:name>
+ <ses:value>en-us,en;q=0.5</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>connection</ses:name>
+ <ses:value>keep-alive</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>cookie</ses:name>
+
<ses:value>JSESSIONID=276212788E3C40E81E47596F77C0DFD5</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>host</ses:name>
+ <ses:value>localhost:8080</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>keep-alive</ses:name>
+ <ses:value>300</ses:value>
+ </ses:header>
+ <ses:header>
+ <ses:name>user-agent</ses:name>
+ <ses:value>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.7.5) Gecko/20041107 Firefox/1.0</ses:value>
+ </ses:header>
+ </ses:headers>
+ </ses:request>
+ <ses:response>
+ <ses:statusCode>200</ses:statusCode>
+ <ses:reason/>
+ <ses:responseBody><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN">
+<html>
+ <head>
+ <title>Struts Interop i18n Tests</title>
+ </head>
+ <body>
+ <b>Struts Interop i18n Tests</b>
+ <p>
+ default bundle: <span>Hello from Struts i18n interop</span><br/>
+ registered bundle using short-name: <span>Hello from Struts i18n interop
that is not the default for this Struts 1.1 module.</span><br/>
+ <br/>
+ <br/>
+ </p>
+ </body>
+</html>]]></ses:responseBody>
+ </ses:response>
+ </ses:test>
+ </ses:tests>
+ <ses:endDate>30 Jan 2005, 12:23:38.780 PM MST</ses:endDate>
+ <ses:testCount>1</ses:testCount>
+</ses:recorderSession>
\ No newline at end of file
Propchange:
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/BundleInferredStrutsModuleConfig.xml
------------------------------------------------------------------------------
svn:eol-style = native