KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > resourcebundle > JahiaResourceBundle


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// NK 18.02.2002 - added in Jahia
15
//
16

17 package org.jahia.resourcebundle;
18
19 import java.security.Principal JavaDoc;
20 import java.util.Locale JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 import org.jahia.params.ParamBean;
24 import org.jahia.registries.ServicesRegistry;
25 import org.jahia.services.pages.ContentPage;
26 import org.jahia.services.sites.JahiaSite;
27 import org.jahia.services.usermanager.JahiaUser;
28
29 /**
30  * Tools to handles resource bundle within Jahia.
31  *
32  * @author Khue Nguyen
33  * @version 1.0
34  */

35 public class JahiaResourceBundle
36 {
37
38     private static final String JavaDoc CLASS_NAME = JahiaResourceBundle.class.getName();
39
40     public static final String JavaDoc ENGINE_DEFAULT_RESOURCE_BUNDLE = "JahiaEnginesResources";
41     public static final String JavaDoc ADMIN_DEFAULT_RESOURCE_BUNDLE = "JahiaAdministrationResources";
42     public static final String JavaDoc MESSAGE_DEFAULT_RESOURCE_BUNDLE = "JahiaMessageResources";
43
44
45     //--------------------------------------------------------------------------
46
/**
47      * Returns the requested resource.
48      *
49      * If the requested resource bundle is missing and useDefault is true,
50      * Jahia will look for another engine resource bundle in that order :
51      *
52      * * 1. Look for the engine resource bundle of the current user.
53      * This resource bundle can be set in the template used by the page
54      * with the SetUsrEngineResourceBundleTag,SetGrpEngineResourceBundleTag.
55      *
56      * * 2. Look for the engine resource bundle of the page.
57      * This resource bundle can be set in the template used by the page
58      * with the SetEngineResourceBundleTag.
59      *
60      * * 3. Look for the site's default engine resource bundle.
61      * Each site can have a default engine resource bundle. It's name
62      * must be of this form : "JahiaEnginesResourcesMYJAHIASITE"
63      * where MYJAHIASITE is the virtual site's sitekey in uppercase.
64      *
65      * * 4. Finally if none of the previous resource bundle are available,
66      * Jahia will return the internal engine's default resource bundle
67      * named "JahiaEnginesResources".
68      *
69      *
70      * @param String resourceName, the resource name
71      * @param ParamBean jParams
72      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
73      *
74      * @return ResourceBundle, the requested resource bundle
75      *
76      * @see EngineResourceBundleTag
77      * @see SetEngineResourceBundleTag
78      * @see JahiaEnginesResources.properties
79      *
80      * @author Khue Nguyen
81      */

82     public static String JavaDoc getEngineResource( String JavaDoc resourceName,
83                                             ParamBean jParams,
84                                             Locale JavaDoc locale ){
85
86         ResourceBundle JavaDoc res = null;
87         String JavaDoc resValue = null;
88
89         if ( resourceName == null || resourceName.trim().equals("") )
90             return null;
91
92         Locale JavaDoc loc = checkLocale(locale,jParams);
93
94         boolean adminMode = false;
95         try {
96             adminMode = jParams.isInAdminMode();
97         } catch ( Throwable JavaDoc t ){
98             t.printStackTrace();
99         }
100
101         if ( !adminMode ) {
102             // first look for user's engine resource bundle
103
res = getGrpUsrEngineResourceBundle(jParams.getPageID(),jParams.getUser());
104             if ( res != null ){
105                 try {
106                     resValue = res.getString(resourceName);
107                     return resValue;
108                 } catch ( Throwable JavaDoc t ){
109                 }
110             }
111
112             // second look for page's engine resource bundle
113
res = getPageEngineResourceBundle(jParams.getPageID(),jParams);
114             if ( res != null ){
115                 try {
116                     resValue = res.getString(resourceName);
117                     return resValue;
118                 } catch ( Throwable JavaDoc t ){
119                 }
120             }
121
122             // third look for site's engine resource bundle
123
res = getSiteEngineResourceBundle(jParams.getSite(),jParams,loc);
124             if ( res != null ){
125                 try {
126                     resValue = getString(res, resourceName, loc);
127                     return resValue;
128                 } catch ( Throwable JavaDoc t ){
129                 }
130             }
131         }
132
133         // fourth look for jahia's engine default resource bundle
134
res = getEngineDefaultResourceBundle(jParams,loc);
135         if ( res != null ){
136             try {
137                 resValue = getString(res, resourceName, loc);
138                 return resValue;
139             } catch ( Throwable JavaDoc t ){
140             }
141         }
142         logger.warn("Resource [" + resourceName +
143                     "] not found in engine resource bundles using locale [" +
144                     locale + "]");
145         return null;
146     }
147
148     //--------------------------------------------------------------------------
149
/**
150      * Returns the requested resource for Administration Templates.
151      *
152      * If the requested resource bundle is missing and useDefault is true,
153      * Jahia will look for another resource bundle in that order :
154      *
155      * * 1. Look for the site's default engine resource bundle.
156      * Each site can have a default engine resource bundle. It's name
157      * must be of this form : "JahiaEnginesResourcesMYJAHIASITE"
158      * where MYJAHIASITE is the virtual site's sitekey in uppercase.
159      *
160      * * 2. Finally if none of the previous resource bundle are available,
161      * Jahia will return the internal engine's default resource bundle
162      * named "JahiaAdministrationResources".
163      *
164      *
165      * @param String resourceName, the resource name
166      * @param ParamBean jParams
167      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
168      *
169      * @return ResourceBundle, the requested resource bundle
170      *
171      * @see AdminResourceBundleTag
172      * @see JahiaAdministrationResources.properties
173      *
174      * @author Khue Nguyen
175      */

176     public static String JavaDoc getAdminResource( String JavaDoc resourceName,
177                                            ParamBean jParams,
178                                            Locale JavaDoc locale ){
179
180         ResourceBundle JavaDoc res = null;
181         String JavaDoc resValue = null;
182
183         if ( resourceName == null || resourceName.trim().equals("") )
184             return null;
185
186         Locale JavaDoc loc = checkLocale(locale,jParams);
187
188         boolean adminMode = false;
189         try {
190             adminMode = jParams.isInAdminMode();
191         } catch ( Throwable JavaDoc t ){
192             t.printStackTrace();
193         }
194
195         // first look for site's engine resource bundle
196
res = getSiteAdminResourceBundle(jParams.getSite(),jParams,loc);
197         if ( res != null ){
198             try {
199                 resValue = getString(res, resourceName, loc);
200                 return resValue;
201             } catch ( Throwable JavaDoc t ){
202             }
203         }
204
205         // second look for jahia's engine default resource bundle
206
res = getAdminDefaultResourceBundle(jParams,loc);
207         if ( res != null ){
208             try {
209                 resValue = getString(res, resourceName, loc);
210                 return resValue;
211             } catch ( Throwable JavaDoc t ){
212             }
213         }
214         logger.warn("Resource [" + resourceName +
215                     "] not found in administration resource bundles using locale [" +
216                     loc + "]");
217         return null;
218     }
219
220     //--------------------------------------------------------------------------
221
/**
222      * Returns the requested resource for Message Templates.
223      *
224      * @param String resourceName, the resource name
225      * @param ParamBean jParams
226      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
227      *
228      * @return ResourceBundle, the requested resource bundle
229      *
230      * @see MessageTag
231      * @see JahiaMessageResources.properties
232      *
233      * @author Khue Nguyen
234      */

235     public static String JavaDoc getMessageResource( String JavaDoc resourceName,
236                                                   Locale JavaDoc locale ){
237
238         ResourceBundle JavaDoc res = ResourceBundle.getBundle(MESSAGE_DEFAULT_RESOURCE_BUNDLE,locale);
239         String JavaDoc resValue = null;
240
241         if ( resourceName == null || resourceName.trim().equals("") )
242             return null;
243
244         if ( res != null ){
245             try {
246                 resValue = getString(res, resourceName, locale);
247                 return resValue;
248             } catch ( Throwable JavaDoc t ){
249             }
250         }
251         logger.warn("Resource [" + resourceName +
252                     "] not found in message resource bundles using locale [" +
253                     locale + "]");
254         return null;
255     }
256
257     //--------------------------------------------------------------------------
258
/**
259      * Returns the requested resource. The resource is prefixed with the Application Context
260      *
261      * If the requested resource bundle is missing and useDefault is true,
262      * Jahia will look for another engine resource bundle in that order :
263      *
264      * * 1. Look for the engine resource bundle of the current user.
265      * This resource bundle can be set in the template used by the page
266      * with the SetUsrEngineResourceBundleTag,SetGrpEngineResourceBundleTag.
267      *
268      * * 2. Look for the engine resource bundle of the page.
269      * This resource bundle can be set in the template used by the page
270      * with the SetEngineResourceBundleTag.
271      *
272      * * 3. Look for the site's default engine resource bundle.
273      * Each site can have a default engine resource bundle. It's name
274      * must be of this form : "JahiaEnginesResourcesMYJAHIASITE"
275      * where MYJAHIASITE is the virtual site's sitekey in uppercase.
276      *
277      * * 4. Finally if none of the previous resource bundle are available,
278      * Jahia will return the internal engine's default resource bundle
279      * named "JahiaEnginesResources".
280      *
281      *
282      * @param String resourceName, the resource name
283      * @param ParamBean jParams
284      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
285      *
286      * @return ResourceBundle, the requested resource bundle
287      *
288      * @see EngineResourceBundleTag
289      * @see SetEngineResourceBundleTag
290      * @see JahiaEnginesResources.properties
291      *
292      * @author Khue Nguyen
293      */

294     public static String JavaDoc getUrlPathResourceEngineResource( String JavaDoc resourceName,
295                                                            ParamBean jParams,
296                                                            Locale JavaDoc locale )
297     {
298         String JavaDoc res = getEngineResource(resourceName,jParams,locale);
299         if ( res != null ){
300             res = jParams.getRequest().getContextPath() + res;
301         }
302         return res;
303     }
304
305
306     /**
307      * Resolves a resource value by looking at the bundle code if specified, or
308      * using the default resource bundle if not specified. The bundle code is
309      * currently a hardcoded resolver but in the future we might change this
310      * to allow the resolver to be more dynamic, notably making by specifying
311      * resolver classes or something fancy like that :)
312      *
313      * @param bundleCode a String containing a bundle code such as "administration",
314      * "engine", "configuration" that will indicate which resolver to use for
315      * finding the resource. If the bundleCode is null, the default resolver
316      * (engine) will be used.
317      * @param resourceKey the key for the resource within the bundle to be found.
318      * @param locale the locale to use for resolving the bundle file, or if it
319      * is null, the jParams parameter is used accessing it's jParams.getLocale()
320      * method
321      * @param jParams used in case the locale parameter is null. the
322      * jParams.getLocale method is then called.
323      *
324      * @return a String containing the value associated with the key in the
325      * bundle specified by the bundle code, or null if the key couldn't be
326      * found.
327      */

328     public static String JavaDoc getResource(String JavaDoc bundleCode, String JavaDoc resourceKey, Locale JavaDoc locale, ParamBean jParams) {
329         String JavaDoc result = null;
330
331         if ("administration".equals(bundleCode)) {
332             result = getAdminResource(resourceKey, jParams, locale);
333         } else if ("configuration".equals(bundleCode)) {
334             result = getMessageResource(resourceKey, locale);
335         } else {
336             result = getEngineResource(resourceKey, jParams, locale);
337         }
338
339         return result;
340     }
341
342
343     //--------------------------------------------------------------------------
344
/**
345      * Get a Jahia common resource defined in ENGINE_DEFAULT_RESOURCE_BUNDLE.
346      *
347      * @param resourceName The name(key) of resource bundle.
348      * @param jParams ;)
349      * @return
350      * Null if no resource found.
351      */

352     public static String JavaDoc getCommonResource(String JavaDoc resourceName, ParamBean jParams) {
353
354         ResourceBundle JavaDoc res = ResourceBundle.getBundle(ENGINE_DEFAULT_RESOURCE_BUNDLE);
355         try {
356             if (res != null) {
357                 return res.getString(resourceName);
358             }
359         } catch (java.util.MissingResourceException JavaDoc mre) {
360             logger.warn("Resource [" + resourceName + "] not found in [" +
361                         ENGINE_DEFAULT_RESOURCE_BUNDLE + "] !");
362         }
363         return null;
364     }
365
366     //--------------------------------------------------------------------------
367
/**
368      * Get a Jahia common resource defined in ENGINE_DEFAULT_RESOURCE_BUNDLE.
369      * The returned value is prefixed with the Application Context Path.
370      *
371      * @param resourceName The name(key) of resource bundle.
372      * @param jParams
373      * @return
374      * Null if no resource found.
375      */

376     public static String JavaDoc getUrlPathCommonResource(String JavaDoc resourceName, ParamBean jParams) {
377
378         String JavaDoc res = getCommonResource(resourceName,jParams);
379         if ( res != null ){
380             res = jParams.getRequest().getContextPath() + res;
381         }
382         return res;
383     }
384
385     //--------------------------------------------------------------------------
386
/**
387      * Returns the requested resource bundle.
388      *
389      * If the requested resource bundle is missing and useDefault is true,
390      * Jahia will look for another engine resource bundle in that order :
391      *
392      * * 1. Look for the engine resource bundle of the current user.
393      * This resource bundle can be set in the template used by the page
394      * with the SetUsrEngineResourceBundleTag,SetGrpEngineResourceBundleTag.
395      *
396      * * 2. Look for the engine resource bundle of the page.
397      * This resource bundle can be set in the template used by the page
398      * with the SetEngineResourceBundleTag.
399      *
400      * * 3. Look for the site's default engine resource bundle.
401      * Each site can have a default engine resource bundle. It's name
402      * must be of this form : "JahiaEnginesResourcesMYJAHIASITE"
403      * where MYJAHIASITE is the virtual site's sitekey in uppercase.
404      *
405      * * 4. Finally if none of the previous resource bundle are available,
406      * Jahia will return the internal engine's default resource bundle
407      * named "JahiaEnginesResources".
408      *
409      *
410      * @param String resourceBundle, the resource bundle name
411      * @param ParamBean jParams
412      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
413      * @param boolean useDefault, when true , return Jahia engines' default resource bundle
414      * if the requested resource bundle is missing.
415      *
416      * @return ResourceBundle, the requested resource bundle
417      * @author Khue Nguyen
418      */

419     public static ResourceBundle JavaDoc getEngineResourceBundle(
420                                                     String JavaDoc resourceBundle,
421                                                     ParamBean jParams,
422                                                     Locale JavaDoc locale,
423                                                     boolean useDefault ){
424
425         ResourceBundle JavaDoc res = null;
426
427         Locale JavaDoc loc = checkLocale(locale,jParams);
428
429         try {
430             res = ResourceBundle.getBundle(resourceBundle,loc);
431         } catch ( Throwable JavaDoc t ){
432             // logger.debug("Error while retrieving engine resource bundle :" + resourceBundle + " for locale " + loc, t);
433
}
434         if ( ((res == null) && useDefault) && (jParams != null) ){
435
436             // first look for usr, grp's engine resource bundle
437
res = getGrpUsrEngineResourceBundle(jParams.getPageID(),jParams.getUser());
438
439             if ( res == null ){
440                 // second look for page's engine resource bundle
441
res = getPageEngineResourceBundle(jParams.getPageID(),jParams);
442             }
443
444             if ( res == null ){
445                 // third look for site's engine resource bundle
446
res = getSiteEngineResourceBundle(jParams.getSite(),jParams,loc);
447             }
448             if ( res == null ){
449                 // fourth look for jahia default engine resource bundle
450
res = getEngineDefaultResourceBundle(jParams,loc);
451             }
452         }
453         return res;
454     }
455
456     //--------------------------------------------------------------------------
457
/**
458      * Returns Jahia engines' default resource bundle
459      * This resource bundle's name is "JahiaEnginesResources"
460      *
461      * @param ParamBean jParams
462      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
463      *
464      * @return ResourceBundle, the Jahia engines' default resource bundle or null if not found
465      */

466     public static ResourceBundle JavaDoc getEngineDefaultResourceBundle(
467                                                     ParamBean jParams,
468                                                     Locale JavaDoc locale ){
469
470         Locale JavaDoc loc = checkLocale(locale,jParams);
471
472         ResourceBundle JavaDoc res = null;
473
474         try {
475             res = ResourceBundle.getBundle(ENGINE_DEFAULT_RESOURCE_BUNDLE,loc);
476         } catch ( Throwable JavaDoc t ){
477             logger.debug("Error while using default engine resource bundle (" +
478                          ENGINE_DEFAULT_RESOURCE_BUNDLE + ") with locale " + loc, t);
479         }
480
481         return res;
482     }
483
484     //--------------------------------------------------------------------------
485
/**
486      * Returns Jahia admin' default resource bundle
487      * This resource bundle's name is "JahiaAdministrationResources"
488      *
489      * @param ParamBean jParams
490      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
491      *
492      * @return ResourceBundle, the Jahia engines' default resource bundle or null if not found
493      */

494     public static ResourceBundle JavaDoc getAdminDefaultResourceBundle(
495                                                     ParamBean jParams,
496                                                     Locale JavaDoc locale ){
497
498         Locale JavaDoc loc = checkLocale(locale,jParams);
499
500         ResourceBundle JavaDoc res = null;
501
502         try {
503             res = ResourceBundle.getBundle(ADMIN_DEFAULT_RESOURCE_BUNDLE,loc);
504         } catch ( Throwable JavaDoc t ){
505             logger.debug("Error while retrieving administration default resource bundle " +
506                          ADMIN_DEFAULT_RESOURCE_BUNDLE + " with locale " + loc, t);
507         }
508
509         return res;
510     }
511
512     //--------------------------------------------------------------------------
513
/**
514      * Returns Jahia Message default resource bundle
515      * This resource bundle's name is "JahiaMessageResources"
516      *
517      * @param ParamBean jParams
518      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
519      *
520      * @return ResourceBundle, the Jahia engines' default resource bundle or null if not found
521      */

522     public static ResourceBundle JavaDoc getMessageDefaultResourceBundle(
523                                                     ParamBean jParams,
524                                                     Locale JavaDoc locale ){
525
526         Locale JavaDoc loc = checkLocale(locale,jParams);
527
528         ResourceBundle JavaDoc res = null;
529
530         try {
531             res = ResourceBundle.getBundle(MESSAGE_DEFAULT_RESOURCE_BUNDLE,loc);
532         } catch ( Throwable JavaDoc t ){
533             logger.debug("Error while retrieving message default resource bundle " +
534                          ADMIN_DEFAULT_RESOURCE_BUNDLE + " with locale " + loc, t);
535         }
536
537         return res;
538     }
539
540     //--------------------------------------------------------------------------
541
/**
542      * Returns the current site engines' resource bundle
543      * Internally, Jahia look for a resource bundle whose name is :
544      *
545      * "JahiaEnginesResources" + jParams.getSite().getSiteKey().toUpperCase()
546      *
547      * like : JahiaEnginesResourcesMYJAHIASITE
548      *
549      * @param JahiaSite site
550      * @param ParamBean jParams
551      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
552      *
553      * @return ResourceBundle, the site engines' default resource bundle or null if not found
554      */

555     public static ResourceBundle JavaDoc getSiteEngineResourceBundle( JahiaSite site,
556                                                               ParamBean jParams,
557                                                               Locale JavaDoc locale ){
558
559         if ( site == null )
560             return null;
561
562         Locale JavaDoc loc = checkLocale(locale,jParams);
563
564         ResourceBundle JavaDoc res = null;
565
566         try {
567             res = ResourceBundle.getBundle( ENGINE_DEFAULT_RESOURCE_BUNDLE
568                                             +site.getSiteKey().toUpperCase(),loc);
569         } catch ( Throwable JavaDoc t ){
570             //JahiaConsole.println( CLASS_NAME+".getSiteEngineResourceBundle",
571
// t.getMessage());
572
}
573
574         return res;
575     }
576
577     //--------------------------------------------------------------------------
578
/**
579      * Returns the current site admin' resource bundle
580      * Internally, Jahia look for a resource bundle whose name is :
581      *
582      * "JahiaAdministrationResources" + jParams.getSite().getSiteKey().toUpperCase()
583      *
584      * like : JahiaAdministrationResourcesMYJAHIASITE
585      *
586      * @param JahiaSite site
587      * @param ParamBean jParams
588      * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()
589      *
590      * @return ResourceBundle, the site engines' default resource bundle or null if not found
591      */

592     public static ResourceBundle JavaDoc getSiteAdminResourceBundle( JahiaSite site,
593                                                              ParamBean jParams,
594                                                              Locale JavaDoc locale ){
595
596         if ( site == null )
597             return null;
598
599         Locale JavaDoc loc = checkLocale(locale,jParams);
600
601         ResourceBundle JavaDoc res = null;
602
603         try {
604             res = ResourceBundle.getBundle( ADMIN_DEFAULT_RESOURCE_BUNDLE
605                                             +site.getSiteKey().toUpperCase(),loc);
606         } catch ( Throwable JavaDoc t ){
607             //JahiaConsole.println( CLASS_NAME+".getSiteEngineResourceBundle",
608
// t.getMessage());
609
}
610
611         return res;
612     }
613
614     //--------------------------------------------------------------------------
615
/**
616      * Returns the engine resource bundle associated with the page.
617      * With the SetEngineResourceBundleTag, you can associate an engine resource bundle
618      * with a template JSP.
619      *
620      * Jahia will use this resource bundle to give different look to the engines
621      * popup that are opened from pages using this template.
622      *
623      * @param int pageID, the page id
624      *
625      * @return ResourceBundle, the site engines' default resource bundle or null if not found
626      */

627     public static ResourceBundle JavaDoc getPageEngineResourceBundle( int pageID , ParamBean jParams){
628
629
630         if ( jParams == null )
631             return null;
632
633         if ( pageID == -1 )
634             return null;
635
636         ContentPage contentPage = null;
637         try {
638             contentPage = ServicesRegistry.getInstance().getJahiaPageService().lookupContentPage(pageID,true);
639         } catch ( Throwable JavaDoc t) {
640             //JahiaConsole.println( CLASS_NAME+".getPageEngineResourceBundle",
641
// t.getMessage());
642
}
643
644         if ( (contentPage == null) )
645             return null;
646
647         ResourceBundle JavaDoc res = null;
648
649         try {
650             res = PagesEngineResourceBundle.getInstance().getResourceBundle( contentPage , jParams );
651         } catch ( Throwable JavaDoc t ){
652             //JahiaConsole.println( CLASS_NAME+".getPageEngineResourceBundle",
653
// t.getMessage());
654
}
655
656         return res;
657     }
658
659     //--------------------------------------------------------------------------
660
/**
661      * Returns the engine resource bundle associated with a page and a given Principal.
662      * With the SetUsrEngineResourceBundleTag and SetGrpEngineResourceBundleTag,
663      * you can associate an engine resource bundle with a template JSP for a given user or group.
664      *
665      * Jahia will use this resource bundle to give different look to the engines
666      * popup that are opened from pages using this template and for the current user.
667      *
668      * @param int pageID, the page id
669      *
670      * @return ResourceBundle, the grp or usr engines' default resource bundle or null if not found
671      */

672     public static ResourceBundle JavaDoc getGrpUsrEngineResourceBundle( int pageID , JahiaUser user){
673
674
675         if ( pageID == -1 || user==null )
676             return null;
677
678         ContentPage contentPage = null;
679         try {
680             contentPage = ServicesRegistry.getInstance().getJahiaPageService().lookupContentPage(pageID,true);
681         } catch ( Throwable JavaDoc t) {
682             //JahiaConsole.println( CLASS_NAME+".getPageEngineResourceBundle",
683
// t.getMessage());
684
}
685
686         if ( (contentPage == null) )
687             return null;
688
689         ResourceBundle JavaDoc res = null;
690
691         try {
692             res = GrpUsrEngineResourceBundle.getInstance().getResourceBundle( contentPage , (Principal JavaDoc)user );
693         } catch ( Throwable JavaDoc t ){
694             //JahiaConsole.println( CLASS_NAME+".getPageEngineResourceBundle",
695
// t.getMessage());
696
}
697
698         return res;
699     }
700
701
702     private static Locale JavaDoc checkLocale(Locale JavaDoc locale, ParamBean jParams){
703         Locale JavaDoc resLocale = locale;
704         if ( resLocale == null ){
705             if ( jParams != null ){
706                 resLocale = jParams.getLocale();
707             } else {
708                 resLocale = Locale.getDefault();
709             }
710         }
711         return resLocale;
712     }
713
714     private static org.apache.log4j.Logger logger =
715             org.apache.log4j.Logger.getLogger(JahiaResourceBundle.class);
716
717         //--------------------------------------------------------------------------
718
/**
719          * Returns the resource string.
720          * This is a convenience way to used such as Chinese to translate from encoding.
721          *
722          * @param ResourceBundle
723          * @param String
724          * @return String
725          */

726         public static String JavaDoc getString( ResourceBundle JavaDoc res, String JavaDoc resName, Locale JavaDoc locale) {
727             String JavaDoc resValue = res.getString(resName);
728             return resValue;
729         }
730 }
731
732
Popular Tags