1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }