-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mir.producer;\r
-\r
-import java.util.*;\r
-\r
-import mir.generator.Generator;\r
-import mir.generator.WriterEngine;\r
-import mir.log.LoggerWrapper;\r
-import mir.util.ParameterExpander;\r
-\r
-public class GeneratingProducerNode implements ProducerNode {\r
- private String generatorExpression;\r
- private String destinationExpression;\r
- private String parametersExpression;\r
- private Generator.GeneratorLibrary generatorLibrary;\r
- private WriterEngine writerEngine;\r
-\r
- public GeneratingProducerNode(Generator.GeneratorLibrary aGeneratorLibrary, WriterEngine aWriterEngine, String aGenerator, String aDestination, String aParameters) {\r
- generatorExpression=aGenerator;\r
- destinationExpression=aDestination;\r
- parametersExpression=aParameters;\r
- generatorLibrary = aGeneratorLibrary;\r
- writerEngine = aWriterEngine;\r
- }\r
-\r
- public GeneratingProducerNode(Generator.GeneratorLibrary aGeneratorLibrary, WriterEngine aWriterEngine, String aGenerator, String aDestination) {\r
- this(aGeneratorLibrary, aWriterEngine, aGenerator, aDestination, "");\r
- }\r
-\r
- public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {\r
- Generator generator;\r
- Object writer;\r
- String generatorIdentifier;\r
- String destinationIdentifier;\r
- String parameters;\r
-\r
- long startTime;\r
- long endTime;\r
-\r
- startTime = System.currentTimeMillis();\r
- try {\r
- Map mirMap = (Map) aValueMap.get("Mir");\r
- if (mirMap==null) {\r
- mirMap = new HashMap();\r
- aValueMap.put("Mir", mirMap);\r
- }\r
-\r
- Object oldGenerator = mirMap.get("generator");\r
- Object oldDestination = mirMap.get("destination");\r
- Object oldParameters = mirMap.get("parameters");\r
- try {\r
- destinationIdentifier = ParameterExpander.expandExpression(aValueMap, destinationExpression);\r
- generatorIdentifier = ParameterExpander.expandExpression(aValueMap, generatorExpression);\r
- parameters = ParameterExpander.expandExpression(aValueMap, parametersExpression);\r
-\r
- mirMap.put("generator", generatorIdentifier);\r
- mirMap.put("destination", destinationIdentifier);\r
- mirMap.put("parameters", parameters);\r
-\r
- writer = writerEngine.openWriter(destinationIdentifier, parameters);\r
- generator = generatorLibrary.makeGenerator(generatorIdentifier);\r
- generator.generate(writer, aValueMap, aLogger);\r
- writerEngine.closeWriter(writer);\r
-\r
- endTime = System.currentTimeMillis();\r
- aLogger.info("Generated " + generatorIdentifier + " into " + destinationIdentifier + " [" + parameters + "] in " + (endTime - startTime) + " ms");\r
- }\r
- finally {\r
- mirMap.put("generator", oldGenerator);\r
- mirMap.put("destination", oldDestination);\r
- mirMap.put("parameters", oldParameters);\r
- }\r
- }\r
- catch (Throwable t) {\r
- aLogger.error(" error while generating: " + t.getClass().getName() + ": " + t.getMessage());\r
- }\r
- }\r
+/*
+ * Copyright (C) 2001-2006 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 any library licensed under the Apache Software License,
+ * 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.producer;
+
+import mir.changetracker.ChangeTracker;
+import mir.changetracker.ChangeType;
+import mir.generator.Generator;
+import mir.generator.WriterEngine;
+import mir.log.LoggerWrapper;
+import mir.util.ParameterExpander;
+import mircoders.global.MirGlobal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GeneratingProducerNode extends AbstractProducerNode {
+ private String generatorExpression;
+ private String destinationExpression;
+ private String parametersExpression;
+ private Generator.Library generatorLibrary;
+ private WriterEngine writerEngine;
+ private Generator.Interceptor interceptor;
+
+ 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, Generator.Interceptor anInterceptor, String aGenerator, String aDestination) {
+ this(aGeneratorLibrary, aWriterEngine, anInterceptor, aGenerator, aDestination, "");
+ }
+
+ public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
+ Generator generator;
+ Object writer;
+ String generatorIdentifier;
+ String destinationIdentifier;
+ String parameters;
+
+ long startTime;
+ long endTime;
+
+ startTime = System.currentTimeMillis();
+ try {
+ Map mirMap = (Map) aValueMap.get("Mir");
+ if (mirMap==null) {
+ mirMap = new HashMap();
+ aValueMap.put("Mir", mirMap);
+ }
+
+ Object oldGenerator = mirMap.get("generator");
+ Object oldDestination = mirMap.get("destination");
+ Object oldParameters = mirMap.get("parameters");
+ try {
+ destinationIdentifier = ParameterExpander.expandExpression(aValueMap, destinationExpression);
+ generatorIdentifier = ParameterExpander.expandExpression(aValueMap, generatorExpression);
+ parameters = ParameterExpander.expandExpression(aValueMap, parametersExpression);
+ //String relPathExpression = "/${article.date.formatted.yyyy}/${article.date.formatted.MM}/${article.id}.shtml";
+ //String relativePath = ParameterExpander.expandExpression(aValueMap, relPathExpression);
+ mirMap.put("generator", generatorIdentifier);
+ mirMap.put("destination", destinationIdentifier);
+ mirMap.put("parameters", parameters);
+
+ writer = writerEngine.openWriter(destinationIdentifier, parameters);
+ generator = generatorLibrary.makeGenerator(generatorIdentifier, interceptor);
+ generator.generate(writer, aValueMap, aLogger);
+ writerEngine.closeWriter(writer);
+
+ endTime = System.currentTimeMillis();
+ aLogger.debug("Generated " + generatorIdentifier + " into " + destinationIdentifier + " [" + parameters + "] in " + (endTime - startTime) + " ms");
+ reportChange(destinationIdentifier);
+ }
+ finally {
+ mirMap.put("generator", oldGenerator);
+ mirMap.put("destination", oldDestination);
+ mirMap.put("parameters", oldParameters);
+ }
+ }
+ catch (Throwable t) {
+ aLogger.error(" error while generating", t);
+ }
+ }
+
+ private void reportChange(String aPath) {
+ ChangeTracker changeTracker = MirGlobal.getChangeEngine().getTracker();
+ changeTracker.addChange(aPath, ChangeType.MODIFICATION);
+ }
}
\ No newline at end of file