Hi Neeme!

> > > Neeme Praks has used it.  He is going to be the maintainer for this.
> >
> > Great. Neeme, I've look at the code to the XMLResourceBundle/Factory
> > class and it seems to be mostly clear. What is not currently not clear
> > to me is the markup of the input xml documents. What format should
> > they be in ?
> 
> Plain XML :-)
> Example:
> <resources>
>       <foo>bar</foo>
> </resources>
> 
> then, in code, you can get "bar" like this:
> bundle.getString("/resources/foo");

        ok. Thanks for clearing that up! :-)

> > I also noticed that the XMLResourceBundle class depends on Xerces and
> > Xalan classes - is there any way of being able to make it function
> > independantly of parser and xslt processor ?
> 
> If there is a standard API for XPath queries (I'm not aware of any), then it
> would be easy. Otherwise, we would need to write our own (or extract from
> Xalan) XPath query "evaluator".

        *nod*

        I've attached a diff which cleans up the code a little - removes
        unused imports, replaces the Xerces classes with javax.xml.parsers.*,
        and updates the logkit code to the new API. Hope the changes are ok
        with you.

        I also noticed that the XPathAPI code is actually a part of Xalan 2
        now. Are there intentions to package Xalan 2 with avalon ? or will
        this file be duplicated for a little while longer ?

        Do you know when this code will be become a part of avalon proper ?
        I'd like to use these classes in some cocoon code I'm writing.

        Cheers,

        Marcus
 
-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   Open Software Associates GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'     Email : [EMAIL PROTECTED]
          &&&&.        Business Hours : +49 69 9757 200
    &&&&&&&:           After Hours    : +49 69 49086750
Index: XMLResourceBundle.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon/src/scratchpad/org/apache/avalon/excalibur/i18n/XMLResourceBundle.java,v

retrieving revision 1.2
diff -u -r1.2 XMLResourceBundle.java
--- XMLResourceBundle.java      2001/05/01 13:41:42     1.2
+++ XMLResourceBundle.java      2001/06/07 16:02:16
@@ -16,27 +16,23 @@
 
 /** W3C DOM classes **/
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.NamedNodeMap;
 
-/** Xerces classes **/
-import org.apache.xerces.dom.DocumentImpl;
-import org.apache.xerces.dom.TextImpl;
-import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.SAXException;
-
-/** Xalan classes **/
-import org.apache.xalan.xpath.XPathSupport;
-import org.apache.xalan.xpath.XPath;
-import org.apache.xalan.xpath.XPathProcessorImpl;
-import org.apache.xalan.xpath.xml.XMLParserLiaisonDefault;
-import org.apache.xalan.xpath.xml.PrefixResolverDefault;
-import org.apache.xalan.xpath.XObject;
+/** Parser classes **/
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+//import javax.xml.parsers.ParserConfigurationException;
+import org.xml.sax.InputSource;
 
+/** XPath classes (already available in Xalan 2) **/
+//import org.apache.xpath.XPathAPI;
+
 /** Avalon classes **/
 import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.log.Logger;
+import org.apache.log.Hierarchy;
 
 /**
  * @author <a href="mailto:[EMAIL PROTECTED]";>Mike Engelhart</a>
@@ -54,11 +50,17 @@
     private String name = "";
     private Document doc;
     private Locale loc;
+
+    protected static DocumentBuilderFactory docfactory =
+       DocumentBuilderFactory.newInstance();
     protected XMLResourceBundle parent = null;
 
+    protected Logger logger =
+       Hierarchy.getDefaultHierarchy().getLoggerFor("XMLResourceBundle");
+
     public XMLResourceBundle(String name, Document doc, Locale loc, XMLResourceBundle 
p, boolean cacheAtStartup)
     {
-        getLogger().info("Constructing XMLResourceBundle: " + name + ", locale: " + 
loc);
+        logger.info("Constructing XMLResourceBundle: " + name + ", locale: " + loc);
         this.name = name;
         this.doc = doc;
         this.loc = loc;
@@ -75,9 +77,8 @@
     // Load the XML document based on bundleName
     protected static Document loadResourceBundle(String bundleName) throws Exception
     {
-        DOMParser parser = new DOMParser();
-        parser.parse(bundleName);
-        return parser.getDocument();
+        DocumentBuilder builder = docfactory.newDocumentBuilder();
+        return builder.parse(new InputSource(bundleName));
     }
 
     public String getName()
@@ -115,7 +116,7 @@
 
     private void cacheNotFoundKey(String key)
     {
-        getLogger().debug(name + ": caching not_found: " + key);
+        logger.debug(name + ": caching not_found: " + key);
         cacheNotFound.put(key, "");
     }
 
@@ -224,7 +225,7 @@
         }
         catch (Exception e)
         {
-            getLogger().error(name + ": error while locating resource: " + key, e);
+            logger.error(name + ": error while locating resource: " + key, e);
         }
         return value;
     }
@@ -280,7 +281,7 @@
         }
         catch (Exception e)
         {
-            getLogger().error("Error while locating resource", e);
+            logger.error("Error while locating resource", e);
         }
         return node;
     }
@@ -316,12 +317,12 @@
                     varValue = dictionary.get(varKey);
                 if (varValue != null)
                 {
-                    getLogger().debug("Substituting var: " + varKey + " --> " + 
varValue);
+                    logger.debug("Substituting var: " + varKey + " --> " + varValue);
                     result.append(varValue);
                 }
                 else
                 {
-                    getLogger().warn(name + ": var not found: " + varKey);
+                    logger.warn(name + ": var not found: " + varKey);
                     result.append('{').append(varKey).append('}');
                 }
                 if (endPos < lastPos)
Index: XMLResourceBundleFactory.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon/src/scratchpad/org/apache/avalon/excalibur/i18n/XMLResourceBundleFactory.java,v

retrieving revision 1.2
diff -u -r1.2 XMLResourceBundleFactory.java
--- XMLResourceBundleFactory.java       2001/05/01 13:41:42     1.2
+++ XMLResourceBundleFactory.java       2001/06/07 16:02:16
@@ -11,12 +11,11 @@
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.MissingResourceException;
-import java.util.Vector;
 
 import org.xml.sax.SAXParseException;
 
-import org.apache.log.LogKit;
 import org.apache.log.Logger;
+import org.apache.log.Hierarchy;
 
 /**
  * This is the XMLResourceBundleFactory, the method for getting and
@@ -42,7 +41,8 @@
     protected static Hashtable cache = new Hashtable();
     protected static Hashtable cache_not_found = new Hashtable();
     protected static String directory;
-    protected static Logger logger = LogKit.getLoggerFor("XMLResourceBundle");
+    protected static Logger logger =
+       Hierarchy.getDefaultHierarchy().getLoggerFor("XMLResourceBundle");
 
     public static XMLResourceBundle getBundle(String name) throws 
MissingResourceException
     {
@@ -61,7 +61,7 @@
             throw new MissingResourceException("Unable to locate resource: " + name, 
XMLResourceBundleFactory.class.getName(), "");
         else
             bundle.setLogger(logger);
-            return bundle;
+        return bundle;
     }
 
     private static XMLResourceBundle _getBundle(String name, Locale loc)
@@ -96,7 +96,7 @@
             throw new MissingResourceException("Unable to locate resource: " + name, 
"XMLResourceBundleFactory", "");
         else
             bundle.setLogger(logger);
-            return bundle;
+        return bundle;
     }
 
     private static XMLResourceBundle _getBundle(String name, Locale loc, boolean 
cacheAtStartup)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to