- ResourceBundleProducerNode now supports language parameter
authorzapata <zapata>
Fri, 5 Jul 2002 00:09:07 +0000 (00:09 +0000)
committerzapata <zapata>
Fri, 5 Jul 2002 00:09:07 +0000 (00:09 +0000)
- dc date format added to dateToMapAdapter

source/mir/config/exceptions/ConfigFailure.java
source/mir/producer/ResourceBundleProducerNode.java
source/mir/util/DateToMapAdapter.java

index 786fb93..be73355 100755 (executable)
@@ -1,25 +1,25 @@
-package mir.config.exceptions;\r
-\r
+package mir.config.exceptions;
+
 import multex.Failure;
 
-import java.io.*;\r
-\r
-public class ConfigFailure extends Failure {\r
-  private String locationDescription;\r
-  private Throwable cause;\r
-\r
-  public ConfigFailure (String aMessage, Throwable aCause, String aLocationDescription) {\r
-    super ("Configuration error at "+aLocationDescription+": "+aMessage,aCause);\r
-\r
-    locationDescription = aLocationDescription;\r
-    cause = aCause;\r
-  }\r
-\r
-  public ConfigFailure (String aMessage, String aLocationDescription) {\r
-    this (aMessage, (Throwable) null, aLocationDescription);\r
-  }\r
-\r
-  public ConfigFailure (String aMessage) {\r
-    this (aMessage, (Throwable) null, "?");\r
-  }\r
-}\r
+import java.io.*;
+
+public class ConfigFailure extends Failure {
+  private String locationDescription;
+  private Throwable cause;
+
+  public ConfigFailure (String aMessage, Throwable aCause, String aLocationDescription) {
+    super ("Configuration error at "+aLocationDescription+": "+aMessage, aCause);
+
+    locationDescription = aLocationDescription;
+    cause = aCause;
+  }
+
+  public ConfigFailure (String aMessage, String aLocationDescription) {
+    this (aMessage, (Throwable) null, aLocationDescription);
+  }
+
+  public ConfigFailure (String aMessage) {
+    this (aMessage, (Throwable) null, "?");
+  }
+}
index b7767cc..1adbb49 100755 (executable)
@@ -4,10 +4,12 @@ import java.util.*;
 import java.io.*;
 import org.apache.struts.util.MessageResources;
 import mir.util.*;
+import mir.misc.*;
 
 public class ResourceBundleProducerNode extends ProducerNodeDecorator {
   private String key;
   private String bundleIdentifier;
+  private String languageIdentifier;
 
   public ResourceBundleProducerNode(String aKey, String aBundleIdentifier, ProducerNode aSubNode) {
     super(aSubNode);
@@ -16,12 +18,32 @@ public class ResourceBundleProducerNode extends ProducerNodeDecorator {
     key = aKey;
   }
 
+  public ResourceBundleProducerNode(String aKey, String aBundleIdentifier, String aLanguageIdentifier, ProducerNode aSubNode) {
+    super(aSubNode);
+
+    bundleIdentifier = aBundleIdentifier;
+    languageIdentifier = aLanguageIdentifier;
+    key = aKey;
+  }
+
   public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
+    Object messages;
+
     try {
-      aValueMap.put(
-          key,
+      if (languageIdentifier!=null) {
+        messages =
+            new MessageMethodModel(
+                new Locale(ParameterExpander.expandExpression( aValueMap, languageIdentifier ), null ),
+                MessageResources.getMessageResources(ParameterExpander.expandExpression( aValueMap, bundleIdentifier ))
+            );
+      }
+      else {
+        messages =
           MessageResources.getMessageResources(
-              ParameterExpander.expandExpression( aValueMap, bundleIdentifier ))
+              ParameterExpander.expandExpression( aValueMap, bundleIdentifier ));
+      }
+      aValueMap.put(
+          key, messages
       );
 
       super.produce(aValueMap, aVerb, aLogger);
index fd8c2c1..54c7374 100755 (executable)
@@ -3,6 +3,8 @@ package mir.util;
 import java.util.*;
 import java.text.*;
 
+import mir.misc.*;
+
 public class DateToMapAdapter extends AbstractMap {
   Date date;
 
@@ -13,7 +15,12 @@ public class DateToMapAdapter extends AbstractMap {
   public Object get(Object aKey) {
     if (aKey instanceof String) {
       try {
-        return new SimpleDateFormat((String) aKey).format(date);
+        // ML: quick fix to allow for the dc encoding now...
+        if (((String) aKey).equals("dc")) {
+          return StringUtil.date2w3DateTime(new GregorianCalendar());
+        }
+        else
+          return new SimpleDateFormat((String) aKey).format(date);
       }
       catch (Throwable t) {
         throw new RuntimeException( "Can't format date with format " + (String) aKey + ": " + t.getMessage());