001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }