Misc. changes
authorzapata <zapata>
Tue, 1 Oct 2002 04:15:57 +0000 (04:15 +0000)
committerzapata <zapata>
Tue, 1 Oct 2002 04:15:57 +0000 (04:15 +0000)
19 files changed:
source/config.properties-dist
source/mir/generator/FreemarkerGenerator.java
source/mir/generator/Generator.java
source/mir/generator/GeneratorLibraryRepository.java [new file with mode: 0755]
source/mir/util/GeneratorHTMLFunctions.java
source/mir/util/GeneratorRegularExpressionFunctions.java [new file with mode: 0755]
source/mir/util/GeneratorStringFunctions.java [new file with mode: 0755]
source/mir/util/HTMLRoutines.java [new file with mode: 0755]
source/mir/util/ParameterExpander.java
source/mir/util/SimpleParser.java [new file with mode: 0755]
source/mir/util/StringParseRoutines.java [new file with mode: 0755]
source/mir/util/StringRoutines.java
source/mircoders/localizer/MirGeneratorLocalizer.java
source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java
source/mircoders/localizer/basic/MirBasicLocalizer.java
source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java
source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
source/mircoders/localizer/basic/MirBasicProducerLocalizer.java
source/mircoders/servlet/ServletModuleComment.java

index 9568f46..8f6bdae 100755 (executable)
@@ -53,6 +53,11 @@ Mir.Localizer.Logfile=log/localizer.log
 # The location of the producer specifiations
 Mir.Localizer.ProducerConfigFile=templates/producer/producers.xml
 
+# the templates
+Mir.Localizer.Producer.GeneratorLibrary= default=freemarker(templates/producer/)
+Mir.Localizer.Admin.GeneratorLibrary= default=freemarker(templates/admin/)
+Mir.Localizer.OpenPosting.GeneratorLibrary= default=freemarker(templates/open/)
+
 # Which producers need to be called after an article (resp. a comment) is posted
 Mir.Localizer.OpenPosting.ContentProducers= media.new;content.new;startpage.new;synchronization.run
 Mir.Localizer.OpenPosting.CommentProducers= content.new;synchronization.run
index 11337f6..9979dda 100755 (executable)
@@ -291,10 +291,10 @@ public class FreemarkerGenerator implements Generator {
   }
 
   public static class FreemarkerGeneratorLibrary implements GeneratorLibrary {
-    private FileTemplateCache  templateCache;
+    private FileTemplateCache templateCache;
 
     public FreemarkerGeneratorLibrary(String aTemplateRoot) {
-      templateCache = new FileTemplateCache( aTemplateRoot + "/" );
+      templateCache = new FileTemplateCache( aTemplateRoot+"/" );
       templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND);
     }
 
@@ -308,4 +308,16 @@ public class FreemarkerGenerator implements Generator {
       return new FreemarkerGenerator(template);
     }
   }
+
+  public static class FreemarkerGeneratorLibraryFactory implements GeneratorLibraryFactory {
+    private String basePath;
+
+    public FreemarkerGeneratorLibraryFactory(String aBasePath) {
+      basePath = aBasePath;
+    }
+
+    public GeneratorLibrary makeLibrary(String anInitializationString) {
+      return new FreemarkerGeneratorLibrary(basePath+anInitializationString);
+    };
+  }
 }
index 87dce6a..09939e4 100755 (executable)
@@ -41,6 +41,10 @@ public interface Generator {
     public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure;
   }
 
+  public static interface GeneratorLibraryFactory {
+    public GeneratorLibrary makeLibrary(String anInitializationString);
+  }
+
   public static interface GeneratorFunction {
     public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure;
   }
diff --git a/source/mir/generator/GeneratorLibraryRepository.java b/source/mir/generator/GeneratorLibraryRepository.java
new file mode 100755 (executable)
index 0000000..046312c
--- /dev/null
@@ -0,0 +1,70 @@
+package mir.generator;
+
+import java.util.*;
+import mir.util.*;
+
+public class GeneratorLibraryRepository {
+  private Map factories;
+
+  public GeneratorLibraryRepository() {
+    factories = new HashMap();
+  }
+
+  public void registerLibraryFactory(String aName, Generator.GeneratorLibraryFactory aFactory) {
+    factories.put(aName, aFactory);
+  }
+
+  public Generator.GeneratorLibrary constructLibrary(String aName, String aParameters) throws GeneratorExc {
+    if (!factories.containsKey(aName))
+      throw new GeneratorExc("Unknown library factory: "+aName);
+
+    return ((Generator.GeneratorLibraryFactory) factories.get(aName)).makeLibrary(aParameters);
+  }
+
+  private final static String SPACE = "[\t\n\r ]*";
+  private final static String IDENTIFIER = "[a-zA-Z_][a-zA-Z0-9_]*";
+  private final static String EQUALS = "=";
+  private final static String LEFT_PARENTHESIS = "[(]";
+  private final static String RIGHT_PARENTHESIS = "[)]";
+  private final static String FACTORY_PARAMETERS = "[^)]*";
+  private final static String SEMICOLON = ";";
+
+  public Generator.GeneratorLibrary constructCompositeLibrary(String aSpecification) throws GeneratorExc, GeneratorFailure {
+    //main=freemarker(path=/var/www/test); test=freemarker(path=/var/www/test2)
+    String identifier;
+    String factory;
+    String factoryParameters;
+    CompositeGeneratorLibrary result = new CompositeGeneratorLibrary();
+    boolean first=true;
+
+    SimpleParser parser = new SimpleParser(aSpecification);
+    try {
+      parser.skip(SPACE);
+      while (!parser.isAtEnd()) {
+        identifier = parser.parse(IDENTIFIER, "library key expected");
+        parser.skip(SPACE);
+        parser.parse(EQUALS, "'=' expected");
+        parser.skip(SPACE);
+        factory = parser.parse(IDENTIFIER, "factory name expected");
+        parser.skip(SPACE);
+        parser.parse(LEFT_PARENTHESIS, "'(' expected");
+        factoryParameters = parser.parse(FACTORY_PARAMETERS, "parameters expected");
+        parser.parse(RIGHT_PARENTHESIS, "')' expected");
+
+        result.addLibrary(identifier, constructLibrary(factory, factoryParameters), first);
+        first=false;
+        parser.skip(SPACE);
+
+        if (!parser.isAtEnd()) {
+          parser.parse(SEMICOLON, "; expected");
+        }
+      }
+    }
+    catch (Exception e) {
+      e.printStackTrace(System.out);
+      throw new GeneratorFailure("Failed to construct generator library: " + e.getMessage(), e);
+    }
+
+    return result;
+  }
+}
\ No newline at end of file
index 4ec3afb..cd6364b 100755 (executable)
@@ -63,7 +63,7 @@ public class GeneratorHTMLFunctions {
         throw new GeneratorExc("encodeHTMLGeneratorFunction: parameter must be a string (not a "+aParameters.get(0).getClass().getName()+")");
 
 
-      return StringRoutines.encodeHTML((String) aParameters.get(0));
+      return HTMLRoutines.encodeHTML((String) aParameters.get(0));
     };
   }
 }
diff --git a/source/mir/util/GeneratorRegularExpressionFunctions.java b/source/mir/util/GeneratorRegularExpressionFunctions.java
new file mode 100755 (executable)
index 0000000..573b2e3
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.util;
+
+import java.util.*;
+import mir.generator.*;
+
+public class GeneratorRegularExpressionFunctions {
+
+  private GeneratorRegularExpressionFunctions() {}
+
+  public static class regularExpressionReplaceFunction implements Generator.GeneratorFunction {
+    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+      try {
+        if (aParameters.size()!=3)
+          throw new GeneratorExc("regularExpressionReplaceFunction: exactly 3 parameters expected: data, search expression, replacement");
+        if (aParameters.get(0)==null)
+          return "";
+        if (!(aParameters.get(0) instanceof String) || !(aParameters.get(1) instanceof String)  || !(aParameters.get(2) instanceof String))
+          throw new GeneratorExc("regularExpressionReplaceFunction: parameters must be strings");
+
+        return StringRoutines.performRegularExpressionReplacement((String) aParameters.get(0), (String) aParameters.get(1), (String) aParameters.get(2));
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure(t);
+      }
+    };
+  }
+}
\ No newline at end of file
diff --git a/source/mir/util/GeneratorStringFunctions.java b/source/mir/util/GeneratorStringFunctions.java
new file mode 100755 (executable)
index 0000000..9aed006
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.util;
+
+import java.util.*;
+import mir.generator.*;
+
+public class GeneratorStringFunctions {
+
+  private GeneratorStringFunctions() {}
+
+  public static int interpretAsInteger(Object aValue) throws GeneratorExc {
+    if (aValue instanceof Integer)
+      return ((Integer) aValue).intValue();
+
+    if (aValue instanceof String)
+      try {
+        return Integer.parseInt((String) aValue);
+      }
+      catch (Throwable t) {
+        throw new GeneratorExc("Integer expected, "+aValue+" found");
+      }
+
+    throw new GeneratorExc("Integer expected, "+aValue+" found");
+  }
+
+  public static String interpretAsString(Object aValue) throws GeneratorExc {
+    if (aValue instanceof String)
+      return (String) aValue;
+
+    if (aValue instanceof Integer)
+      return ((Integer) aValue).toString();
+
+    throw new GeneratorExc("String expected, "+aValue+" found");
+  }
+
+  public static class subStringFunction implements Generator.GeneratorFunction {
+    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+      try {
+        if (aParameters.size()>3 || aParameters.size()<2)
+          throw new GeneratorExc("subStringFunction: 2 or 3 parameters expected: string from [length]");
+
+        if (aParameters.get(0)==null)
+          return "";
+
+        if (aParameters.size()==3) {
+          return interpretAsString(aParameters.get(0)).substring(
+              interpretAsInteger(aParameters.get(1)),
+              interpretAsInteger(aParameters.get(2)));
+        }
+        else {
+          return interpretAsString(aParameters.get(0)).substring(
+              interpretAsInteger(aParameters.get(1)));
+        }
+      }
+      catch (GeneratorExc e) {
+        throw e;
+      }
+      catch (Throwable t) {
+        throw new GeneratorFailure(t);
+      }
+    };
+  }
+}
\ No newline at end of file
diff --git a/source/mir/util/HTMLRoutines.java b/source/mir/util/HTMLRoutines.java
new file mode 100755 (executable)
index 0000000..6e8dfaa
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.util;
+
+public class HTMLRoutines {
+  public static String encodeHTML(String aText) {
+    final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
+    final String[] ESCAPE_CODES = { "&amp;", "&lt;", "&gt;", "&quot;", "&apos;" };
+
+    int position, nextPosition;
+    int i;
+    StringBuffer result = new StringBuffer();
+
+    position=0;
+
+    do {
+      nextPosition = StringRoutines.indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position);
+
+      if (nextPosition<0)
+        nextPosition = aText.length();
+
+      result.append(aText.substring(position, nextPosition));
+
+      if (nextPosition<aText.length())
+        for (i=0; i<CHARACTERS_TO_ESCAPE.length; i++) {
+          if (CHARACTERS_TO_ESCAPE[i] == aText.charAt(nextPosition)) {
+            result.append(ESCAPE_CODES[i]);
+            break;
+          }
+        }
+      position=nextPosition+1;
+    }
+    while (nextPosition<aText.length()) ;
+
+    return result.toString();
+  }
+}
\ No newline at end of file
index 96c7151..5a752d2 100755 (executable)
@@ -41,22 +41,6 @@ public class ParameterExpander {
   final static String NODE_SEPARATOR = ".";
   final static char STRING_ESCAPE_CHARACTER = '\\';
 
-  public static List splitString(String aString, String aSeparator) {
-    List result= new Vector();
-    int previousPosition = 0;
-    int position;
-    int endOfNamePosition;
-
-    while ((position = aString.indexOf(aSeparator, previousPosition))>=0) {
-      result.add(aString.substring(previousPosition, position));
-      previousPosition = position + aSeparator.length();
-    }
-
-    result.add(aString.substring(previousPosition, aString.length()));
-
-    return result;
-  }
-
   private static Object findNode(String aKey, Map aMap, List aParts, boolean aMakeIfNotPresent) throws Exception {
     Iterator i;
     String location = "";
@@ -95,7 +79,7 @@ public class ParameterExpander {
 
   public static Object findValueForKey(Map aMap, String aKey) throws Exception {
     Object node;
-    List parts = splitString(aKey, NODE_SEPARATOR);
+    List parts = StringRoutines.splitString(aKey, NODE_SEPARATOR);
 
     node = findNode(aKey, aMap, parts, false);
 
@@ -112,7 +96,7 @@ public class ParameterExpander {
   }
 
   public static void setValueForKey(Map aMap, String aKey, Object aValue) throws Exception {
-    List parts = splitString(aKey, NODE_SEPARATOR);
+    List parts = StringRoutines.splitString(aKey, NODE_SEPARATOR);
 
     String key = (String) parts.get(parts.size()-1);
     parts.remove(parts.size()-1);
diff --git a/source/mir/util/SimpleParser.java b/source/mir/util/SimpleParser.java
new file mode 100755 (executable)
index 0000000..8c4a5cb
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.util;
+
+import java.util.*;
+import gnu.regexp.*;
+import multex.Exc;
+import multex.Failure;
+
+public class SimpleParser {
+  private String data;
+  private int position;
+
+  public SimpleParser(String aData) {
+    data=aData;
+    position=0;
+
+    System.out.println("Will parse: "+aData);
+  }
+
+  public boolean parses(RE aRegularExpression) throws SimpleParserExc {
+    REMatch match = aRegularExpression.getMatch(data, position);
+
+    return (match!=null && match.getStartIndex()==position) ;
+  }
+
+  public String parse(RE aRegularExpression, String aMessage) throws SimpleParserExc {
+    REMatch match = aRegularExpression.getMatch(data, position);
+
+    if (match==null || match.getStartIndex()!=position)
+      throw new SimpleParserExc(aMessage+" at position "+position+" in '"+data+"'");
+
+    position=match.getEndIndex();
+
+    return match.toString();
+  }
+
+  public String parse(RE aRegularExpression) throws SimpleParserExc {
+    return parse( aRegularExpression, "No match found for '"+aRegularExpression.toString()+"'");
+  }
+
+  public void skip(RE aRegularExpression) throws SimpleParserExc {
+    REMatch match = aRegularExpression.getMatch(data, position);
+
+    if (match!=null && match.getStartIndex()==position)
+      position=match.getEndIndex();
+  }
+
+  public boolean parses(String anExpression) throws SimpleParserExc {
+    try {
+      return parses(new RE(anExpression));
+    }
+    catch (SimpleParserExc e) {
+      throw e;
+    }
+    catch (REException e) {
+      throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
+    }
+    catch (Throwable t) {
+      throw new SimpleParserFailure( t );
+    }
+  }
+
+  public String parse(String anExpression) throws SimpleParserExc, SimpleParserFailure {
+    try {
+      return parse(new RE(anExpression));
+    }
+    catch (SimpleParserExc e) {
+      throw e;
+    }
+    catch (REException e) {
+      throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
+    }
+    catch (Throwable t) {
+      throw new SimpleParserFailure( t );
+    }
+  }
+
+  public String parse(String anExpression, String aMessage) throws SimpleParserExc, SimpleParserFailure {
+    try {
+      System.out.println("Expression: "+anExpression);
+
+      return parse(new RE(anExpression), aMessage);
+    }
+    catch (SimpleParserExc e) {
+      throw e;
+    }
+    catch (REException e) {
+      throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
+    }
+    catch (Throwable t) {
+      throw new SimpleParserFailure( t );
+    }
+  }
+
+  public void skip(String anExpression) throws SimpleParserExc, SimpleParserFailure {
+    try {
+      skip(new RE(anExpression));
+    }
+    catch (SimpleParserExc e) {
+      throw e;
+    }
+    catch (REException e) {
+      throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
+    }
+    catch (Throwable t) {
+      throw new SimpleParserFailure( t );
+    }
+  }
+  public boolean isAtEnd() {
+    return position>=data.length();
+  }
+
+  public static class SimpleParserFailure extends Failure {
+    public SimpleParserFailure(Throwable aThrowable) {
+      super(aThrowable.getMessage(), aThrowable);
+    }
+
+    public SimpleParserFailure(String aMessage, Throwable aThrowable) {
+      super(aMessage, aThrowable);
+    }
+  }
+
+  public static class SimpleParserExc extends Exc {
+    public SimpleParserExc(String aMessage) {
+      super(aMessage);
+    }
+  }
+}
\ No newline at end of file
diff --git a/source/mir/util/StringParseRoutines.java b/source/mir/util/StringParseRoutines.java
new file mode 100755 (executable)
index 0000000..acd56d6
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2001, 2002  The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two.  You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries.  If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so.  If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.util;
+
+import java.util.*;
+
+public class StringParseRoutines {
+
+  private final static String SPACE = "[\t\n\r ]*";
+  private final static String IDENTIFIER = "[a-zA-Z_][a-zA-Z0-9_]*";
+  private final static String EQUALS = "=";
+  private final static String VALUE = "[^;]*";
+  private final static String SEMICOLON = ";";
+
+  //  a=sdfb; c=d; e=f
+
+  public static Map parseValueList(String anExpression) throws SimpleParser.SimpleParserFailure, SimpleParser.SimpleParserExc {
+    String key;
+    String value;
+    Map result = new HashMap();
+    SimpleParser parser = new SimpleParser(anExpression);
+
+    parser.skip(SPACE);
+    while (!parser.isAtEnd()) {
+      key = parser.parse(IDENTIFIER, "key expected");
+      parser.skip(SPACE);
+      parser.parse(EQUALS, "'=' expected");
+      parser.skip(SPACE);
+      value = parser.parse(VALUE, "value expected");
+      parser.skip(SPACE);
+      result.put(key, value);
+      parser.skip(SPACE);
+
+      if (!parser.isAtEnd()) {
+        parser.parse(SEMICOLON, "; expected");
+      }
+    }
+
+    return result;
+  }
+}
\ No newline at end of file
index b670ae3..7907ac2 100755 (executable)
@@ -55,38 +55,6 @@ public class StringRoutines {
     return result;
   }
 
-  public static String encodeHTML(String aText) {
-    final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
-    final String[] ESCAPE_CODES = { "&amp;", "&lt;", "&gt;", "&quot;", "&apos;" };
-
-    int position, nextPosition;
-    int i;
-    StringBuffer result = new StringBuffer();
-
-    position=0;
-
-    do {
-      nextPosition = indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position);
-
-      if (nextPosition<0)
-        nextPosition = aText.length();
-
-      result.append(aText.substring(position, nextPosition));
-
-      if (nextPosition<aText.length())
-        for (i=0; i<CHARACTERS_TO_ESCAPE.length; i++) {
-          if (CHARACTERS_TO_ESCAPE[i] == aText.charAt(nextPosition)) {
-            result.append(ESCAPE_CODES[i]);
-            break;
-          }
-        }
-      position=nextPosition+1;
-    }
-    while (nextPosition<aText.length()) ;
-
-    return result.toString();
-  }
-
   public static String performRegularExpressionReplacement(String aSource,
       String aSearchExpression, String aReplacement) throws Exception {
 
@@ -106,42 +74,19 @@ public class StringRoutines {
     return regularExpression.isMatch(aSource);
   }
 
-/*
-  return StringUtil.createHTML(
-      StringUtil.deleteForbiddenTags(aText),
-      MirGlobal.getConfigProperty("Producer.ImageRoot"),
-      MirGlobal.getConfigProperty("Producer.MailLinkName"),
-      MirGlobal.getConfigProperty("Producer.ExtLinkName"),
-      MirGlobal.getConfigProperty("Producer.IntLinkName")
-  );
- public static String createHTML(String content){
-         content=convertNewline2Break(content);
-         content=convertNewline2P(content);
-         content=createMailLinks(content);
-         content=createURLLinks(content);
-         return content;
-
- public static String convertNewline2Break(String haystack) {
-         return re_newline2br.substituteAll(haystack,"$0<br />");
- }
-
- public static String convertNewline2P(String haystack) {
-                 return re_brbr2p.substituteAll(haystack,"\n</p><p>");
- }
-
- public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
-         return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/>&#160;<a href=\"mailto:$0\">$0</a>");
- }
-
- public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
-         if (title == null) {
-                 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
-         } else {
-                 title = removeHTMLTags(title);
-                 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
-         }
- }
-
- }
-*/
+  public static List splitString(String aString, String aSeparator) {
+    List result= new Vector();
+    int previousPosition = 0;
+    int position;
+    int endOfNamePosition;
+
+    while ((position = aString.indexOf(aSeparator, previousPosition))>=0) {
+      result.add(aString.substring(previousPosition, position));
+      previousPosition = position + aSeparator.length();
+    }
+
+    result.add(aString.substring(previousPosition, aString.length()));
+
+    return result;
+  }
 }
\ No newline at end of file
index 62e6908..b6a9290 100755 (executable)
@@ -34,6 +34,9 @@ package mircoders.localizer;
 import mir.generator.*;
 
 public interface MirGeneratorLocalizer {
-  public Generator.GeneratorLibrary makeGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure;
   public WriterEngine makeWriterEngine() throws MirLocalizerException, MirLocalizerFailure;
+
+  public Generator.GeneratorLibrary makeProducerGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure;
+  public Generator.GeneratorLibrary makeAdminGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure;
+  public Generator.GeneratorLibrary makeOpenPostingGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure;
 }
\ No newline at end of file
index 7501a4e..5ee08d9 100755 (executable)
@@ -39,14 +39,43 @@ import mircoders.global.*;
 
 public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer {
   protected static Logfile logger = Logfile.getInstance( MirGlobal.getConfigProperty("Home") + "/" + MirGlobal.getConfigProperty("Mir.Localizer.Logfile"));
-  private String templateRoot;
+  private GeneratorLibraryRepository repository;
 
-  public MirBasicGeneratorLocalizer (String aTemplateRoot) {
-    templateRoot = aTemplateRoot;
+  public MirBasicGeneratorLocalizer () {
+    repository = new GeneratorLibraryRepository();
+
+    buildRepository(repository);
+  }
+
+  protected void buildRepository(GeneratorLibraryRepository aRepository) {
+    aRepository.registerLibraryFactory("freemarker", new FreemarkerGenerator.FreemarkerGeneratorLibraryFactory( MirGlobal.getConfigProperty("Home") ) );
   }
 
-  public Generator.GeneratorLibrary makeGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure {
-    return new FreemarkerGenerator.FreemarkerGeneratorLibrary(templateRoot);
+  public Generator.GeneratorLibrary makeProducerGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure {
+    try {
+      return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.Producer.GeneratorLibrary"));
+    }
+    catch (Throwable t) {
+      throw new MirLocalizerFailure(t);
+    }
+  };
+
+  public Generator.GeneratorLibrary makeAdminGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure {
+    try {
+      return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.Admin.GeneratorLibrary"));
+    }
+    catch (Throwable t) {
+      throw new MirLocalizerFailure(t);
+    }
+  };
+
+  public Generator.GeneratorLibrary makeOpenPostingGeneratorLibrary() throws MirLocalizerException, MirLocalizerFailure {
+    try {
+      return repository.constructCompositeLibrary(MirGlobal.getConfigProperty("Mir.Localizer.OpenPosting.GeneratorLibrary"));
+    }
+    catch (Throwable t) {
+      throw new MirLocalizerFailure(t);
+    }
   };
 
   public WriterEngine makeWriterEngine() throws MirLocalizerException, MirLocalizerFailure {
index b4c29e1..94ecca0 100755 (executable)
@@ -43,7 +43,7 @@ public class MirBasicLocalizer implements MirLocalizer {
   }
 
   public MirGeneratorLocalizer generators() {
-    return new MirBasicGeneratorLocalizer(MirGlobal.getConfigProperty("Home")+MirGlobal.getConfigProperty("HTMLTemplateProcessor.Dir"));
+    return new MirBasicGeneratorLocalizer();
   }
 
   public MirOpenPostingLocalizer openPostings() {
index 223aaa0..e3060db 100755 (executable)
@@ -80,10 +80,10 @@ public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer {
     Iterator i;
     List result = new Vector();
 
-    i = ParameterExpander.splitString(aList, ";").iterator();
+    i = StringRoutines.splitString(aList, ";").iterator();
     while (i.hasNext()) {
       String taskExpression = (String) i.next();
-      List parts = ParameterExpander.splitString(taskExpression, ".");
+      List parts = StringRoutines.splitString(taskExpression, ".");
 
       if (parts.size()!=2)
         logger.printError("Invalid producer expression: '" + taskExpression + "'");
index 3f46373..d3b843a 100755 (executable)
@@ -73,6 +73,7 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
     utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
     utilityMap.put("encodeHTML", new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());
     utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());
+    utilityMap.put("subString", new GeneratorStringFunctions.subStringFunction());
 
     aValueSet.put("config", configMap);
     aValueSet.put("utility", utilityMap);
index ead78d6..19ad8b9 100755 (executable)
@@ -59,7 +59,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer {
     try {
       producerFactories = new HashMap();
       model = MirGlobal.localizer().dataModel().adapterModel();
-      generatorLibrary = MirGlobal.localizer().generators().makeGeneratorLibrary();
+      generatorLibrary = MirGlobal.localizer().generators().makeProducerGeneratorLibrary();
       writerEngine = MirGlobal.localizer().generators().makeWriterEngine();
     }
     catch (Throwable t) {
index 4593413..67d73e2 100755 (executable)
@@ -171,7 +171,7 @@ public class ServletModuleComment extends ServletModule
     MessageResources messages = MessageResources.getMessageResources("bundles.admin");
 
     try {
-      generator = MirGlobal.localizer().generators().makeGeneratorLibrary().makeGenerator("admin/commentlist2.template");
+      generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator("admin/commentlist2.template");
       model = MirGlobal.localizer().dataModel().adapterModel();
 
 //    commentList = mainModule.getByWhereClause(whereClause, order, offset);