/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
* 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.
+ * the code of this program with 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 mircoders.localizer.basic;
-import java.util.*;
-import java.io.*;
-import mir.producer.*;
-import mir.generator.*;
-import mir.producer.reader.*;
-import mir.misc.*;
-import mir.util.*;
-import mir.entity.adapter.*;
-import mircoders.global.*;
-import mircoders.global.*;
-import mircoders.localizer.*;
-import mircoders.producer.reader.*;
-import mircoders.producer.*;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import mir.entity.adapter.EntityAdapterModel;
+import mir.generator.Generator;
+import mir.generator.WriterEngine;
+import mir.log.LoggerWrapper;
+import mir.producer.ProducerFactory;
+import mir.producer.reader.DefaultProducerNodeBuilders;
+import mir.producer.reader.ProducerConfigReader;
+import mir.producer.reader.ProducerNodeBuilderLibrary;
+import mir.util.FileMonitor;
+import mir.util.StringRoutines;
+import mircoders.global.MirGlobal;
+import mircoders.global.ProducerEngine;
+import mircoders.localizer.MirLocalizerExc;
+import mircoders.localizer.MirLocalizerFailure;
+import mircoders.localizer.MirProducerLocalizer;
+import mircoders.producer.reader.SupplementalProducerNodeBuilders;
public class MirBasicProducerLocalizer implements MirProducerLocalizer {
private List producerFactories;
private Map nameToFactory;
- private List allNewProducerTasks;
+
+ private Map producerRecipes;
+ private List producerRecipeNames;
protected FileMonitor fileMonitor;
protected EntityAdapterModel model;
protected Generator.GeneratorLibrary generatorLibrary;
protected WriterEngine writerEngine;
- protected static Logfile logger = Logfile.getInstance( MirGlobal.getConfigProperty("Home") + "/" + MirGlobal.getConfigProperty("Mir.Localizer.Logfile"));
+ protected LoggerWrapper logger;
public MirBasicProducerLocalizer() {
try {
- String allNewProducers = MirGlobal.getConfigProperty("Mir.Localizer.Producer.AllNewProducers");
- allNewProducerTasks = ProducerEngine.ProducerTask.parseProducerTaskList(allNewProducers);
+ logger = new LoggerWrapper("Localizer.Basic.Producer");
+
+ producerRecipes = new HashMap();
+ producerRecipeNames = new Vector();
+
+ String[] recipes = MirGlobal.config().getStringArray("Mir.Localizer.Producer.ProducerRecipes");
+ for (int i = 0; i<recipes.length; i++) {
+ try {
+ List parts = StringRoutines.separateString(recipes[i], "=");
+ if (parts.size() == 2) {
+ producerRecipes.put(parts.get(0), ProducerEngine.ProducerTask.parseProducerTaskList( (String) parts.get(1)));
+ producerRecipeNames.add(parts.get(0));
+ }
+ else {
+ throw new Exception("'=' expected");
+ }
+ }
+ catch (Throwable t) {
+ logger.error("Error while processing producer recipe '" + recipes[i] + "': " + t.toString());
+ }
+ }
+
+ // for backward compatibility:
+ String allNewProducers = MirGlobal.config().getString("Mir.Localizer.Producer.AllNewProducers");
+ if (allNewProducers!=null && allNewProducers.length()>0) {
+ producerRecipes.put("allnew", ProducerEngine.ProducerTask.parseProducerTaskList(allNewProducers));
+ producerRecipeNames.add("allnew");
+ }
producerFactories = new Vector();
model = MirGlobal.localizer().dataModel().adapterModel();
nameToFactory = new HashMap();
}
catch (Throwable t) {
- logger.printError("MirBasicProducerLocalizer(): Exception "+t.getMessage());
+ logger.error("MirBasicProducerLocalizer(): Exception "+t.getMessage());
model = new EntityAdapterModel();
}
}
+ public List getRecipeNames() throws MirLocalizerExc, MirLocalizerFailure {
+ return producerRecipeNames;
+ }
+
+ public void produceRecipe(String aName) throws MirLocalizerExc, MirLocalizerFailure {
+ if (producerRecipes.containsKey(aName))
+ MirGlobal.producerEngine().addTasks((List) producerRecipes.get(aName));
+ else
+ throw new MirLocalizerExc("Unknown recipe name: " + aName);
+ }
+
public List factories() throws MirLocalizerExc {
if (fileMonitor==null || producerFactories == null || fileMonitor.hasChanged()) {
try {
producerFactories = newProducers;
fileMonitor = newFileMonitor;
- logger.printInfo("MirBasicProducerLocalizer.factories(): successfully setup factories");
+ logger.info("MirBasicProducerLocalizer.factories(): successfully setup factories");
nameToFactory.clear();
Iterator i = producerFactories.iterator();
}
}
catch (Throwable t) {
- logger.printError("MirBasicProducerLocalizer.factories(): Unable to setup factories: "+t.getMessage());
+ logger.error("MirBasicProducerLocalizer.factories(): Unable to setup factories: "+t.getMessage());
+ t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
}
}
return producerFactories;
};
+ public ProducerFactory getFactoryForName(String aName) {
+ try {
+ factories();
+ }
+ catch (Throwable t) {
+ }
+
+ return (ProducerFactory) nameToFactory.get(aName);
+ }
+
protected void setupProducerNodeBuilderLibrary(ProducerNodeBuilderLibrary aLibrary) throws MirLocalizerFailure {
try {
DefaultProducerNodeBuilders.registerBuilders(
aLibrary, model, generatorLibrary, writerEngine,
- MirGlobal.getConfigProperty("Home"), MirGlobal.getConfigProperty("Producer.StorageRoot"));
+ MirGlobal.config().getString("Home"), MirGlobal.config().getString("Producer.StorageRoot"));
SupplementalProducerNodeBuilders.registerBuilders(aLibrary, model);
}
catch (Throwable t) {
ProducerConfigReader reader;
ProducerNodeBuilderLibrary library = new ProducerNodeBuilderLibrary();
setupProducerNodeBuilderLibrary(library);
- List usedFiles = new Vector();
- Iterator i;
aFileMonitor.clear();
reader = new ProducerConfigReader();
- reader.parseFile(MirGlobal.getConfigProperty("Home") + File.separatorChar + MirGlobal.getConfigProperty("Mir.Localizer.ProducerConfigFile"), library, aFactories, usedFiles);
-
- i = usedFiles.iterator();
- while (i.hasNext())
- aFileMonitor.addFile((File) i.next());
-
- setupFactories(aFactories);
- }
-
- protected void setupFactories(List aFactories) throws MirLocalizerExc, MirLocalizerFailure {
- CompositeProducerNode node;
-
- try {
- aFactories.add(
- new CompositeProducerFactory("media", new ProducerFactory[] {
- new OldProducerAdapterFactory("images", new ProducerImages()),
- new OldProducerAdapterFactory("audio", new ProducerAudio()),
- new OldProducerAdapterFactory("video", new ProducerVideo()),
- new OldProducerAdapterFactory("other", new ProducerOther())
- } )
- );
- }
- catch (Exception e) {
- throw new MirLocalizerFailure(e);
- }
- };
- public void produceAllNew() {
- MirGlobal.producerEngine().addTasks(allNewProducerTasks);
- };
-
- public ProducerFactory getFactoryForName(String aName) {
- try {
- factories();
- }
- catch (Throwable t) {
- }
-
- return (ProducerFactory) nameToFactory.get(aName);
+ File inputFile = new File(MirGlobal.config().getString("Home"), MirGlobal.config().getString("Mir.Localizer.ProducerConfigFile"));
+ aFileMonitor.addFile(inputFile);
+ reader.parse(inputFile, library, aFactories);
}
}