cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@localbar.com>
Subject Re: XMLResourceBundle
Date Fri, 23 Jun 2000 08:24:21 GMT

Thanks for a nice util.

And I am 'stealing' it straight off, since I was half way with a similar thing.

However,
private static Document resource;

????
That can't be right. You would want more than one resource document, right?

Niclas

Mike Engelhart wrote:

> I've put together 2 classes that are intended to be a simple equivalent to
> the java.util.ResourceBundle's that have become tedious for me to use in an
> XML environment.
> I've attached the source for the 2 classes XMLResourceBundleFactory and
> XMLResourceBundle.
>
> XMLResourceBundleFactory has the standard getBundle(String name) and
> getBundle(String name, Locale loc) factory methods and implements a simple
> cache using SoftReference's (btw is C2 skipping on JDK 1.1.x??).   There is
> a lot missing in comparison to all the things that java.util.ResourceBundle
> handles such as automatic ResourceBundle fallback (which shouldn't be too
> hard to implement) and a number of other things.
> The XMLResourceBundle class has a getString(String xPath) which takes an
> xPath and returns the string value of the Element that it's pointing to (see
> sample schema below - this needs to be determined or a better
> getString(xPath) needs to be written).   Also there is a getRole(String
> xPath) which returns a Node which can be passed to a getString(Node role,
> String key) method if you're going to be using the same Node over and over.
> To speed up development right now it's using the XPathAPI  which is a sample
> class that comes with the Xalan distribution for doing XPath manipulation
> (today is the first day I've used the XPath API so I don't really know what
> I'm doing).  The method calls appear to  be very slow (it mentions this in
> the inline documentation) so if anyone knows anything about the XPath
> low-level API and is interested in getting the performance increased that
> would be great.
>
> I just wanted to get these out to anyone who might be interested....
>
> I'm using the schema that Neeme Praks had used in one of his emails but this
> can easily be changed:   Here's a sample resource.xml file:
>
> <?xml version="1.0"?>
> <resources xml:lang="en">
>   <forms>
>       <contacts-search>
>           <desc>
>             <searchfor>find:</searchfor>
>             <field-to-search>what:</field-to-search>
>             <from>where:</from>
>             <from-mycontacts>my contacts</from-mycontacts>
>             <from-allmembers>all members</from-allmembers>
>           </desc>
>
>           <input>
>               <field-to-search>
>                 <all>all</all>
>                 <firstname>first name</firstname>
>                 <lastname>last name</lastname>
>                 <phone>phone</phone>
>                 <email>e-mail</email>
>               </field-to-search>
>             <submit>Search</submit>
>           </input>
>       </contacts-search>
>   </forms>
> </resources>
>
> and sample usage:
> XMLResourceBundle bundle = XMLResourceBundleFactory.getBundle("resource");
> System.out.println(bundle.getString("/resources/forms/contacts-search/desc/f
> rom-mycontacts"));
> System.out.println(bundle.getString("/resources/forms/contacts-search/input/
> field-to-search/lastname"));
> System.out.println(bundle.getString("/resources/forms/contacts-search/desc/f
> rom"));
> System.out.println(bundle.getString("/resources/forms/contacts-search/input/
> field-to-search/phone"));
> System.out.println(bundle.getString("/resources/forms/contacts-search/input/
> field-to-search/email"));
> System.out.println(bundle.getString("/resources/forms/contacts-search/desc/s
> earchfor"));
> Node role =
> bundle.getRole("/resources/forms/contacts-search/input/field-to-search");
> System.out.println(bundle.getString(role, "lastname"));
> System.out.println(bundle.getString(role, "firstname"));
> System.out.println(bundle.getString(role, "phone"));


Mime
View raw message