📄 messagetag.java
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file. */package org.butor.web.taglib.bean;import java.util.Locale;import javax.servlet.ServletRequest;import javax.servlet.jsp.JspException;import org.apache.struts.util.RequestUtils;import org.apache.struts.util.ResponseUtils;import org.butor.messageResources.MessageResourcesService;import org.butor.web.helper.StandardAttributes;/** * @author sawanai * * This ressource message tag is derived from struts MessageTag. * The difference is that try to find the locale in the request before * the page and session context. */public class MessageTag extends org.apache.struts.taglib.bean.MessageTag { /** * Constructor for MessageTag. */ public MessageTag() { super(); } /** * The first optional argument message resource key. */ protected String arg0Key = null; public String getArg0Key() { return (this.arg0Key); } public void setArg0Key(String arg0Key) { this.arg0Key = arg0Key; } /** * The second optional argument message resource key. */ protected String arg1Key = null; public String getArg1Key() { return (this.arg1Key); } public void setArg1Key(String arg1Key) { this.arg1Key = arg1Key; } /** * The third optional argument message resource key. */ protected String arg2Key = null; public String getArg2Key() { return (this.arg2Key); } public void setArg2Key(String arg2Key) { this.arg2Key = arg2Key; } /** * The fourth optional argument message resource key. */ protected String arg3Key = null; public String getArg3Key() { return (this.arg3Key); } public void setArg3Key(String arg3Key) { this.arg3Key = arg3Key; } /** * The fifth optional argument message resource key. */ protected String arg4Key = null; public String getArg4Key() { return (this.arg4Key); } public void setArg4Key(String arg4Key) { this.arg4Key = arg4Key; } /** * Process the start tag. * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { String key = this.key; if (key == null) { // Look up the requested property value Object value = RequestUtils.lookup(pageContext, name, property, scope); if (value != null && !(value instanceof String)) { JspException e = new JspException("MessageTag: key found by preoprty is not a string!"); RequestUtils.saveException(pageContext, e); throw e; } key = (String) value; } if (key == null) { JspException e = new JspException("MessageTag: key not found!"); RequestUtils.saveException(pageContext, e); throw e; } ServletRequest sr = pageContext.getRequest(); // Retrieve the message string we are looking for if (this.localeKey == null) { this.localeKey = StandardAttributes.LOCALE_KEY; } Locale locale = (Locale) sr.getAttribute(this.localeKey); if (locale == null) { locale = RequestUtils.retrieveUserLocale(pageContext, this.localeKey); } // Construct the optional arguments array we will be using Object args[] = new Object[5]; args[0] = arg0Key != null ? MessageResourcesService.getMessage(locale, arg0Key) : arg0; args[1] = arg1Key != null ? MessageResourcesService.getMessage(locale, arg1Key) : arg1; args[2] = arg2Key != null ? MessageResourcesService.getMessage(locale, arg2Key) : arg2; args[3] = arg3Key != null ? MessageResourcesService.getMessage(locale, arg3Key) : arg3; args[4] = arg4Key != null ? MessageResourcesService.getMessage(locale, arg4Key) : arg4; String message = MessageResourcesService.getMessage(locale, key, args); if (message != null) { // Print the retrieved message to our output writer ResponseUtils.write(pageContext, message); } // Continue processing this page return (SKIP_BODY); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -