From 781ae5e450f0fdc85d3ee5b4b586aa542611a562 Mon Sep 17 00:00:00 2001
From: zapata
Date: Tue, 1 Oct 2002 04:15:57 +0000
Subject: [PATCH] Misc. changes
---
source/config.properties-dist | 5 +
source/mir/generator/FreemarkerGenerator.java | 16 ++-
source/mir/generator/Generator.java | 4 +
.../mir/generator/GeneratorLibraryRepository.java | 70 +++++++++
source/mir/util/GeneratorHTMLFunctions.java | 2 +-
.../util/GeneratorRegularExpressionFunctions.java | 58 ++++++++
source/mir/util/GeneratorStringFunctions.java | 93 ++++++++++++
source/mir/util/HTMLRoutines.java | 66 +++++++++
source/mir/util/ParameterExpander.java | 20 +--
source/mir/util/SimpleParser.java | 158 +++++++++++++++++++++
source/mir/util/StringParseRoutines.java | 70 +++++++++
source/mir/util/StringRoutines.java | 85 ++---------
.../mircoders/localizer/MirGeneratorLocalizer.java | 5 +-
.../basic/MirBasicGeneratorLocalizer.java | 39 ++++-
.../localizer/basic/MirBasicLocalizer.java | 2 +-
.../basic/MirBasicOpenPostingLocalizer.java | 4 +-
.../basic/MirBasicProducerAssistantLocalizer.java | 1 +
.../localizer/basic/MirBasicProducerLocalizer.java | 2 +-
source/mircoders/servlet/ServletModuleComment.java | 2 +-
19 files changed, 600 insertions(+), 102 deletions(-)
create mode 100755 source/mir/generator/GeneratorLibraryRepository.java
create mode 100755 source/mir/util/GeneratorRegularExpressionFunctions.java
create mode 100755 source/mir/util/GeneratorStringFunctions.java
create mode 100755 source/mir/util/HTMLRoutines.java
create mode 100755 source/mir/util/SimpleParser.java
create mode 100755 source/mir/util/StringParseRoutines.java
diff --git a/source/config.properties-dist b/source/config.properties-dist
index 9568f469..8f6bdaef 100755
--- a/source/config.properties-dist
+++ b/source/config.properties-dist
@@ -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
diff --git a/source/mir/generator/FreemarkerGenerator.java b/source/mir/generator/FreemarkerGenerator.java
index 11337f64..9979dda9 100755
--- a/source/mir/generator/FreemarkerGenerator.java
+++ b/source/mir/generator/FreemarkerGenerator.java
@@ -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);
+ };
+ }
}
diff --git a/source/mir/generator/Generator.java b/source/mir/generator/Generator.java
index 87dce6a8..09939e40 100755
--- a/source/mir/generator/Generator.java
+++ b/source/mir/generator/Generator.java
@@ -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
index 00000000..046312cc
--- /dev/null
+++ b/source/mir/generator/GeneratorLibraryRepository.java
@@ -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
diff --git a/source/mir/util/GeneratorHTMLFunctions.java b/source/mir/util/GeneratorHTMLFunctions.java
index 4ec3afbb..cd6364bb 100755
--- a/source/mir/util/GeneratorHTMLFunctions.java
+++ b/source/mir/util/GeneratorHTMLFunctions.java
@@ -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
index 00000000..573b2e38
--- /dev/null
+++ b/source/mir/util/GeneratorRegularExpressionFunctions.java
@@ -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
index 00000000..9aed0062
--- /dev/null
+++ b/source/mir/util/GeneratorStringFunctions.java
@@ -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
index 00000000..6e8dfaa6
--- /dev/null
+++ b/source/mir/util/HTMLRoutines.java
@@ -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 = { "&", "<", ">", """, "'" };
+
+ 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=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
index 00000000..8c4a5cb7
--- /dev/null
+++ b/source/mir/util/SimpleParser.java
@@ -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
index 00000000..acd56d6a
--- /dev/null
+++ b/source/mir/util/StringParseRoutines.java
@@ -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
diff --git a/source/mir/util/StringRoutines.java b/source/mir/util/StringRoutines.java
index b670ae3a..7907ac24 100755
--- a/source/mir/util/StringRoutines.java
+++ b/source/mir/util/StringRoutines.java
@@ -55,38 +55,6 @@ public class StringRoutines {
return result;
}
- public static String encodeHTML(String aText) {
- final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
- final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" };
-
- 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");
- }
-
- public static String convertNewline2P(String haystack) {
- return re_brbr2p.substituteAll(haystack,"\n
");
- }
-
- public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
- return re_mail.substituteAll(haystack," $0");
- }
-
- public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
- if (title == null) {
- return re_url.substituteAll(haystack," $0");
- } else {
- title = removeHTMLTags(title);
- return re_url.substituteAll(haystack," "+title+"");
- }
- }
-
- }
-*/
+ 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
diff --git a/source/mircoders/localizer/MirGeneratorLocalizer.java b/source/mircoders/localizer/MirGeneratorLocalizer.java
index 62e69080..b6a92900 100755
--- a/source/mircoders/localizer/MirGeneratorLocalizer.java
+++ b/source/mircoders/localizer/MirGeneratorLocalizer.java
@@ -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
diff --git a/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java b/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java
index 7501a4e2..5ee08d96 100755
--- a/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java
+++ b/source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java
@@ -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 {
diff --git a/source/mircoders/localizer/basic/MirBasicLocalizer.java b/source/mircoders/localizer/basic/MirBasicLocalizer.java
index b4c29e1b..94ecca0b 100755
--- a/source/mircoders/localizer/basic/MirBasicLocalizer.java
+++ b/source/mircoders/localizer/basic/MirBasicLocalizer.java
@@ -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() {
diff --git a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java
index 223aaa00..e3060db4 100755
--- a/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java
+++ b/source/mircoders/localizer/basic/MirBasicOpenPostingLocalizer.java
@@ -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 + "'");
diff --git a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
index 3f463731..d3b843ac 100755
--- a/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
+++ b/source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
@@ -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);
diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java
index ead78d6b..19ad8b91 100755
--- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java
+++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java
@@ -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) {
diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java
index 45934135..67d73e24 100755
--- a/source/mircoders/servlet/ServletModuleComment.java
+++ b/source/mircoders/servlet/ServletModuleComment.java
@@ -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);
--
2.11.0