}\r
}\r
\r
-\r
public boolean hasNext() throws StorageObjectException {\r
if (position>=currentBatch.size() && currentBatch.hasNextBatch()) {\r
readNextBatch();\r
--- /dev/null
+package mir.util;
+
+import java.util.*;
+
+public class ParameterExpander {
+
+ final static String DEFAULT_KEY = "(default)";
+ final static String NODE_SEPARATOR = ".";
+
+ private 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;
+ }
+
+ public static String findValueForKey(Map aMap, String aKey) throws Exception {
+ Object node;
+ Iterator i;
+ List parts = splitString(aKey, NODE_SEPARATOR);
+ String location = "";
+
+ node = aMap;
+
+ i = parts.iterator();
+
+ while(i.hasNext()) {
+ String part = (String) i.next();
+
+ if (!(node instanceof Map)) {
+ throw new Exception( "Can't expand key " + aKey + ": " + location + " is not a map" );
+ }
+
+ node = ((Map) node).get(part);
+
+ if (location.length()>0) {
+ location=location + NODE_SEPARATOR;
+ }
+
+ location = location + part;
+
+ if (node == null) {
+ throw new Exception( "Can't expand key " + aKey + ": "+ location + " does not exist" );
+ }
+ }
+
+ if (node instanceof Map) {
+ node = ((Map) node).get(DEFAULT_KEY);
+ }
+
+ if (!(node instanceof String))
+ throw new Exception( "Can't expand key " + aKey + ": "+ location + " is not a string but a " + node.getClass().getName() );
+
+ return (String) node;
+ }
+
+ public static String expandExpression(Map aMap, String anExpression) throws Exception {
+ int previousPosition = 0;
+ int position;
+ int endOfNamePosition;
+ StringBuffer result = new StringBuffer();
+
+ while ((position=anExpression.indexOf("$", previousPosition))>=0) {
+ result.append(anExpression.substring(previousPosition, position));
+
+ if (position>=anExpression.length()-1) {
+ result.append(anExpression.substring(position, anExpression.length()));
+ previousPosition=anExpression.length();
+ }
+ else
+ {
+ if (anExpression.charAt(position+1) == '{') {
+ endOfNamePosition=anExpression.indexOf('}', position);
+ if (endOfNamePosition>=0) {
+ result.append(findValueForKey(aMap, anExpression.substring(position+2, endOfNamePosition)));
+ previousPosition=endOfNamePosition+1;
+ }
+ else {
+ throw new Exception("Missing } in " + anExpression);
+ }
+ }
+ else
+ {
+ previousPosition=position+2;
+ result.append(anExpression.charAt(position+1));
+ }
+ }
+ }
+ result.append(anExpression.substring(previousPosition, anExpression.length()));
+
+ return result.toString();
+ }
+}
+
+
public static MirLocalizer localizer() {
if (localizer == null ) {
- localizer = new MirBasicLocalizer();
+ localizer = new MirCachingLocalizerDecorator(new MirBasicLocalizer());
}
return localizer;
--- /dev/null
+package mircoders.localizer;
+
+public class MirCachingLocalizerDecorator implements MirLocalizer {
+ private MirLocalizer localizer;
+ private MirProducerLocalizer producerLocalizer;
+ private MirGeneratorLocalizer generatorLocalizer;
+ private MirOpenPostingLocalizer openPostingsLocalizer;
+ private MirProducerToolLocalizer producerToolLocalizer;
+
+ public MirCachingLocalizerDecorator(MirLocalizer aLocalizer) {
+ localizer = aLocalizer;
+ }
+
+ public MirProducerLocalizer producers() {
+ if (producerLocalizer==null) {
+ producerLocalizer = localizer.producers();
+ }
+
+ return producerLocalizer;
+ }
+
+ public MirGeneratorLocalizer generators() {
+ if (generatorLocalizer==null) {
+ generatorLocalizer = localizer.generators();
+ }
+
+ return generatorLocalizer;
+ }
+
+ public MirOpenPostingLocalizer openPostings() {
+ if (openPostingsLocalizer==null) {
+ openPostingsLocalizer = localizer.openPostings();
+ }
+
+ return openPostingsLocalizer;
+ }
+
+ public MirProducerToolLocalizer producerTool() {
+ if (producerToolLocalizer==null) {
+ producerToolLocalizer = localizer.producerTool();
+ }
+
+ return producerToolLocalizer;
+ }
+
+}
\ No newline at end of file
package mircoders.localizer;
+import java.util.*;
+
public interface MirProducerToolLocalizer {
+ public void initializeGenerationValueSet(Map aValueSet);
}
new ContentProducerFactory(
MirGlobal.getConfigProperty("Producer.Content.Template"),
"bundles.admin",
- MirGlobal.getConfigProperty("Producer.StorageRoot"),
- ".shtml",
+ MirGlobal.getConfigProperty("Producer.StorageRoot") + "/${contentyear}/${contentmonth}/${contentid}.shtml",
Integer.parseInt(MirGlobal.getConfigProperty("Producer.Content.Batchsize"))));
}
protected void setupStartPageFactory(CompositeProducerFactory aStartPageFactory) {
aStartPageFactory.addFactory(
new StartPageProducerFactory(
- MirGlobal.getConfigProperty("Producer.StartPage.Template"),
- "bundles.admin",
- MirGlobal.getConfigProperty("Producer.StorageRoot") + "/index.shtml",
- MirGlobal.getConfigIntegerProperty("Producer.StartPage.Items"),
- MirGlobal.getConfigIntegerProperty("Producer.StartPage.Newswire")));
+ MirGlobal.getConfigProperty("Producer.StartPage.Template"),
+ "bundles.admin",
+ MirGlobal.getConfigProperty("Producer.StorageRoot") + "/index.shtml",
+ MirGlobal.getConfigIntegerProperty("Producer.StartPage.Items"),
+ MirGlobal.getConfigIntegerProperty("Producer.StartPage.Newswire")));
+
+
+ aStartPageFactory.addFactory(
+ new TopicStartPageProducerFactory(
+ MirGlobal.getConfigProperty("Producer.StartPage.Template"),
+ "bundles.admin",
+ MirGlobal.getConfigProperty("Producer.StorageRoot") + "/${filename}index.shtml",
+ MirGlobal.getConfigIntegerProperty("Producer.StartPage.Items"),
+ MirGlobal.getConfigIntegerProperty("Producer.StartPage.Newswire")));
}
protected void setupSynchronizationFactory(CompositeProducerFactory aSynchronizationFactory) {
setupSynchronizationFactory(factory);
aFactoriesMap.put("synchronization", factory);
- aFactoriesMap.put("oldstartpage", new OldProducerAdapterFactory(new ProducerStartPage()));
+
+
aFactoriesMap.put("images", new OldProducerAdapterFactory(new ProducerImages()));
aFactoriesMap.put("navigation", new OldProducerAdapterFactory(new ProducerNavigation()));
aFactoriesMap.put("openposting", new OldProducerAdapterFactory(new ProducerOpenPosting()));
aFactoriesMap.put("topics", new OldProducerAdapterFactory(new ProducerTopics()));
-
};
}
package mircoders.localizer.basic;
+import java.util.*;
+import freemarker.template.utility.*;
+import mir.misc.*;
import mircoders.localizer.*;
+import mircoders.global.*;
public class MirBasicProducerToolLocalizer implements MirProducerToolLocalizer {
+
+ public void initializeGenerationValueSet(Map aValueSet) {
+ // ML: these config settings will be included more beautifully as soon as the new config system is in place
+
+ Map configMap = new HashMap();
+
+ configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot"));
+ configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
+ configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
+ configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
+ configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
+ configMap.put("now", StringUtil.date2readableDateTime(new GregorianCalendar()));
+ configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
+ configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
+ configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
+ configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
+ configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
+ configMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
+
+ aValueSet.put("config", configMap);
+ };
}
import java.io.*;
import java.util.*;
+import mir.util.*;
import mir.misc.*;
import mir.entity.*;
import mir.producer.*;
private String generatorIdentifier;
private String resourceBundle;
- private String outputFilePrefix;
- private String outputFilePostfix;
+ private String outputFileExpression;
+
EntityBrowser browser;
EntityBrowser aBrowser,
String aGeneratorIdentifier,
String aResourceBundle,
- String anOutputFilePrefix,
- String anOutputFilePostfix) {
+ String anOutputFileExpression) {
browser = aBrowser;
- generatorIdentifier=aGeneratorIdentifier;
- resourceBundle=aResourceBundle;
- outputFilePrefix=anOutputFilePrefix;
- outputFilePostfix=anOutputFilePostfix;
+ generatorIdentifier = aGeneratorIdentifier;
+ resourceBundle = aResourceBundle;
+ outputFileExpression = anOutputFileExpression;
}
public void produce( PrintWriter aLogger ) throws ProducerException {
EntityContent content;
- Map configMap = new HashMap();
Map generationValues = new HashMap();
Map dataMap = new HashMap();
String fileName;
-
-
- configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot"));
- configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
- configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
- configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
- configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
- configMap.put("now", StringUtil.date2readableDateTime(new GregorianCalendar()));
- configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
- configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
- configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
- configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
- configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
- configMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
- generationValues.put("config", configMap);
+ MirGlobal.localizer().producerTool().initializeGenerationValueSet(generationValues);
MessageResources messages = MessageResources.getMessageResources(resourceBundle);
generationValues.put("lang", new MessageMethodModel(null, messages) );
generationValues.put("data", dataMap);
-
-
try {
Generator generator = MirGlobal.localizer().generators().makeGenerator(generatorIdentifier);
- aLogger.println("ContentProducer.produce:<br>");
- aLogger.println("generatorIdentifier = " + generatorIdentifier + "<br>");
+ aLogger.println("ContentProducer.produce:");
+ aLogger.println("generatorIdentifier = " + generatorIdentifier);
while (browser.hasNext()) {
content = (EntityContent) browser.next();
String date = content.getValue("date");
- fileName = outputFilePrefix + "/" +
- date.substring(0,4) + "/" + date.substring(4,6) + "/" +
- content.getValue("id") + outputFilePostfix;
+ // ML: this will be done more elegantly soon!
+ dataMap.put("contentmonth", date.substring(4,6));
+ dataMap.put("contentyear", date.substring(0,4));
+ dataMap.put("contentid", content.getValue("id"));
+
+ aLogger.println("unparsed fileName = " + outputFileExpression);
+
+ fileName = ParameterExpander.expandExpression(dataMap, outputFileExpression);
- aLogger.println("fileName = " + fileName + "<br>");
+ aLogger.println("fileName = " + fileName);
try {
File file = new File(fileName);
FileWriter fileWriter = new FileWriter(file);
PrintWriter printWriter = new PrintWriter(fileWriter);
- aLogger.println("generating: " + fileName + "<br/>");
+ aLogger.println("generating: " + fileName);
generator.generate(printWriter, generationValues, aLogger);
printWriter.close();
fileWriter.close();
content.setProduced(true);
- aLogger.println("done generating: " + fileName + "<br/>");
+ aLogger.println("done generating: " + fileName);
}
catch (Exception e) {
- aLogger.println("exception while generating " + fileName + ":<br/>");
- aLogger.println(e.getMessage() + "<br/>");
+ aLogger.println("exception while generating " + fileName + ":");
+ aLogger.println(e.getMessage());
e.printStackTrace(aLogger);
aLogger.flush();
}
}
}
catch (Exception e) {
- aLogger.println("exception while generating:<br/>");
- aLogger.println(e.getMessage() + "<br/>");
+ aLogger.println("exception while generating:");
+ aLogger.println(e.getMessage());
e.printStackTrace(aLogger);
aLogger.flush();
}
- aLogger.println("ContentProducer.produce: done<br>");
+ aLogger.println("ContentProducer.produce: done");
}
public class ContentProducerFactory implements ProducerFactory {
private String generatorIdentifier;
private String resourceBundle;
- private String outputFilePrefix;
- private String outputFilePostfix;
+ private String outputFileNameExpression;
private int batchSize;
-// ML: extra selection needed for article types
public ContentProducerFactory(
String aGeneratorIdentifier,
String aResourceBundle,
- String anOutputFilePrefix,
- String anOutputFilePostfix,
+ String anOutputFileNameExpression,
int aBatchSize) {
- generatorIdentifier=aGeneratorIdentifier;
- resourceBundle=aResourceBundle;
- outputFilePrefix=anOutputFilePrefix;
- outputFilePostfix=anOutputFilePostfix;
+ generatorIdentifier = aGeneratorIdentifier;
+ resourceBundle = aResourceBundle;
+ outputFileNameExpression = anOutputFileNameExpression;
batchSize=aBatchSize;
}
batchSize),
generatorIdentifier,
resourceBundle,
- outputFilePrefix,
- outputFilePostfix
+ outputFileNameExpression
);
} catch (Exception e) {
throw new ProducerException(e);
--- /dev/null
+package mircoders.producer;
+
+import java.io.*;
+import mir.producer.*;
+
+public class NullProducer implements mir.producer.Producer {
+ public NullProducer() {
+ }
+
+ public void produce( PrintWriter aLogger ) throws ProducerException {
+ }
+}
+
+
+
--- /dev/null
+package mircoders.producer;
+
+import java.io.*;
+import java.util.*;
+import mir.producer.*;
+
+public class NullProducerFactory implements ProducerFactory {
+ List verbs;
+
+ public NullProducerFactory() {
+ verbs = new Vector();
+ }
+
+ public void addVerb(String aVerb) {
+ verbs.add(aVerb);
+ }
+
+ public mir.producer.Producer makeProducer(String aVerb) {
+ return new NullProducer();
+ }
+
+
+ public Iterator verbs() {
+ return verbs.iterator();
+ }
+}
Process process;
int returnValue;
- aLogger.println("Executing " + script + ":<br>");
+ aLogger.println("Executing " + script + ":");
try {
process = Runtime.getRuntime().exec(script);
returnValue = process.waitFor();
- aLogger.println("Terminated successfully, return value = " + returnValue + ".<br>");
+ aLogger.println("Terminated successfully, return value = " + returnValue + ".");
}
catch (Throwable e) {
- aLogger.println("Exception has occurred: " + e.getMessage() + ":<br>");
+ aLogger.println("Exception has occurred: " + e.getMessage() + ":");
e.printStackTrace(aLogger);
throw new ProducerException(e);
}
Generator generator = MirGlobal.localizer().generators().makeGenerator(generatorIdentifier);
- aLogger.println("StartPageProducer.produce:<br>");
- aLogger.println("generatorIdentifier = " + generatorIdentifier + "<br>");
+ aLogger.println("StartPageProducer.produce:");
+ aLogger.println("generatorIdentifier = " + generatorIdentifier);
File file = new File(outputFile);
FileWriter fileWriter = new FileWriter(file);
PrintWriter printWriter = new PrintWriter(fileWriter);
- aLogger.println("generating: " + outputFile + "<br/>");
+ aLogger.println("generating: " + outputFile);
generator.generate(printWriter, generationValues, aLogger);
printWriter.close();
fileWriter.close();
- aLogger.println("done<br/>");
+ aLogger.println("done");
}
catch (Exception e) {
- aLogger.println("exception while generating " + outputFile + ":<br/>");
- aLogger.println(e.getMessage() + "<br/>");
+ aLogger.println("exception while generating " + outputFile + ":");
+ aLogger.println(e.getMessage());
e.printStackTrace(aLogger);
aLogger.flush();
}
--- /dev/null
+package mircoders.producer;
+
+import java.util.*;
+import mir.entity.*;
+import mir.producer.*;
+import mir.util.*;
+import mircoders.storage.*;
+import mircoders.module.*;
+import mircoders.entity.*;
+
+
+public class TopicStartPageProducerFactory implements ProducerFactory {
+ private String generatorIdentifier;
+ private String resourceBundle;
+ private String outputFileNameExpression;
+ private int nrNewswireItems;
+ private int nrFeatures;
+
+ public TopicStartPageProducerFactory(
+ String aGeneratorIdentifier,
+ String aResourceBundle,
+ String anOutputFileNameExpression,
+ int aNrFeatures,
+ int aNrNewswireItems) {
+
+ generatorIdentifier = aGeneratorIdentifier;
+ resourceBundle = aResourceBundle;
+ outputFileNameExpression = anOutputFileNameExpression;
+ nrFeatures = aNrFeatures;
+ nrNewswireItems = aNrNewswireItems;
+ }
+
+
+ public mir.producer.Producer makeProducer(String aVerb) throws ProducerException {
+ CompositeProducer result = new CompositeProducer();
+ Map values = new HashMap();
+
+ try {
+ ModuleContent contentModule = new ModuleContent(DatabaseContent.getInstance());
+ ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
+ ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
+
+ EntityBrowser topicBrowser = new EntityBrowser(
+ DatabaseTopics.getInstance(),
+ "",
+ "",
+ 100);
+
+ while (topicBrowser.hasNext()) {
+ Entity topic = (Entity) topicBrowser.next();
+ values.put("title", topic.getValue("title"));
+ values.put("filename", topic.getValue("filename"));
+ values.put("main_url", topic.getValue("main_url"));
+ values.put("archiv_url", topic.getValue("archiv_url"));
+
+
+ // ML: ok, this is way to low-level for this place:
+ String orderBy = "webdb_create desc";
+ String topicSelection = "exists (select * from content_x_topic where content_id=content.id and topic_id='"+topic.getValue("id")+"')";
+ String featureWhereClause = "is_published='1' and to_article_type='2' and "+topicSelection;
+ String newsWireWhereClause = "is_published='1' and to_article_type='1' and "+topicSelection;
+
+ result.addProducer(
+
+ // "exists (select * from content_x_topic where content_id=content.id and topic_id="+topic.getValue("id")
+ new StartPageProducer(
+ generatorIdentifier,
+ resourceBundle,
+ ParameterExpander.expandExpression(values, outputFileNameExpression),
+ contentModule.getContent(newsWireWhereClause, orderBy, 0,nrNewswireItems),
+ contentModule.getContent(featureWhereClause, orderBy, 0,nrFeatures),
+ topicsModule .getTopicsList(),
+ breakingModule.getBreakingNews()));
+ }
+
+ return result;
+
+
+ }
+ catch (Throwable e) {
+ throw new ProducerException(e);
+ }
+ };
+
+ public Iterator verbs() {
+ Vector verbList = new Vector();
+
+ verbList.add("all");
+
+ return verbList.iterator();
+ };
+}
+