You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/03/18 17:43:40 UTC
svn commit: r158092 -
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
cocoon/branches/BRANCH_2_1_X/status.xml
Author: vgritsenko
Date: Fri Mar 18 08:43:37 2005
New Revision: 158092
URL: http://svn.apache.org/viewcvs?view=rev&rev=158092
Log:
Bugfix: wrong usage of SourceValidity.isValid methods.
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java?view=diff&r1=158091&r2=158092
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java Fri Mar 18 08:43:37 2005
@@ -1,12 +1,12 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,7 +42,7 @@
/**
* Implementation of <code>Bundle</code> interface for XML resources. Represents a
* single XML message bundle.
- *
+ *
* XML format for this resource bundle implementation is the following:
* <pre>
* <catalogue xml:lang="en">
@@ -51,13 +51,13 @@
* ...
* </catalogue>
* </pre>
- *
+ *
* Value can be any well formed XML snippet and it will be cached by the key specified
* in the attrbute <code>key</code>. Objects returned by this {@link Bundle} implementation
* are instances of the {@link ParamSaxBuffer} class.
- *
+ *
* @author <a href="mailto:dev@cocoon.apache.org">Apache Cocoon Team</a>
- * @version CVS $Id$
+ * @version $Id$
*/
public class XMLResourceBundle extends AbstractLogEnabled
implements Bundle, Serviceable {
@@ -66,23 +66,23 @@
* Namespace for the Bundle markup
*/
public static final String NS = "http://apache.org/cocoon/i18n/2.0";
-
+
/**
* XML bundle root element name
*/
public static final String EL_CATALOGUE = "catalogue";
-
+
/**
* XML bundle message element name
*/
public static final String EL_MESSAGE = "message";
-
+
/**
- * XML bundle message element's key attribute name
+ * XML bundle message element's key attribute name
*/
public static final String AT_KEY = "key";
-
-
+
+
/**
* Bundle name
*/
@@ -91,7 +91,7 @@
/**
* Bundle validity
*/
- private SourceValidity validity = null;
+ private SourceValidity validity;
/**
* Locale of the bundle
@@ -107,7 +107,7 @@
* Objects stored in the bundle
*/
protected HashMap values;
-
+
/**
* Service Manager
*/
@@ -120,12 +120,12 @@
private Map values;
private int state;
private String namespace;
- private ParamSaxBuffer buffer;
-
+ private ParamSaxBuffer buffer;
+
public SAXContentHandler(Map values) {
this.values = values;
}
-
+
public void setDocumentLocator(Locator arg0) {
// Ignore
}
@@ -233,7 +233,7 @@
}
}
}
-
+
/**
* Compose this instance
*
@@ -287,20 +287,23 @@
*/
protected void load(String sourceURL)
throws IOException, ProcessingException, SAXException {
-
Source source = null;
SourceResolver resolver = null;
try {
- resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
- source = resolver.resolveURI(sourceURL);
- 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);
+ int valid = this.validity == null? SourceValidity.INVALID: this.validity.isValid();
+ if (valid != SourceValidity.VALID) {
+ // Saved validity is not valid, get new source and validity
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(sourceURL);
+ SourceValidity sourceValidity = source.getValidity();
+ if (valid == SourceValidity.INVALID || this.validity.isValid(sourceValidity) != SourceValidity.VALID) {
+ HashMap values = new HashMap();
+ SourceUtil.toSAX(source, new SAXContentHandler(values));
+ this.validity = sourceValidity;
+ this.values = values;
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Loaded XML bundle: " + this.name + ", locale: " + this.locale);
+ }
}
}
} catch (ServiceException e) {
@@ -311,7 +314,7 @@
if (source != null) {
resolver.release(source);
}
- manager.release(resolver);
+ this.manager.release(resolver);
}
}
@@ -339,7 +342,7 @@
* @return the locale
*/
public Locale getLocale() {
- return locale;
+ return this.locale;
}
/**
@@ -372,11 +375,11 @@
return null;
}
- Object value = values.get(key);
+ Object value = this.values.get(key);
if (value != null) {
return value.toString();
}
-
+
if(this.parent != null) {
return this.parent.getString(key);
}
@@ -390,21 +393,20 @@
* @return the enumeration of keys
*/
public Set keySet() {
- return Collections.unmodifiableSet(values.keySet());
+ return Collections.unmodifiableSet(this.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)
- {
+ */
+ public void update(String sourceURL) {
try {
- load(sourceURL);
- }
- catch (Exception e) {
- getLogger().info("Resource update failed. " + name + ", locale: " + locale + " Exception: " + e.getMessage());
+ load(sourceURL);
+ } catch (Exception e) {
+ getLogger().info("Resource update failed. " + this.name + ", locale: " + this.locale +
+ " Exception: " + e);
}
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java?view=diff&r1=158091&r2=158092
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java Fri Mar 18 08:43:37 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,12 +48,20 @@
* @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
* @author <a href="mailto:oleg@one.lv">Oleg Podolsky</a>
* @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
- * @version CVS $Id$
+ * @version $Id$
*/
public class XMLResourceBundleFactory
implements BundleFactory, Serviceable, Configurable, Disposable, ThreadSafe, LogEnabled {
- protected Map cache = Collections.synchronizedMap(new HashMap());
+ /**
+ * Cache of the bundles by file name
+ */
+ protected final Map cache = Collections.synchronizedMap(new HashMap());
+
+ /**
+ * Cache for the file names of the bundles that were not found
+ */
+ protected final Map cacheNotFound = new HashMap();
/**
* Should we load bundles to cache on startup or not?
@@ -66,11 +74,6 @@
protected String directory;
/**
- * Cache for the names of the bundles that were not found
- */
- protected final Map cacheNotFound = new HashMap();
-
- /**
* The logger
*/
private Logger logger;
@@ -78,7 +81,7 @@
/**
* Service Manager
*/
- protected ServiceManager manager = null;
+ protected ServiceManager manager;
/**
* Source resolver
@@ -140,7 +143,7 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Configured with: cacheAtStartup = " +
- cacheAtStartup + ", directory = '" + directory + "'");
+ this.cacheAtStartup + ", directory = '" + this.directory + "'");
}
}
@@ -196,7 +199,8 @@
* @return the bundle
* @exception ComponentException if a bundle is not found
*/
- public Bundle select(String directory, String name, String localeName) throws ComponentException {
+ public Bundle select(String directory, String name, String localeName)
+ throws ComponentException {
return select(directory, name, new Locale(localeName, localeName));
}
@@ -210,7 +214,8 @@
* @return the bundle
* @exception ComponentException if a bundle is not found
*/
- public Bundle select(String directory, String name, Locale locale) throws ComponentException {
+ public Bundle select(String directory, String name, Locale locale)
+ throws ComponentException {
String []directories = new String[1];
directories[0] = directory;
return select(directories, name, locale);
@@ -227,7 +232,7 @@
* @exception ComponentException if a bundle is not found
*/
public Bundle select(String[] directories, String name, Locale locale)
- throws ComponentException {
+ throws ComponentException {
Bundle bundle = _select(directories, 0, name, locale);
if (bundle == null) {
throw new ComponentException(name, "Unable to locate resource: " + name);
@@ -246,7 +251,7 @@
private XMLResourceBundle _select(String[] directories, int index, String name,
Locale locale) {
if (getLogger().isDebugEnabled()) {
- getLogger().debug("selecting from: " + name + ", locale: " + locale +
+ getLogger().debug("Selecting from: " + name + ", locale: " + locale +
", directory: " + directories[index]);
}
String cacheKey = getCacheKey(directories, index, name, locale);
@@ -304,10 +309,10 @@
return bundle;
} catch (ResourceNotFoundException e) {
getLogger().info("Resource not found: " + name + ", locale: " + locale +
- ", bundleName: " + fileName + ". Exception: " + e.toString());
+ ", bundleName: " + fileName + ". Exception: " + e);
} catch (SourceNotFoundException e) {
getLogger().info("Resource not found: " + name + ", locale: " + locale +
- ", bundleName: " + fileName + ". Exception: " + e.toString());
+ ", bundleName: " + fileName + ". Exception: " + e);
} catch (SAXParseException e) {
getLogger().error("Incorrect resource format", e);
} catch (Exception e) {
@@ -411,7 +416,7 @@
*/
protected XMLResourceBundle selectCached(String fileName) {
XMLResourceBundle bundle = null;
- bundle = (XMLResourceBundle)cache.get(fileName);
+ bundle = (XMLResourceBundle) this.cache.get(fileName);
if (bundle != null) {
bundle.update(fileName);
if (getLogger().isDebugEnabled()) {
@@ -434,7 +439,7 @@
* otherwise, false.
*/
protected boolean isNotFoundBundle(String fileName) {
- String result = (String) (cacheNotFound.get(fileName));
+ String result = (String) this.cacheNotFound.get(fileName);
if (result != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Returning from not_found_cache: " + fileName);
@@ -457,7 +462,7 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Updating not_found_cache: " + fileName);
}
- cacheNotFound.put(fileName, fileName);
+ this.cacheNotFound.put(fileName, fileName);
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Updating cache: " + fileName);
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=158091&r2=158092
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Mar 18 08:43:37 2005
@@ -202,6 +202,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="VG" type="fix">
+ Fix caching of i18n bundles with expires validities.
+ </action>
<action dev="VG" type="add">
Implemented error handling for the internal requests. Error handling for
the internal requests configured using <code>when</code> attribute on
@@ -240,7 +243,8 @@
default platform encoding is used.
</action>
<action dev="JQ" type="add">
- Added QueryBean as a standalone block, copied over from 2.2.0. Removed the original from the Lucene Block. Stores Favourites using OJB in HSQLDB.
+ Added QueryBean as a standalone block, copied over from 2.2.0. Removed
+ the original from the Lucene Block. Stores Favourites using OJB in HSQLDB.
</action>
<action dev="SW" type="update">
CForms: separate <code>FormattingDateConvertor</code> that uses