1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.language.LanguageUtil;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.StringPool;
20  
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.tagext.TagSupport;
23  
24  /**
25   * <a href="MessageTag.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class MessageTag extends TagSupport {
30  
31      public int doEndTag() throws JspException {
32          try {
33              String value =  StringPool.BLANK;
34  
35              if (_arguments == null) {
36                  value = LanguageUtil.get(pageContext, _key);
37              }
38              else {
39                  value = LanguageUtil.format(
40                      pageContext, _key, _arguments, _translateArguments);
41              }
42  
43              pageContext.getOut().print(value);
44  
45              return EVAL_PAGE;
46          }
47          catch (Exception e) {
48              throw new JspException(e);
49          }
50          finally {
51              if (!ServerDetector.isResin()) {
52                  _arguments = null;
53                  _key = null;
54                  _translateArguments = true;
55              }
56          }
57      }
58  
59      public void setArguments(Object argument) {
60          _arguments = new Object[] {argument};
61      }
62  
63      public void setArguments(Object[] arguments) {
64          _arguments = arguments;
65      }
66  
67      public void setKey(String key) {
68          _key = key;
69      }
70  
71      public void setTranslateArguments(boolean translateArguments) {
72          _translateArguments = translateArguments;
73      }
74  
75      private Object[] _arguments;
76      private String _key;
77      private boolean _translateArguments = true;
78  
79  }