KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > taglibs > resourcebundle > SetEngineResourceBundleTag


1 package org.jahia.taglibs.resourcebundle;
2
3 import java.util.Locale JavaDoc;
4 import java.util.ResourceBundle JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.jsp.JspException JavaDoc;
8 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
9
10 import org.jahia.data.JahiaData;
11 import org.jahia.resourcebundle.PagesEngineResourceBundle;
12
13
14 /**
15  * This tag should be called on top of each template JSP file.
16  * It is used to allow template designer to provide a different engine resource bunlde
17  * that Jahia will use to give different look to the engines
18  * popup that are opened from pages using this template.
19  *
20  * @author Khue Nguyen
21  */

22 public class SetEngineResourceBundleTag extends TagSupport JavaDoc {
23
24     private static final String JavaDoc CLASS_NAME =
25                                     SetEngineResourceBundleTag.class.getName();
26
27     private String JavaDoc resourceBundle = "";
28     private String JavaDoc localeLangage = "";
29     private String JavaDoc localeCountry = "";
30     private String JavaDoc localeVariant = "";
31     private Locale JavaDoc locale = null;
32
33     public void setResourceBundle(String JavaDoc resourceBundle) {
34         if ( resourceBundle == null )
35             resourceBundle = "";
36         this.resourceBundle = resourceBundle.trim();
37     }
38
39     public void setLocaleLangage(String JavaDoc localeLangage) {
40         if ( localeLangage != null )
41             this.localeLangage = localeLangage.trim();
42     }
43
44     public void setLocaleCountry(String JavaDoc localeCountry) {
45         if ( localeCountry != null )
46             this.localeCountry = localeCountry.trim();
47     }
48
49     public void setLocaleVariant(String JavaDoc localeVariant) {
50         if ( localeVariant != null )
51             this.localeVariant = localeVariant.trim();
52     }
53
54     public int doStartTag() {
55
56
57         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
58         JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");
59
60         ResourceBundle JavaDoc res = null;
61         String JavaDoc resValue = null;
62
63         if ( localeLangage.equals("") ){
64             locale = jData.params().getLocale();
65         } else {
66             locale = new Locale JavaDoc(localeLangage,localeCountry,localeVariant);
67         }
68
69         res = ResourceBundle.getBundle(resourceBundle,locale);
70
71         if (res != null) {
72             try {
73                 PagesEngineResourceBundle.getInstance().addResourceBundle( jData.params().getContentPage(), res , jData.params() );
74             } catch (Throwable JavaDoc t){
75             }
76         }
77
78         return SKIP_BODY;
79
80     }
81
82     public int doEndTag() throws JspException JavaDoc {
83         // let's reinitialize the tag variables to allow tag object reuse in
84
// pooling.
85
resourceBundle = "";
86         localeLangage = "";
87         localeCountry = "";
88         localeVariant = "";
89         locale = null;
90         return EVAL_PAGE;
91     }
92
93 }
94
Popular Tags