You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by kp...@apache.org on 2002/12/17 13:03:07 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/i18n XMLResourceBundle.java
kpiroumian 2002/12/17 04:03:07
Modified: . changes.xml
src/java/org/apache/cocoon/i18n XMLResourceBundle.java
Log:
<action dev="KP" type="fix" fixes-bug="15431" due-to="Michael Gerzabek" due-to-email="michael.gerzabek@gmx.net">
Perform correct source resolution in XMLResourceBundle.
Now i18n transformer can obtain dictionaries using any supported source (e.g. 'cocoon:/').
</action>
Revision Changes Path
1.309 +5 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.308
retrieving revision 1.309
diff -u -r1.308 -r1.309
--- changes.xml 17 Dec 2002 11:13:21 -0000 1.308
+++ changes.xml 17 Dec 2002 12:03:06 -0000 1.309
@@ -40,6 +40,10 @@
</devs>
<release version="@version@" date="@date@">
+ <action dev="KP" type="fix" fixes-bug="15431" due-to="Michael Gerzabek" due-to-email="michael.gerzabek@gmx.net">
+ Perform correct source resolution in XMLResourceBundle.
+ Now i18n transformer can obtain dictionaries using any supported source (e.g. 'cocoon:/').
+ </action>
<action dev="KP" type="update">
Added Greek translation, thanks to Stavros Kounis (gounis@osmosis.gr).
Corrected Armenian translation to be real Unicode and be
1.12 +34 -16 xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java
Index: XMLResourceBundle.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundle.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XMLResourceBundle.java 13 Nov 2002 22:09:35 -0000 1.11
+++ XMLResourceBundle.java 17 Dec 2002 12:03:07 -0000 1.12
@@ -68,12 +68,16 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
import org.apache.avalon.excalibur.xml.xpath.XPathProcessor;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+
/**
* Implementation of <code>Bundle</code> interface for XML resources.
* Represents a single XML message bundle.
@@ -182,14 +186,28 @@
* @exception ParserConfigurationException if no parser is configured
* @exception SAXException if an error occurs while parsing the file
*/
- protected static Document loadResourceBundle(String fileName)
+ protected synchronized Document loadResourceBundle(String fileName)
throws IOException, ParserConfigurationException, SAXException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
+ Source source = null;
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(fileName);
+ return builder.parse(new InputSource(source.getInputStream()));
+ }
+ catch (Exception e) {
+ logger.warn("XMLResourceBundle: Non excalibur-source " + fileName, e);
+ }
+ finally {
+ resolver.release(source);
+ manager.release(resolver);
+ }
+ // Fallback try
return builder.parse(fileName);
}
-
/**
* Gets the name of the bundle.
*
@@ -273,15 +291,15 @@
* @return the value
*/
private Node getFromCache(String key) {
- Object value;
- if (logger.isDebugEnabled())
+ Object value;
+ if (logger.isDebugEnabled())
logger.debug(name + ": returning from cache: " + key);
- value = cache.get(key);
- if(value == null)
- logger.debug("Could not find!");
+ value = cache.get(key);
+ if(value == null)
+ logger.debug("Could not find!");
- return (Node) value;
+ return (Node) value;
}
/**
@@ -292,7 +310,7 @@
* @param pathToParent XPath to the parent node
*/
private void cacheAll(Node parent, String pathToParent) {
- if (logger.isDebugEnabled())
+ if (logger.isDebugEnabled())
logger.debug("Caching all messages");
NodeList children = parent.getChildNodes();
@@ -302,7 +320,7 @@
Node child = children.item(i);
if(child.getNodeType() == Node.ELEMENT_NODE) {
- StringBuffer pathToChild = new StringBuffer(pathToParent)
+ StringBuffer pathToChild = new StringBuffer(pathToParent)
.append('/').append(child.getNodeName());
NamedNodeMap attrs = child.getAttributes();
@@ -315,15 +333,15 @@
temp = attrs.item(j);
if (!temp.getNodeName().equalsIgnoreCase("xml:lang"))
pathToChild.append("[@").append(temp.getNodeName())
- .append("='").append(temp.getNodeValue())
+ .append("='").append(temp.getNodeValue())
.append("']");
}
}
- cacheKey(pathToChild.toString(), child);
+ cacheKey(pathToChild.toString(), child);
}
- if (logger.isDebugEnabled())
+ if (logger.isDebugEnabled())
logger.debug("What we've cached: " + child.toString());
}
}
@@ -337,9 +355,9 @@
private Object _getObject(String key) {
if (key == null) return null;
- Node value = getFromCache(key);
+ Node value = getFromCache(key);
if (value == null && !cacheNotFoundContains(key)) {
- if (doc != null)
+ if (doc != null)
value = (Node)_getObject(this.doc.getDocumentElement(), key);
if (value == null) {
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org