interceptor concept introduced: entity adapter fields referenced in a
authorzapata <zapata>
Sat, 24 Dec 2005 21:47:17 +0000 (21:47 +0000)
committerzapata <zapata>
Sat, 24 Dec 2005 21:47:17 +0000 (21:47 +0000)
producer will now by default pass through the html filter.

19 files changed:
NEWS
source/default.properties
source/mir/entity/adapter/EntityAdapter.java
source/mir/generator/CompositeGeneratorLibrary.java
source/mir/generator/FreemarkerGenerator.java
source/mir/generator/Generator.java
source/mir/generator/TALGenerator.java
source/mir/generator/VelocityGenerator.java
source/mir/generator/tal/MirExpressionParser.java
source/mir/producer/GeneratingProducerNode.java
source/mir/producer/reader/DefaultProducerNodeBuilders.java
source/mircoders/localizer/MirProducerAssistantLocalizer.java
source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java
source/mircoders/localizer/basic/MirBasicEmailArticleHandler.java
source/mircoders/localizer/basic/MirBasicProducerAssistantLocalizer.java
source/mircoders/localizer/basic/MirBasicProducerLocalizer.java
source/mircoders/servlet/ServletHelper.java
source/mircoders/servlet/ServletModuleOpenIndy.java
source/mircoders/servlet/ServletModuleProducer.java

diff --git a/NEWS b/NEWS
index 8c4f5c3..cf1ead2 100755 (executable)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-[last changed: $Date: 2003/12/03 15:41:11 $]  2002 mir-coders group
+[last changed: $Date: 2005/12/24 21:47:17 $]  2002 mir-coders group
 -------------------------------------------------------------------------------
 
 ================================
   incrementally when they are produced, uses standard internationalized
   template scheme to display results of queries, which can be sorted by real
   publication date and include things like image thumbnails
-  
-[Bugfixes]
-* more image formats supported with JAI / Java Image I/O
 
 [Build process]
 
 [Maintenance]
 
-[Notes]
-Mir depends media operations depend on the correct installation of
-JAI / Java Image I/O in the JRE running tomcat.
-
 ===============================
 1.0.0 final released 2002/12/24
 ===============================
@@ -31,7 +24,7 @@ JAI / Java Image I/O in the JRE running tomcat.
 [Bugfixes]
 * minor: in source/mir/misc/HTMLTemplateProcessor.java, use Video.Host
   config option not the non-existant VideoHost option.
-  
+
 [Build process]
 
 [Maintenance]
@@ -44,18 +37,18 @@ JAI / Java Image I/O in the JRE running tomcat.
 =============================
 
 [New features/Improvements]
-* throw a RuntimeException in MirConfig.getProp(..) if the property is not 
+* throw a RuntimeException in MirConfig.getProp(..) if the property is not
   found. This should ease upgrading between versions when a new Config property
   is added.
 
 [Bugfixes]
 * Add a new method to escape characters that are special characters in SQL. It
-  does a better job than the old hack in StringUtil.quote(..) which replaced 
-  single quotes with the HTML representation of a single quote (&#39; 
+  does a better job than the old hack in StringUtil.quote(..) which replaced
+  single quotes with the HTML representation of a single quote (&#39;
   I believe). The hack papered over a bug in the postgres JDBC driver which
   makes it not recognize escaping w/ a backslash (it uses double single quotes
   instead).
-  
+
 [Build process]
 
 [Maintenance]
@@ -87,7 +80,7 @@ JAI / Java Image I/O in the JRE running tomcat.
   posting.template that prevented the chossing of a topic in openposting from
   working. luckily this bug didn't affect most sites since most installations
   customize the template.
-  
+
 
 [Build process]
 
@@ -105,8 +98,8 @@ JAI / Java Image I/O in the JRE running tomcat.
 * set a "Cache-control", "Pragma" and "Expires" header to the http response
   in the Mir and OpenMir servlets to insure that nothing gets cached by a
   client browser.
-* Add a new config parameter: Mir.DefaultHTMLCharset to set the HTML 
-  content-type charset in one place and re-use it in templates as 
+* Add a new config parameter: Mir.DefaultHTMLCharset to set the HTML
+  content-type charset in one place and re-use it in templates as
   ${config.defEncoding}.
 * Allow some HTML tags in the abstract (description field) during an
   openposting. strip out the dangerous ones like <head>, <body> and <script> as
@@ -126,7 +119,7 @@ JAI / Java Image I/O in the JRE running tomcat.
 * Fix embarrassing bug in the admin interface that caused data to dissappear
   when double quotes were in a title form field for example.. (anything
   enclosed in a value="...")
-* fix a bug in comment search: if you were at an offset > 0, i.e not on the 
+* fix a bug in comment search: if you were at an offset > 0, i.e not on the
   first page, the search would be broken.
 * fix minor bug in media searching: mediafolder search setting would be reset
   each time. make sure it is not so.
@@ -137,7 +130,7 @@ JAI / Java Image I/O in the JRE running tomcat.
 [Maintenance]
 * comment out a bunch of debug logging in Database.java
 * add this file, REPORTING_BUGS, KNOWN_BUGS, CODINGSTYLE and a README file.
-* Add gnu Style ChangeLog using cvs2cl (use "-F MIR_1_0 --utc" options., for 
+* Add gnu Style ChangeLog using cvs2cl (use "-F MIR_1_0 --utc" options., for
   HEAD, it would be "-F trunk --utc")
 
 [Notes]
@@ -253,7 +246,7 @@ From approx. March 2001 (beginning of indymedia.de) to 1.0.0-rc1, Dec 2002
 [Bugfixes]
 * Better and more consistent exception handling: make sure all exceptions make
   it to the top.
-* make sure that if some part of a posting fails that the posting however 
+* make sure that if some part of a posting fails that the posting however
   complete/inconplete it may be is deleted
 * many bugfixes all over the place
 
index cc015f1..9db014a 100755 (executable)
@@ -81,6 +81,9 @@ Mir.Localizer.Producer.GeneratorLibrary= default=freemarker(etc/producer/)
 Mir.Localizer.Admin.GeneratorLibrary= default=freemarker(templates/admin/),preview=freemarker(etc/producer)
 Mir.Localizer.OpenPosting.GeneratorLibrary= default=freemarker(etc/open/)
 
+# Should an XSS preventing interceptor be used by the producer subsystem?
+Mir.Producer.UseInterceptor=1
+
 # How should the custom operations (hide etc) in article and comment lists
 # be presented?
 # 0 = links, 1 = checkboxes, 2 = a listbox
index 8e5921c..bbb2319 100755 (executable)
@@ -83,14 +83,14 @@ public class EntityAdapter {
     if (calculatedFieldsCache.containsKey(aKey)) {
       return calculatedFieldsCache.get(aKey);
     }
-    else if (aKey instanceof String && definition.hasCalculatedField((String) aKey)) {
-      result = definition.getCalculatedField((String) aKey).getValue(this);
+    else if (definition.hasCalculatedField(aKey)) {
+      result = definition.getCalculatedField(aKey).getValue(this);
       calculatedFieldsCache.put(aKey, result);
 
       return result;
     }
     else {
-      return entity.getFieldValue((String) aKey);
+      return entity.getFieldValue(aKey);
     }
   }
 
index a9e9a70..dc7c267 100755 (executable)
@@ -46,7 +46,7 @@ public class CompositeGeneratorLibrary implements Generator.Library {
     generatorLibraries.put(aQualifier, aLibrary);
   }
 
-  public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
+  public Generator makeGenerator(String anIdentifier, Generator.Interceptor anInterceptor) throws GeneratorExc, GeneratorFailure {
     String qualifier;
     String libraryName;
     int position;
@@ -61,10 +61,10 @@ public class CompositeGeneratorLibrary implements Generator.Library {
       if (library==null)
         throw new GeneratorExc("CompositeGeneratorLibrary: library '"+libraryName+"' not found");
 
-      return library.makeGenerator(qualifier);
+      return library.makeGenerator(qualifier, anInterceptor);
     }
                if (defaultLibrary!=null)
-                 return defaultLibrary.makeGenerator(anIdentifier);
+                 return defaultLibrary.makeGenerator(anIdentifier, anInterceptor);
                throw new GeneratorExc("CompositeGeneratorLibrary: no default library speficied");
   }
 }
\ No newline at end of file
index 378ef1d..75d36fa 100755 (executable)
@@ -57,9 +57,11 @@ import freemarker.template.TemplateScalarModel;
 
 public class FreemarkerGenerator implements Generator {
   private Template template;
+  private Interceptor interceptor;
 
-  public FreemarkerGenerator(Template aTemplate) {
+  public FreemarkerGenerator(Template aTemplate, Interceptor anInterceptor) {
     template = aTemplate;
+    interceptor = anInterceptor;
   }
 
   public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure {
@@ -81,68 +83,72 @@ public class FreemarkerGenerator implements Generator {
     return new SimpleScalar(aString);
   }
 
-  private static TemplateHashModel makeMapAdapter(Map aMap)  {
+  private TemplateHashModel makeMapAdapter(Map aMap)  {
     return new MapAdapter(aMap);
   }
 
-  private static TemplateListModel makeIteratorAdapter(Iterator anIterator) {
+  private TemplateListModel makeIteratorAdapter(Iterator anIterator) {
     return new IteratorAdapter(anIterator);
   }
 
-  private static TemplateMethodModel makeFunctionAdapter(Generator.Function aFunction) {
+  private TemplateMethodModel makeFunctionAdapter(Generator.Function aFunction) {
     return new FunctionAdapter(aFunction);
   }
 
-  private static TemplateHashModel makeBeanAdapter(Object anObject)  {
+  private TemplateHashModel makeBeanAdapter(Object anObject)  {
     return new BeanAdapter(anObject);
   }
 
-  public static TemplateModel makeAdapter(Object anObject) throws TemplateModelException {
-    if (anObject == null) {
-      return null;
+  public TemplateModel makeAdapter(Object anObject) throws TemplateModelException {
+    Object object = anObject;
+    if (interceptor != null) {
+      object = interceptor.intercept(object);
     }
 
-    if (anObject instanceof TemplateModel) {
-      return (TemplateModel) anObject;
+    if (object == null) {
+      return null;
     }
-    else if (anObject instanceof Generator.Function) {
-      return makeFunctionAdapter((Generator.Function) anObject);
+    if (object instanceof TemplateModel) {
+      return (TemplateModel) object;
     }
-    else if (anObject instanceof Integer) {
-      return makeStringAdapter(anObject.toString());
+    else if (object instanceof Generator.Function) {
+      return makeFunctionAdapter((Generator.Function) object);
     }
-    else if (anObject instanceof Boolean) {
-      if (((Boolean) anObject).booleanValue()) {
+    else if (object instanceof Integer) {
+      return makeStringAdapter(object.toString());
+    }
+    else if (object instanceof Boolean) {
+      if (((Boolean) object).booleanValue()) {
         return makeStringAdapter("1");
       }
       else {
         return makeStringAdapter("0");
       }
     }
-    else if (anObject instanceof String) {
-      return makeStringAdapter((String) anObject);
+    else if (object instanceof String) {
+      return makeStringAdapter((String) object);
     }
-    else if (anObject instanceof Map) {
-      return makeMapAdapter((Map) anObject);
+    else if (object instanceof Map) {
+      return makeMapAdapter((Map) object);
     }
-    else if (anObject instanceof Iterator) {
-      return makeIteratorAdapter((Iterator) anObject);
+    else if (object instanceof Iterator) {
+      return makeIteratorAdapter((Iterator) object);
     }
-    else if (anObject instanceof Collection) {
-      return makeIteratorAdapter(((Collection) anObject).iterator());
+    else if (object instanceof Collection) {
+      return makeIteratorAdapter(((Collection) object).iterator());
     }
-    else if (anObject instanceof Number) {
-      return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) anObject));
+    else if (object instanceof Number) {
+      return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) object));
     }
-    else if (anObject instanceof Date) {
-      return makeAdapter(new GeneratorFormatAdapters.DateFormatAdapter((Date) anObject));
+    else if (object instanceof Date) {
+      return makeAdapter(new GeneratorFormatAdapters.DateFormatAdapter((Date) object));
     }
     else {
-      return makeBeanAdapter(anObject);
+      return makeBeanAdapter(object);
     }
   }
 
-  private static class MapAdapter implements TemplateModelRoot {
+  private class MapAdapter implements TemplateModelRoot {
     private Map map;
     private Map valuesCache;
 
@@ -185,7 +191,7 @@ public class FreemarkerGenerator implements Generator {
     }
   }
 
-  private static class IteratorAdapter implements TemplateListModel {
+  private class IteratorAdapter implements TemplateListModel {
     private Iterator iterator;
     private List valuesCache;
     private int position;
@@ -248,7 +254,7 @@ public class FreemarkerGenerator implements Generator {
     }
   }
 
-  private static class FunctionAdapter implements TemplateMethodModel {
+  private class FunctionAdapter implements TemplateMethodModel {
     private Generator.Function function;
 
     FunctionAdapter(Generator.Function aFunction) {
@@ -270,7 +276,7 @@ public class FreemarkerGenerator implements Generator {
 
   }
 
-  private static class BeanAdapter implements TemplateHashModel {
+  private class BeanAdapter implements TemplateHashModel {
     private Object object;
 
     public BeanAdapter(Object anObject) {
@@ -310,7 +316,7 @@ public class FreemarkerGenerator implements Generator {
       templateCache.setLoadingPolicy(FileTemplateCache.LOAD_ON_DEMAND);
     }
 
-    public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
+    public Generator makeGenerator(String anIdentifier, Interceptor anInterceptor) throws GeneratorExc, GeneratorFailure {
       Template template = (Template) templateCache.getItem(anIdentifier, "template");
 
       if (template==null) {
@@ -318,8 +324,9 @@ public class FreemarkerGenerator implements Generator {
             templateCache.getDirectory() + File.separatorChar + anIdentifier);
       }
 
-      return new FreemarkerGenerator(template);
+      return new FreemarkerGenerator(template, anInterceptor);
     }
+
   }
 
   public static class FreemarkerGeneratorLibraryFactory implements LibraryFactory {
index 9387dde..f225bd7 100755 (executable)
  */
 package mir.generator;
 
-import java.io.PrintWriter;
-import java.io.Reader;
+import mir.log.LoggerWrapper;
+
 import java.util.List;
 import java.util.Map;
 
-import mir.log.LoggerWrapper;
-
 /**
  * A "generator" is an abstraction for a template
  * If you need a generator, use MirGeneratorLocalizer  
@@ -43,24 +41,23 @@ public interface Generator {
    * MirGeneratorLocalizer to create a writer.
    * @param aValues the key/value pairs which the template engine will use as variables 
    */
-  public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure;
+  void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure;
 
-  
-  public static interface Library {
-    public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure;
+  interface Library {
+    Generator makeGenerator(String anIdentifier, Interceptor anInterceptor) throws GeneratorExc, GeneratorFailure;
   }
 
-  public static interface LibraryFactory {
-    public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure ;
+  interface LibraryFactory {
+    Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure ;
   }
 
-  /** interface for a generator implementation independent function */
-  public static interface Function {
-    /** performs the function with the given parameters */
-    public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure;
+  interface Interceptor {
+    Object intercept(Object anObject);
   }
 
-  public static interface Transformer {
-    public void perform(Reader aSource, PrintWriter anOutput) throws GeneratorExc, GeneratorFailure;
+  /** interface for a generator implementation independent function */
+  interface Function {
+    /** performs the function with the given parameters */
+    Object perform(List aParameters) throws GeneratorExc, GeneratorFailure;
   }
 }
index 2dc91af..12bb488 100755 (executable)
@@ -39,10 +39,12 @@ import mir.log.LoggerWrapper;
 public class TALGenerator implements Generator {
   private String templateIdentifier;
   private TALGeneratorLibrary library;
+  private Interceptor interceptor;
 
-  public TALGenerator(String aTemplate, TALGeneratorLibrary aLibrary) {
+  public TALGenerator(String aTemplate, TALGeneratorLibrary aLibrary, Interceptor anInterceptor) {
     templateIdentifier = aTemplate;
     library = aLibrary;
+    interceptor = anInterceptor;
   }
 
   public void generate(Object anOutputWriter, Map aValues, final LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure {
@@ -93,8 +95,8 @@ public class TALGenerator implements Generator {
       engine = new TALTemplateEngine(new MirExpressionParser(), aTemplateRoot);
     }
 
-    public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
-      return new TALGenerator(anIdentifier, this);
+    public Generator makeGenerator(String anIdentifier, Interceptor anInterceptor) throws GeneratorExc, GeneratorFailure {
+      return new TALGenerator(anIdentifier, this, anInterceptor);
     }
   }
 
index b49f49f..e6c78ac 100755 (executable)
@@ -55,6 +55,7 @@ public class VelocityGenerator implements Generator {
   private String templateIdentifier;
   private VelocityGeneratorLibrary library;
   private static LoggerWrapper logger = new LoggerWrapper("Generator.velocity");
+  private Interceptor interceptor;
 
   /**
    *
@@ -62,9 +63,10 @@ public class VelocityGenerator implements Generator {
    * @param aLibrary
    */
 
-  public VelocityGenerator(String aTemplate, VelocityGeneratorLibrary aLibrary) {
+  public VelocityGenerator(String aTemplate, VelocityGeneratorLibrary aLibrary, Interceptor anInterceptor) {
     templateIdentifier = aTemplate;
     library = aLibrary;
+    interceptor = anInterceptor;
   }
 
   /**
@@ -560,8 +562,8 @@ public class VelocityGenerator implements Generator {
       }
     }
 
-    public Generator makeGenerator(String anIdentifier) throws GeneratorExc, GeneratorFailure {
-      return new VelocityGenerator(anIdentifier, this);
+    public Generator makeGenerator(String anIdentifier, Interceptor anInterceptor) throws GeneratorExc, GeneratorFailure {
+      return new VelocityGenerator(anIdentifier, this, anInterceptor);
     }
   }
 
index 89184cb..0f328be 100755 (executable)
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 
 import mir.generator.tal.interfaces.TALExpressionParser;
+import mir.generator.Generator;
 import mir.util.ParameterExpander;
 import mir.util.RewindableIterator;
 
index 82d5f9a..bab2deb 100755 (executable)
@@ -43,17 +43,19 @@ public class GeneratingProducerNode extends AbstractProducerNode {
   private String parametersExpression;
   private Generator.Library generatorLibrary;
   private WriterEngine writerEngine;
+  private Generator.Interceptor interceptor;
 
-  public GeneratingProducerNode(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine, String aGenerator, String aDestination, String aParameters) {
+  public GeneratingProducerNode(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine, Generator.Interceptor anInterceptor, String aGenerator, String aDestination, String aParameters) {
     generatorExpression=aGenerator;
     destinationExpression=aDestination;
     parametersExpression=aParameters;
     generatorLibrary = aGeneratorLibrary;
     writerEngine = aWriterEngine;
+    interceptor = anInterceptor;
   }
 
-  public GeneratingProducerNode(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine, String aGenerator, String aDestination) {
-    this(aGeneratorLibrary, aWriterEngine, aGenerator, aDestination, "");
+  public GeneratingProducerNode(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine, Generator.Interceptor anInterceptor, String aGenerator, String aDestination) {
+    this(aGeneratorLibrary, aWriterEngine, anInterceptor, aGenerator, aDestination, "");
   }
 
   public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
@@ -87,7 +89,7 @@ public class GeneratingProducerNode extends AbstractProducerNode {
         mirMap.put("parameters", parameters);
 
         writer = writerEngine.openWriter(destinationIdentifier, parameters);
-        generator = generatorLibrary.makeGenerator(generatorIdentifier);
+        generator = generatorLibrary.makeGenerator(generatorIdentifier, interceptor);
         generator.generate(writer, aValueMap, aLogger);
         writerEngine.closeWriter(writer);
 
index 86429c3..aaaf59a 100755 (executable)
@@ -72,6 +72,7 @@ public class DefaultProducerNodeBuilders {
 
   public static void registerBuilders(ProducerNodeBuilderLibrary aBuilderLibrary,
        EntityAdapterModel aModel, Generator.Library aGeneratorLibrary,
+       Generator.Interceptor anInterceptor,
        WriterEngine aWriterEngine, File aSourceBasePath, File aDestinationBasePath) throws ProducerConfigExc {
 
     aBuilderLibrary.registerBuilder("Set", EvaluatedAssignmentProducerNodeBuilder.class);
@@ -101,7 +102,8 @@ public class DefaultProducerNodeBuilders {
     aBuilderLibrary.registerFactory("CreateEntity", new CreateEntityProducerNodeBuilder.factory(aModel));
     aBuilderLibrary.registerFactory("DeleteEntity", new DeleteEntityProducerNodeBuilder.factory(aModel));
 
-    aBuilderLibrary.registerFactory("Generate", new GeneratingProducerNodeBuilder.factory(aGeneratorLibrary, aWriterEngine));
+    aBuilderLibrary.registerFactory("Generate", new GeneratingProducerNodeBuilder.factory(aGeneratorLibrary,
+        aWriterEngine, anInterceptor));
   }
 
   public static abstract class AbstractProducerNodeBuilder implements ProducerNodeBuilder {
@@ -837,12 +839,15 @@ public class DefaultProducerNodeBuilders {
     private String parameters;
     private Generator.Library generatorLibrary;
     private WriterEngine writerEngine;
+    private Generator.Interceptor interceptor;
 
-    public GeneratingProducerNodeBuilder(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine) {
+    public GeneratingProducerNodeBuilder(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine,
+                                         Generator.Interceptor anInterceptor) {
       super(GENERATION_SUBNODES);
 
       writerEngine = aWriterEngine;
       generatorLibrary = aGeneratorLibrary;
+      interceptor = anInterceptor;
     }
 
     public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc {
@@ -854,20 +859,22 @@ public class DefaultProducerNodeBuilders {
     }
 
     public ProducerNode constructNode() {
-      return new GeneratingProducerNode(generatorLibrary, writerEngine, generator, destination, parameters);
+      return new GeneratingProducerNode(generatorLibrary, writerEngine, interceptor, generator, destination, parameters);
     }
 
     public static class factory implements ProducerNodeBuilderFactory {
       private Generator.Library generatorLibrary;
       private WriterEngine writerEngine;
+      private Generator.Interceptor interceptor;
 
-      public factory(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine) {
+      public factory(Generator.Library aGeneratorLibrary, WriterEngine aWriterEngine, Generator.Interceptor anInterceptor) {
         writerEngine = aWriterEngine;
         generatorLibrary = aGeneratorLibrary;
+        interceptor = anInterceptor;
       }
 
       public ProducerNodeBuilder makeBuilder() {
-        return new GeneratingProducerNodeBuilder(generatorLibrary, writerEngine);
+        return new GeneratingProducerNodeBuilder(generatorLibrary, writerEngine, interceptor);
       }
     }
   }
index 8e11e75..af0aefa 100755 (executable)
  */
 package mircoders.localizer;
 
+import mir.generator.Generator;
+
 import java.util.Map;
 
 public interface MirProducerAssistantLocalizer {
   public void initializeGenerationValueSet(Map aValueSet) throws MirLocalizerExc, MirLocalizerFailure;
   public String filterHTMLText(String aText) throws MirLocalizerExc, MirLocalizerFailure;
   public String filterNonHTMLText(String aText) throws MirLocalizerExc, MirLocalizerFailure;
+  public Generator.Interceptor createGenerationInterceptor() throws MirLocalizerExc, MirLocalizerFailure; 
 }
index d90f62e..ef75632 100755 (executable)
@@ -150,7 +150,8 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz
 
     if (previewPages.containsKey(aPreviewPage)) {
       try {
-        return MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator((String) previewPages.get(aPreviewPage));
+        return MirGlobal.localizer().generators().makeAdminGeneratorLibrary().
+            makeGenerator((String) previewPages.get(aPreviewPage), null);
       }
       catch (GeneratorExc e) {
         throw new MirLocalizerFailure(e);
index 0c96b79..5038b6a 100755 (executable)
@@ -199,7 +199,9 @@ public class MirBasicEmailArticleHandler implements SessionHandler {
 
        String emailAnArticleTemplate = configuration.getString("Localizer.OpenSession.email.MailTemplate");
 
-       Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(emailAnArticleTemplate);
+       Generator generator =
+      MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().
+          makeGenerator(emailAnArticleTemplate, null);
 
        StringWriter theEmailStringWriter = new StringWriter();
        PrintWriter theEmailPrintWriter = new PrintWriter(theEmailStringWriter);
index 84afe0d..6d31d17 100755 (executable)
@@ -164,8 +164,9 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
         Iterator i = new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "language");
         while (i.hasNext()) {
           EntityAdapter language = (EntityAdapter) i.next();
-          if (language.get("code").equals("ot"))
+          if (language.get("code").equals("ot")) {
             otherLanguageId = (String) language.get("id");
+          }
 
           languageCodeToId.put(language.get("code"), language.get("id"));
         }
@@ -208,8 +209,7 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
           MirGlobal.config().getString("Producer.ImageRoot"),
           MirGlobal.config().getString("Producer.MailLinkName"),
           MirGlobal.config().getString("Producer.ExtLinkName"),
-          MirGlobal.config().getString("Producer.IntLinkName")
-          );
+          MirGlobal.config().getString("Producer.IntLinkName"));
       logger.debug("done filtering non-HTML text ");
       return result;
     }
@@ -219,6 +219,60 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
       throw new RuntimeException(t.toString());
     }
   }
+
+  public Generator.Interceptor createGenerationInterceptor() throws MirLocalizerExc, MirLocalizerFailure {
+
+    if (MirGlobal.config().getBoolean("Mir.Producer.UseInterceptor", true)) {
+      return new Generator.Interceptor() {
+
+        public Object intercept(Object anObject) {
+          if (anObject instanceof EntityAdapter) {
+            return new InterceptedEntityAdapter((EntityAdapter) anObject);
+          }
+
+          return anObject;
+        }
+      };
+    }
+    else {
+      return null;
+    }
+  }
+
+  public class InterceptedEntityAdapter {
+    private EntityAdapter adapter;
+
+    InterceptedEntityAdapter(EntityAdapter anEntityAdapter) {
+      adapter = anEntityAdapter;
+    }
+
+    public Object get(String aField) {
+      Object result = adapter.get(aField);
+      if (result instanceof String) {
+        return filterHTMLText((String) result);
+      }
+      else {
+        return result;
+      }
+    }
+
+    public Object getRaw() {
+      return new RawEntityAdapter(adapter);
+    }
+  }
+
+  public class RawEntityAdapter {
+    private EntityAdapter adapter;
+
+    RawEntityAdapter(EntityAdapter anEntityAdapter) {
+      adapter = anEntityAdapter;
+    }
+
+    public Object get(String aField) {
+      return adapter.get(aField);
+    }
+  }
+
   public String filterHTMLText(String aText) {
     try {
       StringWriter out = new StringWriter();
@@ -228,7 +282,7 @@ public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantL
       tidy.setCharEncoding(Configuration.UTF8);
       tidy.setErrout(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
       print(tidy.parseDOM(in, null), out);
-      
+
       return out.toString();
     }
     catch (IOException e) {
index e04200f..16aee46 100755 (executable)
@@ -170,8 +170,11 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer {
   protected void setupProducerNodeBuilderLibrary(ProducerNodeBuilderLibrary aLibrary) throws MirLocalizerFailure {
     try {
       DefaultProducerNodeBuilders.registerBuilders(
-          aLibrary, model, generatorLibrary, writerEngine,
-          MirGlobal.config().getHome(), MirGlobal.config().getFile("Producer.StorageRoot"));
+          aLibrary, model, generatorLibrary, 
+          MirGlobal.localizer().producerAssistant().createGenerationInterceptor(),
+          writerEngine,
+          MirGlobal.config().getHome(),
+          MirGlobal.config().getFile("Producer.StorageRoot"));
       SupplementalProducerNodeBuilders.registerBuilders(aLibrary, MirGlobal.config().getHome());
     }
     catch (Throwable t) {
index 3869a3d..fd699a2 100755 (executable)
@@ -95,7 +95,7 @@ public class ServletHelper {
     logger.debug("generator used: " + aGenerator);
 
     try {
-      Generator generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator);
+      Generator generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator, null);
 
       generator.generate(aWriter, aGenerationData, logger);
     }
@@ -106,7 +106,7 @@ public class ServletHelper {
 
   public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) {
     try {
-      Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
+      Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator, null);
 
       generator.generate(aWriter, aGenerationData, logger);
     }
index e5b1960..d8df5dc 100755 (executable)
@@ -769,7 +769,8 @@ public class ServletModuleOpenIndy extends ServletModule {
       responseData.put("extra", anExtra);
 
 
-      Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
+      Generator generator =
+          MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator, null);
       generator.generate(anOutputWriter, responseData, getLogger());
 
       anOutputWriter.close();
@@ -789,7 +790,9 @@ public class ServletModuleOpenIndy extends ServletModule {
       responseData.put("extra", anExtra);
 
 
-      Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
+      Generator generator =
+          MirGlobal.localizer().generators().
+              makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator, null);
       generator.generate(anOutputWriter, responseData, getLogger());
 
       anOutputWriter.close();
index 3d76981..c54319e 100755 (executable)
@@ -60,7 +60,8 @@ public class ServletModuleProducer extends AdminServletModule {
   public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) {
     try {
       // TODO: use ServletHelper
-      Generator generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator("producerqueue.template");
+      Generator generator = MirGlobal.localizer().generators().
+          makeAdminGeneratorLibrary().makeGenerator("producerqueue.template", null);
 
       Map generationData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
       generationData.put( "thisurl", "module=Producer&do=showProducerQueueStatus");