merge of localization branch into HEAD. mh and zap
[mir.git] / source / mir / util / ResourceBundleGeneratorFunction.java
1 package mir.util;
2
3 import java.util.*;
4 import org.apache.struts.util.MessageResources;
5
6 import mir.generator.*;
7
8 public class ResourceBundleGeneratorFunction implements Generator.GeneratorFunction {
9   private MessageResources messages;
10   private Locale locale;
11
12   public ResourceBundleGeneratorFunction(Locale aLocale, MessageResources aMessages) {
13     this.locale = aLocale;
14     this.messages = aMessages;
15   }
16
17   public Object perform(List aParameters) throws GeneratorExc {
18     List extraParameters = new Vector(aParameters);
19
20     if (aParameters.size()<1)
21       throw new GeneratorExc("ResourceBundleGeneratorFunction: at least 1 parameter expected");
22
23     if (!(aParameters.get(0) instanceof String))
24       throw new GeneratorExc("encodeHTMLGeneratorFunction: parameters must be strings");
25
26     String key = (String) aParameters.get(0);
27     extraParameters.remove(0);
28     String message = messages.getMessage(locale, key, extraParameters.toArray());
29
30     if (message == null) {
31       return new String("??" + key + "??");
32     }
33     else {
34       return message;
35     }
36   };
37 }