Using ResourceBundles (without having to restart container)

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
 
(ResourceBundles, property-files, properties)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
taken from the newsgroup:
+
''taken from the newsgroup:''
  
 
It's a pain to work with i18n'ed jsp pages, and restart the container every time I want to see if the keys are working ok.
 
It's a pain to work with i18n'ed jsp pages, and restart the container every time I want to see if the keys are working ok.
  
Actually we have implemented such a feature in OpenCms 6.2.
+
Actually there is a feature since OpenCms 6.2 for this:
  
 
All OpenCms module based message bundles are flushed if you clear the cache,
 
All OpenCms module based message bundles are flushed if you clear the cache,
Line 18: Line 18:
  
 
only that we do have the flushable bundle cache.  
 
only that we do have the flushable bundle cache.  
 +
 +
You should put the property-files into your module's classes folder in opencms.
 +
<br>COMMENT: This didn't work for me, but it works putting it in "/tomcat/webapps/opencms/WEB-INF/classes".
  
 
Example:
 
Example:
<nowiki>
+
<code lang="java">
<%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %>
+
<%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %>
 
+
<%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %>
+
<%
 
+
org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache(); // this is probably just good for testing
<%
+
java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new  
  org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache();
+
java.util.Locale("es"));
  java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new java.util.Locale("es"));
+
%>
%>
+
<%= messages.getString("test.label1") %>
 
+
</code>
 
+
<%= messages.getString("test.label1") %>
+
</nowiki>
+

Latest revision as of 19:58, 14 November 2008

taken from the newsgroup:

It's a pain to work with i18n'ed jsp pages, and restart the container every time I want to see if the keys are working ok.

Actually there is a feature since OpenCms 6.2 for this:

All OpenCms module based message bundles are flushed if you clear the cache, which can be triggered by "Administration View > Workplace Tools > Re-Initialize the Workplace".

You can also use this caching behaviour in your Java code like this:

org.opencms.i18n.CmsResourceBundleLoader.getBundle(baseName, locale);

which is the same as

java.util.resourceBundle.getBundle(baseName, locale);

only that we do have the flushable bundle cache.

You should put the property-files into your module's classes folder in opencms.
COMMENT: This didn't work for me, but it works putting it in "/tomcat/webapps/opencms/WEB-INF/classes".

Example:

 <%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %>
 <%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %>
 <%
 org.opencms.i18n.CmsResourceBundleLoader.flushBundleCache(); // this is probably just good for testing
 java.util.ResourceBundle messages = org.opencms.i18n.CmsResourceBundleLoader.getBundle("your_bundle_here", new 
 java.util.Locale("es"));
 %>
 <%= messages.getString("test.label1") %>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox