i18n-feature based on kellans proposal implemented. the resource-bundles are located...
authoridfx <idfx>
Sun, 17 Mar 2002 21:32:33 +0000 (21:32 +0000)
committeridfx <idfx>
Sun, 17 Mar 2002 21:32:33 +0000 (21:32 +0000)
14 files changed:
build.xml
build.xml-new
bundles/admin.properties [new file with mode: 0755]
bundles/admin_de.properties [new file with mode: 0755]
source/Mir.java
source/OpenMir.java
source/mir/misc/HTMLTemplateProcessor.java
source/mir/misc/MessageMethodModel.java
source/mir/servlet/ServletModule.java
source/mircoders/producer/Producer.java
source/mircoders/servlet/ServletModuleComment.java
source/mircoders/servlet/ServletModuleImages.java
source/mircoders/servlet/ServletModuleLinksImcs.java
source/mircoders/servlet/ServletModuleMessage.java

index 11c97f7..2b325ec 100755 (executable)
--- a/build.xml
+++ b/build.xml
@@ -71,6 +71,9 @@
         <exclude name="xerces.jar"/>
       </fileset>
     </copy>
+    <copy todir="${deploy.home}/WEB-INF/classes">
+      <fileset dir="bundles"/>
+    </copy>
     <mkdir  dir="${javadoc.home}"/>
     <mkdir  dir="${deploy.home}/log"/>
 
index 6dd605e..1608988 100755 (executable)
         <exclude name="xerces.jar"/>
       </fileset>
     </copy>
+    <copy todir="${deploy.home}/WEB-INF/classes">
+      <fileset dir="bundles"/>
+    </copy>
     <mkdir  dir="${javadoc.home}"/>
     <mkdir  dir="${deploy.home}/log"/>
 
diff --git a/bundles/admin.properties b/bundles/admin.properties
new file mode 100755 (executable)
index 0000000..b400b0c
--- /dev/null
@@ -0,0 +1 @@
+hello=Hello
\ No newline at end of file
diff --git a/bundles/admin_de.properties b/bundles/admin_de.properties
new file mode 100755 (executable)
index 0000000..cdf9a49
--- /dev/null
@@ -0,0 +1 @@
+hello=halloli
\ No newline at end of file
index 123f32a..abd442a 100755 (executable)
@@ -159,10 +159,11 @@ public class Mir extends AbstractServlet {
       ServletModuleDispatch.dispatch(smod,req,res);
     }
     catch (ServletModuleException e) {
-                       handleError(res, res.getWriter(), "ServletException in Module " + moduleName + " -- " + e.toString());
+                       handleError(req, res, res.getWriter(),
+                                                                       "ServletException in Module " + moduleName + " -- " + e.toString());
                }
     catch (ServletModuleUserException e) {
-      handleUserError(res,res.getWriter(), "User error" + e.toString());
+      handleUserError(req,res,res.getWriter(), "User error" + e.toString());
     }
 
     // timing...
@@ -207,14 +208,16 @@ public class Mir extends AbstractServlet {
   }
 
 
-  private void handleError(HttpServletResponse res, PrintWriter out, String errorString) {
+  private void handleError(HttpServletRequest req, HttpServletResponse res,
+                                                                                                        PrintWriter out, String errorString) {
 
     try {
       theLog.printError(errorString);
       SimpleHash modelRoot = new SimpleHash();
       modelRoot.put("errorstring", new SimpleScalar(errorString));
       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),modelRoot,out);
+      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
+                                                                                                                                               modelRoot,out,req.getLocale());
       out.close();
     }
     catch (Exception e) {
@@ -222,14 +225,15 @@ public class Mir extends AbstractServlet {
     }
   }
 
-  private void handleUserError(HttpServletResponse res,PrintWriter out, String errorString) {
-
+  private void handleUserError(HttpServletRequest req, HttpServletResponse res,
+                                                                                                                        PrintWriter out, String errorString) {
     try {
       theLog.printError(errorString);
       SimpleHash modelRoot = new SimpleHash();
       modelRoot.put("errorstring", new SimpleScalar(errorString));
       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),modelRoot,out);
+      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
+                                                                                                                                               modelRoot,out, req.getLocale());
       out.close();
     }
     catch (Exception e) {
@@ -263,9 +267,10 @@ public class Mir extends AbstractServlet {
       }
       SimpleHash mergeData = new SimpleHash();
       mergeData.put("session",sessionUrl);
-      HTMLTemplateProcessor.process(res,lang+"/"+loginTemplate, mergeData, out);
+      HTMLTemplateProcessor.process(res, lang+"/"+loginTemplate, mergeData,
+                                                                                                                                               out, req.getLocale());
     } catch(HTMLParseException e) {
-      handleError(res, out, "Error in logintemplate.");
+      handleError(req, res, out, "Error in logintemplate.");
     }
   }
 
@@ -279,10 +284,11 @@ public class Mir extends AbstractServlet {
       mergeData.put("login_user", userEntity);
       if (messageModule == null) messageModule = new ModuleMessage(DatabaseMessages.getInstance());
       mergeData.put("messages", messageModule.getByWhereClause(null, "webdb_create desc",0,10));
-      HTMLTemplateProcessor.process(res,getLanguage(req,session)+"/"+startTemplate, mergeData,out);
+      HTMLTemplateProcessor.process(res, getLanguage(req,session)+"/"+startTemplate,
+                                                                                                                                               mergeData, out, req.getLocale());
     }
     catch(Exception e) {
-      handleError( res,out, "error while trying to send startpage. " + e.toString());
+      handleError(req, res, out, "error while trying to send startpage. " + e.toString());
     }
   }
 
index 96820b2..1b10a98 100755 (executable)
@@ -41,8 +41,6 @@ public class OpenMir extends AbstractServlet {
     long            startTime = (new java.util.Date()).getTime();
     long            sessionConnectTime=0;
 
-    
-    
     // get the configration
     if(getServletContext().getAttribute("mir.confed") == null) {
       getConfig(req);
@@ -58,25 +56,26 @@ public class OpenMir extends AbstractServlet {
       ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res);
     }
     catch (ServletModuleUserException e) {
-      handleUserError(res,res.getWriter(), e.getMsg());  
+      handleUserError(req,res,res.getWriter(), e.getMsg());
     }
     catch (ServletModuleException e){
       e.printStackTrace();
-      handleError(res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
+      handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.toString());
     }
     // timing...
     sessionConnectTime = new java.util.Date().getTime() - startTime;
     theLog.printInfo("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms");
   }
 
-  private void handleUserError(HttpServletResponse res,PrintWriter out, String errorString) {
-
+  private void handleUserError(HttpServletRequest req, HttpServletResponse res,
+                                                                                                                        PrintWriter out, String errorString) {
     try {
       theLog.printError(errorString);
       SimpleHash modelRoot = new SimpleHash();
       modelRoot.put("errorstring", new SimpleScalar(errorString));
       modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),modelRoot,out);
+      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.UserErrorTemplate"),
+                                                                                                                                               modelRoot, out, req.getLocale() );
       out.close();
     }
     catch (Exception e) {
@@ -85,14 +84,16 @@ public class OpenMir extends AbstractServlet {
 
   }
 
-  private void handleError(HttpServletResponse res,PrintWriter out, String errorString) {
+  private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) {
 
     try {
       theLog.printError(errorString);
       SimpleHash modelRoot = new SimpleHash();
       modelRoot.put("errorstring", new SimpleScalar(errorString));
-      modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar())));
-      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),modelRoot,out);
+      modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(
+                                                                                                                                                                                        new GregorianCalendar())));
+      HTMLTemplateProcessor.process(res,MirConfig.getProp("Mir.ErrorTemplate"),
+                                                                                                                                               modelRoot,out, req.getLocale());
       out.close();
     }
     catch (Exception e) {
index bfa7558..681f063 100755 (executable)
@@ -13,6 +13,7 @@ import  freemarker.template.*;
 import  mir.entity.*;
 import  mir.storage.*;
 import javax.servlet.http.*;
+import org.apache.struts.util.MessageResources;
 
 
 /**
@@ -30,9 +31,10 @@ public final class HTMLTemplateProcessor {
   private static String               videoHost;
   private static String               imageHost;
   private static String               openAction;
-  protected static String producerDocRoot = MirConfig.getProp("Producer.DocRoot");
-  protected static String producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
-
+  protected static String producerDocRoot =
+               MirConfig.getProp("Producer.DocRoot");
+  protected static String producerStorageRoot =
+               MirConfig.getProp("Producer.StorageRoot");
 
   //
   // init
@@ -104,9 +106,10 @@ public final class HTMLTemplateProcessor {
    * @param out
    * @exception HTMLParseException
    */
-  public static void process(HttpServletResponse res,String templateFilename, EntityList entList, PrintWriter out)
-      throws HTMLParseException {
-    process(res, templateFilename,  entList,  (String)null, (TemplateModelRoot)null,  out);
+  public static void process(HttpServletResponse res,String templateFilename,
+                                                                                                                EntityList entList, PrintWriter out, Locale locale)
+    throws HTMLParseException {
+    process(res, templateFilename, entList, (String)null, (TemplateModelRoot)null, out, locale);
   }
 
   /**
@@ -122,14 +125,16 @@ public final class HTMLTemplateProcessor {
    * @param out
    * @exception HTMLParseException
    */
-    public static void process(HttpServletResponse res,String templateFilename, EntityList entList, String additionalModelName,
-             TemplateModelRoot additionalModel, PrintWriter out)
+    public static void process(HttpServletResponse res,String templateFilename,
+                                                                                                                        EntityList entList, String additionalModelName,
+                               TemplateModelRoot additionalModel, PrintWriter out,
+                                                                                                                        Locale locale)
       throws HTMLParseException {
 
       SimpleHash modelRoot = new SimpleHash();
 
       if (entList == null) {
-         process(null,templateFilename, modelRoot, out);
+         process(null,templateFilename, modelRoot, out, locale);
       } else {
         try {
           modelRoot = makeSimpleHashWithEntitylistInfos(entList);
@@ -138,7 +143,7 @@ public final class HTMLTemplateProcessor {
           if (additionalModelName != null && additionalModel != null)
               modelRoot.put(additionalModelName, additionalModel);
 
-          process(res,templateFilename, modelRoot, out);
+          process(res,templateFilename, modelRoot, out, locale);
         } catch (StorageObjectException e) {
           throw new HTMLParseException(e.toString());
         }
@@ -155,9 +160,10 @@ public final class HTMLTemplateProcessor {
    * @param out
    * @exception HTMLParseException
    */
-    public static void process(HttpServletResponse res,String templateFilename, HashMap mergeData, PrintWriter out)
+    public static void process(HttpServletResponse res,String templateFilename,
+                                                                                                                        HashMap mergeData, PrintWriter out, Locale locale)
       throws HTMLParseException {
-      process(res,templateFilename, makeSimpleHash(mergeData), out);
+      process(res,templateFilename, makeSimpleHash(mergeData), out, locale);
     }
 
   /**
@@ -169,9 +175,10 @@ public final class HTMLTemplateProcessor {
    * @param out
    * @exception HTMLParseException
    */
-    public static void process(String templateFilename, PrintWriter out)
+    public static void process(String templateFilename, PrintWriter out,
+                                                                                                                        Locale locale)
       throws HTMLParseException {
-      process(null,templateFilename, (TemplateModelRoot)null, out);
+      process(null,templateFilename, (TemplateModelRoot)null, out, locale);
     }
 
 
@@ -185,7 +192,8 @@ public final class HTMLTemplateProcessor {
    * @param out
    * @exception HTMLParseException
    */
-    public static void process(HttpServletResponse res,String templateFilename, TemplateModelRoot tmr, PrintWriter out)
+    public static void process(HttpServletResponse res,String templateFilename,
+                                                                                                                        TemplateModelRoot tmr, PrintWriter out, Locale locale)
       throws HTMLParseException {
       if (out==null) throw new HTMLParseException("no outputstream");
       Template tmpl = getTemplateFor(templateFilename);
@@ -222,7 +230,10 @@ public final class HTMLTemplateProcessor {
                        SimpleHash outPutHash = new SimpleHash();
                        outPutHash.put("data",tmr);
       outPutHash.put("config", configHash);
-                       
+                               
+                       MessageResources messages = MessageResources.getMessageResources("admin");
+                       outPutHash.put("message", new MessageMethodModel(locale, messages) );
+                               
       tmpl.process(outPutHash,out);
     }
 
index 5a9322b..3abedd7 100755 (executable)
@@ -5,10 +5,10 @@ import freemarker.template.*;
 import org.apache.struts.util.*;
 
 /**
- * A FreeMarker <code>TemplateMethodModel</code> that provides access to a 
+ * A FreeMarker <code>TemplateMethodModel</code> that provides access to a
  * Struts <code>MessageResources</code>, for use in Interantionalized templates.
  *
- * TODO:  we probably want to be doing some memoizing or something with this class* 
+ * TODO:  we probably want to be doing some memoizing or something with this class*
  * @author Kellan <kellan@protest.net>
  *
  */
@@ -17,37 +17,37 @@ import org.apache.struts.util.*;
   /**
    * The perferred locale for this instance of MessageMethod.
    */
-   private Locale locale;
+       private Locale locale;
     
   /**
    * The MessageResources to query, a single instances shared for
    * the lifetime of servlet.
    */
-   private MessageResources messages;
+       private MessageResources messages;
    
    
-   /**
-    * Construct a MessageMethod that uses the JVM's default locale.
-    * 
-    * @param message The MessageResources object to query
-    */
-   public MessageMethodModel(MessageResources messages) {
-      this(null, messages);
-   }
-   
-  /**
-   * Construct a MessageMethod
-   * 
-   * @param locale a Locale object, persumably initialized 
-   *               from users Accept-Language header field
-   *
-   * @param message The MessageResources object to query
-   */
-   public MessageMethodModel(Locale locale, MessageResources messages) {
-      this.locale = locale;
-      this.messages = messages;
-   }
+       /**
+   * Construct a MessageMethod that uses the JVM's default locale.
+        *
+        * @param message The MessageResources object to query
+        */
+  public MessageMethodModel(MessageResources messages) {
+       this(null, messages);
+  }
    
+       /**
+        * Construct a MessageMethod
+        *
+        * @param locale a Locale object, persumably initialized
+        *               from users Accept-Language header field
+        *
+        * @param message The MessageResources object to query
+        */
+       public MessageMethodModel(Locale locale, MessageResources messages) {
+               this.locale = locale;
+               this.messages = messages;
+       }
+        
    
   /**
    * Takes the first argument as a resource key, then looks up
@@ -55,34 +55,34 @@ import org.apache.struts.util.*;
    * TODO: this is an alpha implementation.  We should then check if we have
    *       any keys left over, and attempt to apply MessageFormat.format.
    * TODO: error messages should be i18n :)
-   * 
-   * @param arguments List passed in by FM, first arguement is a string used as the key 
+   *
+   * @param arguments List passed in by FM, first arguement is a string used as the key
    */
-   public TemplateModel exec(List arguments) {
-      if ( arguments != null ) {
-        String key = (String)arguments.get(0);
-        String mesg = messages.getMessage(locale, key);
-        if ( mesg == null ) {
-           return unknownTagScalar;
-        }
-        return new SimpleScalar(mesg);
-      } else {
-        return missingKeyScalar;
-      }
-   }
-   
-   // i'm not real clear on how this is used - kellan :)
-   public boolean isEmpty() {
-      if (messages == null)
-       return true;
-      else
-       return false;
-   }
+  public TemplateModel exec(List arguments) {
+               if ( arguments != null ) {
+                       String key = (String)arguments.get(0);
+                       String mesg = messages.getMessage(locale, key);
+                       if ( mesg == null ) {
+                               return unknownTagScalar;
+                       }
+                       return new SimpleScalar(mesg);
+               } else {
+                       return missingKeyScalar;
+               }
+       }
+          
+       // i'm not real clear on how this is used - kellan :)
+       public boolean isEmpty() {
+       if (messages == null)
+                       return true;
+    else
+                       return false;
+  }
  
-   private static String errUnknownTag = "TAG NOT FOUND";
-   private static String missingKey = "MESSAGE CALL WITHOUT KEY";
-   private static SimpleScalar unknownTagScalar =
-     new SimpleScalar(errUnknownTag);
-   private static SimpleScalar missingKeyScalar =
-     new SimpleScalar(missingKey);
+       private static String errUnknownTag = "TAG NOT FOUND";
+       private static String missingKey = "MESSAGE CALL WITHOUT KEY";
+       private static SimpleScalar unknownTagScalar =
+               new SimpleScalar(errUnknownTag);
+       private static SimpleScalar missingKeyScalar =
+               new SimpleScalar(missingKey);
 }
index eab5dc5..2355920 100755 (executable)
@@ -88,7 +88,7 @@ public abstract class ServletModule {
       theList = mainModule.getByWhereClause(null, offset);
       //theList = mainModule.getByWhereClause((String)null, offset);
       if (theList == null || theList.getCount() == 0 || theList.getCount()>1){
-        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, theList, out);
+        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, theList, out,req.getLocale());
       } else {
         deliver(req, res, theList.elementAt(0), templateObjektString);
       }
@@ -268,7 +268,7 @@ public abstract class ServletModule {
     try {
       //PrintWriter out =  new LineFilterWriter(res.getWriter());
       PrintWriter out =  res.getWriter();
-      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out);
+      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out, req.getLocale());
       out.close();
     } catch (HTMLParseException e) {
       throw new ServletModuleException(e.toString());
@@ -293,7 +293,7 @@ public abstract class ServletModule {
     try {
       PrintWriter out =  new LineFilterWriter(res.getWriter());
       //PrintWriter out =  res.getWriter();
-      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out);
+      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out, req.getLocale());
       out.close();
     } catch (HTMLParseException e) {
       throw new ServletModuleException(e.toString());
@@ -315,7 +315,7 @@ public abstract class ServletModule {
    */
   private void deliver(HttpServletResponse res,HttpServletRequest req, PrintWriter out, TemplateModelRoot rtm, String templateFilename)
     throws HTMLParseException {
-    HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out);
+    HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateFilename, rtm , out, req.getLocale());
   }
 
   /**
index c875958..2d4d638 100755 (executable)
@@ -82,7 +82,7 @@ abstract public class Producer {
                                outStream = new PrintWriter(outputFile);
                        }
 
-                       HTMLTemplateProcessor.process(null,template, model, outStream);
+                       HTMLTemplateProcessor.process(null,template, model, outStream,null);
                        outputFile.close();
                        outStream.close();
 
index 03d4235..5478e20 100755 (executable)
@@ -117,7 +117,8 @@ public class ServletModuleComment extends ServletModule
                                        }
                                }
                                // raus damit
-                               HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
+                               HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString,
+                                                                                                                                                       mergeData, res.getWriter(), req.getLocale());
                        }
                        catch (ModuleException e) {throw new ServletModuleException(e.toString());}
                        catch (IOException e) {throw new ServletModuleException(e.toString());}
index 89df034..75cf200 100755 (executable)
@@ -284,7 +284,8 @@ public class ServletModuleImages extends mir.servlet.ServletModule
           }
         }
         // raus damit
-        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
+        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString,
+                                                                                                                                                       mergeData, res.getWriter(),req.getLocale());
       }
       catch (ModuleException e) {throw new ServletModuleException(e.toString());}
       catch (IOException e) {throw new ServletModuleException(e.toString());}
index 2a5b051..f100489 100755 (executable)
@@ -66,7 +66,8 @@ public class ServletModuleLinksImcs extends ServletModule
       modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
 
       if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount()>1){
-        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString, modelRoot, res.getWriter());
+        HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString,
+                                                                                                                                                       modelRoot, res.getWriter(), req.getLocale());
       } else {
         deliver(req, res, modelRoot, templateObjektString);
       }
@@ -151,7 +152,8 @@ public class ServletModuleLinksImcs extends ServletModule
                        if (theImcsList.hasPrevBatch())
                                modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
 
-      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, modelRoot, res.getWriter());
+      HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString,
+                                                                                                                                               modelRoot, res.getWriter(), req.getLocale());
 
       } catch (Exception e) {
       throw new ServletModuleException(e.toString());
index ec11703..65da2f1 100755 (executable)
@@ -68,7 +68,8 @@ public class ServletModuleMessage extends ServletModule
                                mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
 
                        // raus damit
-                       HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
+                       HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString,
+                                                                                                                                               mergeData, res.getWriter(), req.getLocale());
 
                }
                catch (ModuleException e) {throw new ServletModuleException(e.toString());}