KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jahia.deprecated.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.JahiaGroup;
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 group.
22  *
23  * @author Khue Nguyen
24  */

25 public class SetGrpEngineResourceBundleTag extends TagSupport JavaDoc {
26
27     private static final String JavaDoc CLASS_NAME =
28                                     SetGrpEngineResourceBundleTag.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 groupName = 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 localeCountry) {
54         if ( localeVariant != null )
55             this.localeVariant = localeVariant.trim();
56     }
57
58     public void setGroupName(String JavaDoc groupName) {
59         if ( groupName != null )
60             this.groupName = groupName.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                 JahiaGroup grp = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup(jData.params().getSiteID(),this.groupName);
83                 if ( grp == null ){
84                     // check if the user is the root admin group.
85
grp = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup(0,this.groupName);
86                 }
87
88                 if ( grp != null ){
89                     GrpUsrEngineResourceBundle.getInstance().addResourceBundle( jData.params().getContentPage(), (Principal JavaDoc)grp, res );
90                 }
91             } catch (Throwable JavaDoc t){
92             }
93         }
94
95         return SKIP_BODY;
96
97     }
98
99     public int doEndTag() throws JspException JavaDoc {
100         // let's reinitialize the tag variables to allow tag object reuse in
101
// pooling.
102
resourceBundle = "";
103         localeLangage = "";
104         localeCountry = "";
105         localeVariant = "";
106         locale = null;
107         groupName = null;
108         return EVAL_PAGE;
109     }
110
111 }
112
Popular Tags