- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 24 Jul 2009 13:47:48 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/index
In directory hutz:/tmp/cvs-serv28782/org/w3c/unicorn/index
Modified Files:
IndexGenerator.java
Log Message:
Fixed errors where the velocity config file could not be found
New template system for index.html : only one velocity template file and several language properties files
Index: IndexGenerator.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/index/IndexGenerator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- IndexGenerator.java 23 Jul 2009 13:00:42 -0000 1.7
+++ IndexGenerator.java 24 Jul 2009 13:47:46 -0000 1.8
@@ -9,7 +9,11 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
@@ -26,6 +30,7 @@
import org.w3c.unicorn.tasklist.parameters.ParameterType;
import org.w3c.unicorn.util.ListFiles;
import org.w3c.unicorn.util.Property;
+import org.w3c.unicorn.util.MergeProperties;;
/**
* IndexGenerator<br />
@@ -63,7 +68,7 @@
IndexGenerator.aProperties.load(new URL(Property.class.getResource("/"),
Property.get("REL_PATH_TO_CONF_FILES") + "velocity.properties").openStream());
IndexGenerator.aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH,
- Property.get("PATH_TO_INDEX_TEMPLATES"));
+ Property.get("PATH_TO_TEMPLATES"));
IndexGenerator.aVelocityEngine.init(IndexGenerator.aProperties);
} catch (final MalformedURLException e) {
IndexGenerator.logger.error("MalformedURLException : "
@@ -82,13 +87,11 @@
IndexGenerator.aVelocityContext.put("dropdown", ParameterType.DROPDOWN);
IndexGenerator.aVelocityContext.put("checkbox", ParameterType.CHECKBOX);
- IndexGenerator.aVelocityContext.put("checkboxlist",
- ParameterType.CHECKBOXLIST);
+ IndexGenerator.aVelocityContext.put("checkboxlist", ParameterType.CHECKBOXLIST);
IndexGenerator.aVelocityContext.put("radio", ParameterType.RADIO);
IndexGenerator.aVelocityContext.put("textarea", ParameterType.TEXTAREA);
- IndexGenerator.aVelocityContext.put("textfield",
- ParameterType.TEXTFIELD);
-
+ IndexGenerator.aVelocityContext.put("textfield", ParameterType.TEXTFIELD);
+
IndexGenerator.aVelocityContext.put("simple", TUi.SIMPLE);
IndexGenerator.aVelocityContext.put("advanced", TUi.ADVANCED);
IndexGenerator.aVelocityContext.put("none", TUi.NONE);
@@ -107,27 +110,82 @@
public static void generateIndexes() throws ResourceNotFoundException,
ParseErrorException, Exception {
IndexGenerator.logger.trace("generateIndexes");
- final File[] tFile = ListFiles.listFiles(Property
- .get("PATH_TO_INDEX_TEMPLATES"), "\\.vm$");
- for (final File aFile : tFile) {
- final String sName = aFile.getName();
- final String sOutputName = sName.substring(0, sName.length() - 3);
-
- final Template aTemplate = IndexGenerator.aVelocityEngine
- .getTemplate(sName, "UTF-8");
-
- OutputStreamWriter aFileWriter = new OutputStreamWriter(new FileOutputStream(Property.get("PATH_TO_INDEX_OUTPUT")
- + sOutputName),
- "UTF-8");
- aTemplate.merge(IndexGenerator.aVelocityContext, aFileWriter);
- aFileWriter.close();
-
- IndexGenerator.logger.debug("Index file "
- + Property.get("PATH_TO_INDEX_OUTPUT") + sOutputName
- + " generated.");
+
+ // Get the Properties object for the default language
+ File[] defaultLangFile = ListFiles.listFiles(Property.get("PATH_TO_LANGUAGE_FILES"),
+ "index\\." + Property.get("DEFAULT_LANGUAGE"));
+
+ // Get the list of the language properties files
+ File[] langFiles = ListFiles.listFiles(Property.get("PATH_TO_LANGUAGE_FILES"), "index");
+
+ // Get all the languages and their associated code (defined in the name of the properties file) in a hashtable
+ Map<String, String> languages = new Hashtable<String, String>();
+ for (File langFile : langFiles) {
+ Properties props = new java.util.Properties();
+ props.load(langFile.toURL().openStream());
+ languages.put(langFile.getName().split("\\.")[1], props.getProperty("language"));
+ }
+
+ IndexGenerator.logger.info("Found Languages : " + languages.toString());
+
+ aVelocityContext.put("languages", languages);
+
+ MergeProperties mergeProps = new MergeProperties();
+
+ for (File langFile : langFiles) {
+
+ String langCode = langFile.getName().split("\\.")[1];
+
+ Properties props = mergeProps.getMergeProperties(defaultLangFile[0], langFile);
+
+ // Iteration on the properties to add them to the Velocity context
+ Set<Object> keys = props.keySet();
+ Iterator<Object> itr = keys.iterator();
+ String key;
+ while (itr.hasNext()) {
+ key = itr.next().toString();
+ aVelocityContext.put(key, props.get(key));
+ }
+
+ if (langCode.equals(Property.get("DEFAULT_LANGUAGE"))) {
+ writeIndex("index.html");
+ IndexGenerator.logger.info("Default language is \"" + props.getProperty("language") + "\" : created index.html");
+ }
+
+
+
+ String indexPageName = "index." + langCode + ".html";
+ writeIndex(indexPageName);
+
+ IndexGenerator.logger.info("Created index page for language \"" + props.getProperty("language") + "\" : " + indexPageName);
}
+
+
+
+ Template template = aVelocityEngine.getTemplate("index/en_parameters.js.vm");
+
+ OutputStreamWriter fileWriter = new OutputStreamWriter(
+ new FileOutputStream(Property.get("PATH_TO_INDEX_OUTPUT") + "en_parameters.js"),
+ "UTF-8");
+
+ template.merge(IndexGenerator.aVelocityContext, fileWriter);
+ fileWriter.close();
}
-
+
+ private static void writeIndex(String pageName) throws ResourceNotFoundException, ParseErrorException, Exception {
+
+ // index.vm is located in PATH_TO_TEMPLATES
+ Template template = aVelocityEngine.getTemplate("index.vm");
+
+ // Generate the files
+ OutputStreamWriter fileWriter = new OutputStreamWriter(
+ new FileOutputStream(Property.get("PATH_TO_INDEX_OUTPUT") + pageName),
+ "UTF-8");
+
+ template.merge(IndexGenerator.aVelocityContext, fileWriter);
+ fileWriter.close();
+ }
+
/**
* Launch the creation of the indexes
*
Received on Friday, 24 July 2009 13:48:01 UTC