> got me past all my confusion was printing out the relevent
> classes and writing all sorts of notes all over. Then I
> slapped my forehead and said "Duh!", and put the code
> together this morning.
That's where I've been going wrong - I left out the going "Duh" step.
Thanks Becky.
My office is full of slapping & duhing & productivity has increased.
--- Becky Moyer <[EMAIL PROTECTED]> wrote:
> Just so everyone knows, thanks for all your input. It helped out. What got
> me past all my confusion was printing out the relevent classes and writing
> all sorts of notes all over. Then I slapped my forehead and said "Duh!", and
> put the code together this morning.
>
> Here's what I did. I made my own MessageResource class and added a method
> called forceLoad(File). (I used a File because I was lazy and my method to
> find all of my .properties files already returned a Vector of Files. I
> could have used filenames or anything else).
>
> Then, in my actionServlet, I added the following:
> protected void initApplication()
> {
> super.initApplication();
> initOtherProperties();
> }
>
> where the method initOtherProperties does
> MessageResources mr = getServletContext().getAttribute(Action.MESSAGE_KEY);
> and iterates over my vector of Fields, passing each to
> ((MyMessageResources)mr).forceLoad(File);
>
> So it loads all properties into the same bundle and the properties are now
> available anywhere without using the bundle attribute of the bean:message
> tag.
>
> My custom MessageResources class is below; I also had to make a factory to
> load this, and I set my factory in web.xml using the factory init-param.
>
> The only thing that I doubt is quite right is my determination of locale
> from filename...I think that it works, but if someone knows of a more
> graceful way to do it, I'd welcome the advice. I have only tested it with
> US English.
>
> Thanks again!
> Becky
>
> PS - sorry the formatting is all weird, lost it when I pasted to the email
> editor.
>
> package com.my.struts.util;
>
> import org.apache.struts.util.*;
> import org.apache.log4j.Category;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.InputStream;
> import java.io.IOException;
> import java.util.Properties;
> import java.util.Enumeration;
>
> public class MyPropertyMessageResources extends PropertyMessageResources
> {
>
> private static final Category log =
> Category.getInstance("MyProperyMessageResources");
>
> public MyPropertyMessageResources(MessageResourcesFactory factory,
> �����String config)
> {
> super(factory, config);
> }
>
> public MyPropertyMessageResources(MessageResourcesFactory factory,
> �����String config,
> �����boolean returnNull)
> {
> super(factory, config, returnNull);
> }
>
> public void forceLoad(File propsFile)
> {
> //make a new properties object from the input stream
> Properties props = new Properties();
> InputStream is = null;
> try
> {
> �is = new FileInputStream(propsFile);
> �if (is == null)
> � {
> � return;
> � }
> �
> �props.load(is);
> �if (props.size() < 1)
> � return;
> �is.close();
> }
> catch (IOException ex)
> {
> �log.error("Exception reading properties file " + propsFile.getName(), ex);
> }
>
>
> //here i need to figure out what the localeKey should be
> String filename = propsFile.getName();
> String localeKey = this.getLocale(filename);
> if (localeKey.equals(""))
> localeKey=defaultLocale.getLanguage();
> log.debug("LocaleKey = (" + localeKey + ")");
> //add the properties to the HashMap messages one at a time
> synchronized (messages)
> {
> �Enumeration names = props.keys();
> �while (names.hasMoreElements())
> � {
> � String key = (String) names.nextElement();
> � log.debug("loading the following key: " + messageKey(localeKey, key) +
> " with value " + props.getProperty(key));
> � messages.put(messageKey(localeKey, key), props.getProperty(key));
> � }
> }
> return;
> }
>
> protected String getLocale(String filename)
> {
> String locale = "";
> int startChar = 0;
> int endChar = 0;
> for (int i=0; i < filename.length(); i++)
> {
> �if (filename.charAt(i) == '_')
> � startChar=i;
> �if (filename.charAt(i) == '.')
> � endChar=i-1;
> }
> if (startChar!=0)
> locale = filename.substring(startChar, endChar);
>
> return locale;
> }
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>