001    /**
002     * Copyright (c) 2000-2011 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.JspWriter;
023    import javax.servlet.jsp.tagext.TagSupport;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class MessageTag extends TagSupport {
029    
030            @Override
031            public int doEndTag() throws JspException {
032                    try {
033                            String value =  StringPool.BLANK;
034    
035                            if (_arguments == null) {
036                                    value = LanguageUtil.get(pageContext, _key);
037                            }
038                            else {
039                                    value = LanguageUtil.format(
040                                            pageContext, _key, _arguments, _translateArguments);
041                            }
042    
043                            JspWriter jspWriter = pageContext.getOut();
044    
045                            jspWriter.write(value);
046    
047                            return EVAL_PAGE;
048                    }
049                    catch (Exception e) {
050                            throw new JspException(e);
051                    }
052                    finally {
053                            if (!ServerDetector.isResin()) {
054                                    _arguments = null;
055                                    _key = null;
056                                    _translateArguments = true;
057                            }
058                    }
059            }
060    
061            public void setArguments(Object argument) {
062                    _arguments = new Object[] {argument};
063            }
064    
065            public void setArguments(Object[] arguments) {
066                    _arguments = arguments;
067            }
068    
069            public void setKey(String key) {
070                    _key = key;
071            }
072    
073            public void setTranslateArguments(boolean translateArguments) {
074                    _translateArguments = translateArguments;
075            }
076    
077            private Object[] _arguments;
078            private String _key;
079            private boolean _translateArguments = true;
080    
081    }