[opencms-dev] [locale vs. language when accessing content] OpenCMS does only use the language and does not handle Locales properly?

mailinglists mailinglists at pcom.at
Wed Sep 24 18:13:04 CEST 2008


Hi,

When trying to find out if a specific xml element is present in a 
content item I had the problem that I could not use 
"request.getLocale()" as locale for the CmsJspTagContentCheck.

The browsers request locale in my case is "en_US". When using the 
request locale to access or check content (which in fact is "en" 
content) the api does return null (or false). When creating a new locale 
after cropping the country from the Locale everything works fine (see 
code below). As the cms backend does only provide interfaces to set the 
content language and not the content locale I assume this to be an 
improper implementation of Locale/language handling.

br,
Philip

Example 1 - works fine:
******************
code:
     List li = 
content.getContentContainer().getXmlDocument().getNames(java.util.Locale.ENGLISH); 

     log.debug("Locale: "+java.util.Locale.ENGLISH);
     log.debug("Elements: "+li);
output:
     Locale: en
     Elements: [Elements[1]/Item[1], ShowBreadCrumbs[1], 
ShowLeftNavigation[1], Elements[1]/elementParam2[1], ...<snip>


Example 2 - returns empty list:
******************
code:
     List li = 
content.getContentContainer().getXmlDocument().getNames(request.getLocale()); 

     log.debug("Locale: "+request.getLocale());
     log.debug("Elements: "+li);
output:
     Locale: en_US
     Elements: []


Example 2 - works fine:
******************
code:
     List li = 
content.getContentContainer().getXmlDocument().getNames(new 
Locale(request.getLocale().getLanguage()));
     log.debug("Locale: "+new Locale(request.getLocale().getLanguage()));
     log.debug("Elements: "+li);
output:
     Locale: en
     Elements: [Elements[1]/Item[1], ShowBreadCrumbs[1], 
ShowLeftNavigation[1], Elements[1]/elementParam2[1], ...<snip>





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20080924/c9076290/attachment.htm>


More information about the opencms-dev mailing list