Author: xlawrence
Date: Wed Jun 27 16:35:06 2007
New Revision: 17807
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17807&repname=
=3Djahia
Log:
Backport improvement on the way getting messages (WAI)
Modified:
trunk/core/src/java/org/jahia/taglibs/resourcebundle/MessageTag.java
Modified: trunk/core/src/java/org/jahia/taglibs/resourcebundle/MessageTag.j=
ava
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/taglibs/resourcebundle/MessageTag.java&rev=3D17807&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/taglibs/resourcebundle/MessageTag.java (o=
riginal)
+++ trunk/core/src/java/org/jahia/taglibs/resourcebundle/MessageTag.java We=
d Jun 27 16:35:06 2007
@@ -14,7 +14,8 @@
* 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.
- */package org.jahia.taglibs.resourcebundle;
+ */
+package org.jahia.taglibs.resourcebundle;
=
import java.io.IOException;
import java.text.MessageFormat;
@@ -33,58 +34,53 @@
=
/**
* Support for Jahia Message ResourceBundle within Jahia
- *
+ * <p/>
* Returns the requested resource.
*
- * @see JahiaResourceBundle
- * @see SetAdminResourceBundleTag
- * @see JahiaEnginesResources.properties
- *
* @author Khue Nguyen
- *
- *
* @jsp:tag name=3D"message" body-content=3D"empty"
* description=3D"display a specific value in a resource bundle and format=
s it using
* <a href=3D'http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFor=
mat.html' target=3D'tagFrame'>java.text.MessageFormat</a>.
- *
+ * <p/>
* <p><attriInfo>Lowest level support for resource bundle messages. This i=
s inspired by the Struts bean message tag
* except that it checks a session variable (org.jahia.services.multilang.=
currentlocale) to
* determine if a Locale has been chosen.
- *
+ * <p/>
* <p>The value lookup is done in the 'JahiaMessageResources.properties' r=
esource bundle.
- *
+ * <p/>
* <p>Similar in functionality to <a href=3D'resourceBundle.html' target=
=3D'tagFrame'>content:resourceBundle</a>.
- *
- *
+ * <p/>
+ * <p/>
* <p><b>Example 1 :</b>
- * <p>
+ * <p/>
* <logic:present name=3D\"engineMessages\"> <br>
-<div id=3D\"errors\"> <br>
- <content:resourceBundle resourceBundle=3D\"jahiatemplates.=
Corporate_portal_templates\" resourceName=3D\"mySettingsErrors\"/> : <=
;br/> <br>
- <ul> <br>
- <logic:iterate name=3D\"engineMessages\" property=3D\"mess=
ages\" id=3D\"curMessage\"> <br>
- <li><content:message name=3D\"curMessage=
\"/></li> <br>
- </logic:iterate> <br>
- </ul> <br>
-</div><br>
-</logic:present> <br>
- *
+ * <div id=3D\"errors\"> <br>
+ * <content:resourceBundle resourceBundle=3D\"jahiatemplate=
s.Corporate_portal_templates\" resourceName=3D\"mySettingsErrors\"/> : &=
lt;br/> <br>
+ * <ul> <br>
+ * <logic:iterate name=3D\"engineMessages\" property=3D\"me=
ssages\" id=3D\"curMessage\"> <br>
+ * <li><content:message name=3D\"curMessa=
ge\"/></li> <br>
+ * </logic:iterate> <br>
+ * </ul> <br>
+ * </div><br>
+ * </logic:present> <br>
+ * <p/>
* <p>The above example takes all the EngineMessage objects in EngineMessa=
ges and displays them using the content:message tag. The
* EngineMessages is instanciated when Jahia detects an error.
- *
+ * <p/>
* <p><b>Example 2 :</b>
- * <p>
+ * <p/>
* <content:message key=3D\"org.jahia.bin.JahiaConfigurationWizard.root=
.adminUserName.label\" />
- *
+ * <p/>
* </attriInfo>"
+ * @see JahiaResourceBundle
+ * see SetAdminResourceBundleTag
+ * see JahiaEnginesResources.properties
*/
public class MessageTag extends TagSupport {
=
- private static org.apache.log4j.Logger logger =3D
+ private static final org.apache.log4j.Logger logger =3D
org.apache.log4j.Logger.getLogger(MessageTag.class);
=
- private static final String CLASS_NAME =3D MessageTag.class.getName();
-
private String key =3D null;
private String name =3D null;
private boolean display =3D true;
@@ -93,7 +89,7 @@
/**
* @jsp:attribute name=3D"key" required=3D"false" rtexprvalue=3D"true"
* description=3D"the key of the resource to fetch in the resource bun=
dle.
- *
+ * <p/>
* <p><attriInfo>If it is defined, all other attributes are ignored.
* </attriInfo>"
*/
@@ -107,7 +103,7 @@
/**
* @jsp:attribute name=3D"name" required=3D"false" rtexprvalue=3D"true"
* description=3D"name of the pageContext attribute which holds the be=
an to fetch and display.
- *
+ * <p/>
* <p><attriInfo>
* </attriInfo>"
*/
@@ -138,50 +134,34 @@
=
public int doStartTag () {
=
- HttpServletRequest request =3D (HttpServletRequest) pageContext.
- getRequest();
+ HttpServletRequest request =3D (HttpServletRequest) pageContext.ge=
tRequest();
String resValue =3D null;
=
Locale currentLocale =3D request.getLocale();
HttpSession session =3D pageContext.getSession();
if (session !=3D null) {
if (session.getAttribute(ProcessingContext.SESSION_LOCALE) !=
=3D null) {
- currentLocale =3D (Locale) session.getAttribute(Processing=
Context.
- SESSION_LOCALE);
+ currentLocale =3D (Locale) session.getAttribute(Processing=
Context.SESSION_LOCALE);
}
}
=
try {
-
- String keyName =3D null;
if (key !=3D null) {
- resValue =3D JahiaResourceBundle
- .getMessageResource(key,
- currentLocale);
+ resValue =3D JahiaResourceBundle.getMessageResource(key, c=
urrentLocale);
} else if (name !=3D null) {
- EngineMessage message =3D (EngineMessage) pageContext.
- findAttribute(name);
+ EngineMessage message =3D (EngineMessage) pageContext.find=
Attribute(name);
if (message !=3D null) {
- String keyValue =3D JahiaResourceBundle
- .getMessageResource(message.getKey(),
- currentLocale);
+ String keyValue =3D JahiaResourceBundle.getMessageReso=
urce(message.getKey(), currentLocale);
if (keyValue !=3D null && message.getValues() !=3D nul=
l) {
- MessageFormat msgFormat =3D new MessageFormat(
- keyValue);
- msgFormat.setLocale(currentLocale);
+ MessageFormat msgFormat =3D new MessageFormat(keyV=
alue, currentLocale);
resValue =3D msgFormat.format(message.getValues());
} else {
resValue =3D keyValue;
}
=
} else {
- logger.error(
- "Couldn't find any EngineMessage bean with name " +
- name + "!");
- }
+ logger.error("Couldn't find any EngineMessage bean wit=
h name " + name + "!");
}
-
- if (key !=3D null) {
}
=
} catch (MissingResourceException mre) {
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list