KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > deprecated > taglibs > resourcebundle > MessageTag


1 package org.jahia.deprecated.taglibs.resourcebundle;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Locale JavaDoc;
5 import java.util.MissingResourceException JavaDoc;
6
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpSession JavaDoc;
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.JspWriter JavaDoc;
11 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
12
13 import org.jahia.params.ParamBean;
14 import org.jahia.resourcebundle.JahiaResourceBundle;
15 import org.jahia.utils.JahiaConsole;
16
17
18 /**
19  * Support for Jahia Message ResourceBundle within Jahia
20  *
21  * Returns the requested resource.
22  *
23  * @see JahiaResourceBundle
24  * @see SetAdminResourceBundleTag
25  * @see JahiaEnginesResources.properties
26  *
27  * @author Khue Nguyen
28  */

29 public class MessageTag extends TagSupport JavaDoc {
30
31     private static final String JavaDoc CLASS_NAME = MessageTag.class.getName();
32
33     private String JavaDoc key = "";
34
35     public void setKey(String JavaDoc key) {
36         if ( key == null )
37             key = "";
38         this.key = key;
39     }
40
41     public int doStartTag() {
42
43         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
44         String JavaDoc resValue = null;
45
46         Locale JavaDoc currentLocale = request.getLocale();
47         HttpSession JavaDoc session = pageContext.getSession();
48         if (session != null) {
49             if (session.getAttribute(ParamBean.SESSION_LOCALE) != null) {
50                 currentLocale = (Locale JavaDoc) session.getAttribute(ParamBean.
51                     SESSION_LOCALE);
52             }
53         }
54
55         try {
56             resValue = JahiaResourceBundle
57                         .getMessageResource( key,
58                                               currentLocale );
59
60         } catch ( MissingResourceException JavaDoc mre ) {
61             JahiaConsole.println(CLASS_NAME+"doStartTag", mre.toString());
62         }
63
64         if (resValue == null) {
65             resValue = "";
66         }
67
68         try {
69             JspWriter JavaDoc out = pageContext.getOut();
70             out.print( resValue );
71             out.flush();
72         } catch (IOException JavaDoc ioe) {
73             JahiaConsole.println(CLASS_NAME+"doStartTag", ioe.toString());
74         }
75
76         return SKIP_BODY;
77
78     }
79
80     public int doEndTag() throws JspException JavaDoc {
81         // let's reinitialize the tag variables to allow tag object reuse in
82
// pooling.
83
key = "";
84         return EVAL_PAGE;
85     }
86
87
88 }
89
Popular Tags