001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.ServerDetector;
019    import com.liferay.portal.kernel.util.StringPool;
020    
021    import javax.servlet.jsp.JspException;
022    import javax.servlet.jsp.tagext.TagSupport;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class MessageTag extends TagSupport {
028    
029            public int doEndTag() throws JspException {
030                    try {
031                            String value =  StringPool.BLANK;
032    
033                            if (_arguments == null) {
034                                    value = LanguageUtil.get(pageContext, _key);
035                            }
036                            else {
037                                    value = LanguageUtil.format(
038                                            pageContext, _key, _arguments, _translateArguments);
039                            }
040    
041                            pageContext.getOut().print(value);
042    
043                            return EVAL_PAGE;
044                    }
045                    catch (Exception e) {
046                            throw new JspException(e);
047                    }
048                    finally {
049                            if (!ServerDetector.isResin()) {
050                                    _arguments = null;
051                                    _key = null;
052                                    _translateArguments = true;
053                            }
054                    }
055            }
056    
057            public void setArguments(Object argument) {
058                    _arguments = new Object[] {argument};
059            }
060    
061            public void setArguments(Object[] arguments) {
062                    _arguments = arguments;
063            }
064    
065            public void setKey(String key) {
066                    _key = key;
067            }
068    
069            public void setTranslateArguments(boolean translateArguments) {
070                    _translateArguments = translateArguments;
071            }
072    
073            private Object[] _arguments;
074            private String _key;
075            private boolean _translateArguments = true;
076    
077    }