kpiroumian 2004/01/16 07:55:39
Modified: src/java/org/apache/cocoon/i18n XMLResourceBundle.java
XMLResourceBundleFactory.java
Log:
Reload the translation if the dictionary was modified.
Patch# 26138
Thanks to [EMAIL PROTECTED] (Kamal Dalal)
Revision Changes Path
1.6 +27 -6
cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
Index: XMLResourceBundle.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLResourceBundle.java 23 Dec 2003 15:28:33 -0000 1.5
+++ XMLResourceBundle.java 16 Jan 2004 15:55:38 -0000 1.6
@@ -125,7 +125,7 @@
/**
* Bundle validity
*/
- private SourceValidity validity;
+ private SourceValidity validity = null;
/**
* Locale of the bundle
@@ -327,10 +327,16 @@
try {
resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
source = resolver.resolveURI(sourceURL);
- HashMap values = new HashMap();
- SourceUtil.toSAX(source, new SAXContentHandler(values));
- this.validity = source.getValidity();
- this.values = values;
+ SourceValidity sourceValidity = source.getValidity();
+ if (validity == null || validity.isValid( sourceValidity ) ==
SourceValidity.INVALID) {
+ HashMap values = new HashMap();
+ SourceUtil.toSAX(source, new SAXContentHandler(values));
+ this.validity = sourceValidity;
+ this.values = values;
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Loaded XML bundle: " + name + ",
locale: " + locale);
+ }
+ }
} catch (ServiceException e) {
throw new ProcessingException("Can't lookup source resolver", e);
} catch (MalformedURLException e) {
@@ -419,5 +425,20 @@
*/
public Set keySet() {
return Collections.unmodifiableSet(values.keySet());
+ }
+
+ /**
+ * Reload this bundle if URI's timestam is newer than ours
+ *
+ * @param sourceURL source URL of the XML bundle
+ **/
+ public void update(String sourceURL)
+ {
+ try {
+ load(sourceURL);
+ }
+ catch (Exception e) {
+ getLogger().info("Resource update failed. " + name + ", locale:
" + locale + " Exception: " + e.getMessage());
+ }
}
}
1.10 +7 -6
cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
Index: XMLResourceBundleFactory.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XMLResourceBundleFactory.java 15 Jan 2004 15:24:31 -0000 1.9
+++ XMLResourceBundleFactory.java 16 Jan 2004 15:55:38 -0000 1.10
@@ -272,10 +272,10 @@
", directory: " + directories[index]);
}
String fileName = getFileName(directories[index], name, locale);
- XMLResourceBundle bundle = (XMLResourceBundle)selectCached(fileName);
+ XMLResourceBundle bundle = selectCached(fileName);
if (bundle == null) {
synchronized (this) {
- bundle = (XMLResourceBundle)selectCached(fileName);
+ bundle = selectCached(fileName);
if (bundle == null) {
XMLResourceBundle parentBundle = null;
if (locale != null && !locale.getLanguage().equals("")) {
@@ -414,10 +414,11 @@
* @param fileName file name of the bundle
* @return the cached bundle; null, if not found
*/
- protected Component selectCached(String fileName) {
- Component bundle = null;
+ protected XMLResourceBundle selectCached(String fileName) {
+ XMLResourceBundle bundle = null;
try {
- bundle = super.select(fileName);
+ bundle = (XMLResourceBundle)super.select(fileName);
+ bundle.update(fileName);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Returning from cache: " + fileName);
}