KickJava   Java API By Example, From Geeks To Geeks.

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


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

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