W3C home > Mailing lists > Public > www-validator-cvs@w3.org > August 2009

2006/unicorn/src/org/w3c/unicorn Framework.java,1.1.2.8,1.1.2.9

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 18 Aug 2009 11:56:38 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MdNIs-0001TV-5w@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv5650/src/org/w3c/unicorn

Modified Files:
      Tag: dev2
	Framework.java 
Log Message:
added verifications

Index: Framework.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Attic/Framework.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -d -r1.1.2.8 -r1.1.2.9
--- Framework.java	17 Aug 2009 17:28:26 -0000	1.1.2.8
+++ Framework.java	18 Aug 2009 11:56:36 -0000	1.1.2.9
@@ -12,6 +12,7 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
@@ -32,6 +33,8 @@
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
 import org.w3c.unicorn.contract.Observer;
 import org.w3c.unicorn.contract.WADLUnmarshaller;
 import org.w3c.unicorn.contract.WADLUnmarshallerXPath;
@@ -109,7 +112,7 @@
 	/**
 	 * Initialize Unicorn
 	 */
-	public static void init()  throws Exception {
+	public static void init() {// throws Exception {
 		unicornPropertiesFiles = new Hashtable<String, Properties>();
 		languageContexts = new Hashtable<String, VelocityContext>();
 		languageProperties = new Hashtable<String, Properties>();
@@ -284,7 +287,6 @@
 		// Loading observers
 		logger.debug("-------------------------------------------------------");
 		logger.debug("Loading available observers from the observers list file.");
-		LocalizedString.DEFAULT_LANGUAGE = Property.get("DEFAULT_LANGUAGE");
 		BufferedReader aBufferedReader;
 		try {
 			aBufferedReader = new BufferedReader(new FileReader(Property.get("OBSERVER_LIST_FILE")));
@@ -384,6 +386,7 @@
 		aRDFUnmarshaller.setMapOfObserver(mapOfObserver);
 		for (final File aFile : tFileRDF) {
 			try {
+				logger.debug("- Loading rdf file: " + aFile.getName());
 				aRDFUnmarshaller.addURL(aFile.toURI().toURL());
 				aRDFUnmarshaller.unmarshal();
 			} catch (MalformedURLException e) {
@@ -397,13 +400,26 @@
 			}
 		}
 		mapOfTask = aTaskListUnmarshaller.getMapOfTask();
+		for (String key : mapOfTask.keySet()) {
+			Task task = mapOfTask.get(key);
+			String defaultLang = Property.get("DEFAULT_LANGUAGE");
+			if (task.getLongName().getLocalization(defaultLang) == null) {
+				task.getLongName().addLocalization(defaultLang, key);
+				logger.warn("Missing default language long name for task: " + key + ". Long name will be the task id.");
+			}
+		}
 		if (mapOfTask.size() == 0) {
 			logger.fatal("No task have been loaded. Check task files in: " + Property.get("PATH_TO_TASKLIST"));
 			return;
 		} else {
+			String s = "Map of tasks:";
+			for (String key : mapOfTask.keySet()) {
+				s += "\n\t" + key + " => " + mapOfTask.get(key).getLongName() + " - " + mapOfTask.get(key).getDescription();
+			}
+			logger.debug(s);
 			logger.info("OK - " + mapOfTask.size() + " task(s) successfully loaded.");
-			logger.info(mapOfTask);
 		}
+		
 
 		// Retrieve output lang from PATH_TO_OUTPUT_TEMPLATES
 		/*File[] listFD = (new File(Property.get("PATH_TO_TEMPLATES")))
@@ -417,17 +433,22 @@
 			outputLang.add((listFD[i].getName().split("_"))[0]);
 		}*/
 
-		outputLang = new HashSet<String>();
+		//outputLang = new HashSet<String>();
 		
 		
 		// Loading language files
-		if (!Language.isISOLanguageCode(Property.get("DEFAULT_LANGUAGE")))
-			logger.error("Property DEFAULT_LANGUAGE is not a valid ISO639 code: " + Property.get("DEFAULT_LANGUAGE"));
+		logger.debug("-------------------------------------------------------");
+		logger.debug("Loading language files from language directory: " + Property.get("PATH_TO_LANGUAGE_FILES"));
+		if (!Language.isISOLanguageCode(Property.get("DEFAULT_LANGUAGE"))) {
+			logger.fatal("Property DEFAULT_LANGUAGE is not a valid ISO639 code: " + Property.get("DEFAULT_LANGUAGE"));
+			return;
+		}
 		
 		File defaultLanguageFile = new File(Property.get("PATH_TO_LANGUAGE_FILES", "DEFAULT_LANGUAGE") + ".properties");
 		if (!defaultLanguageFile.exists()) {
-			logger.error("Default language file does not exists: " + Property.get("PATH_TO_LANGUAGE_FILES", "DEFAULT_LANGUAGE") + ".properties");
-		} 
+			logger.fatal("Default language file does not exists: " + Property.get("PATH_TO_LANGUAGE_FILES", "DEFAULT_LANGUAGE") + ".properties");
+			return;
+		}
 		
 		File[] languageFiles = ListFiles.listFiles(Property
 				.get("PATH_TO_LANGUAGE_FILES"), "\\.properties$");
@@ -435,20 +456,59 @@
 		for (File langFile : languageFiles) {
 			String localeString = langFile.getName().split("\\.")[0];
 			if (!Language.isISOLanguageCode(localeString))
-				logger.warn(langFile.getName() + " is not a language file: " + localeString + " is not a valid locale.");
+				logger.warn("Invalid language file: " + langFile.getName() + "" +
+						". \"" + localeString + "\" is not a valid locale.");
 			else {
-				FileInputStream fis = new FileInputStream(langFile);
-				InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
-				Properties props = new Properties();
-				props.load(isr);
-				props.put("lang", localeString);
-				props.put("tasklist", mapOfTask);
-				languageProperties.put(localeString, props);
-				logger.debug("Added language file: " + localeString + " - " + props.getProperty("language"));
+				try {
+					FileInputStream fis = new FileInputStream(langFile);
+					InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
+					Properties props = new Properties();
+					props.load(isr);
+					props.put("lang", localeString);
+					props.put("tasklist", mapOfTask);
+					languageProperties.put(localeString, props);
+					String s;
+					if (localeString.equals(Property.get("DEFAULT_LANGUAGE")))
+						s = " (default)";
+					else
+						s = "";
+					logger.debug("> Added language"+s+": " + localeString + " - " + props.getProperty("language"));
+				} catch (FileNotFoundException e) {
+					// Should not happen
+					logger.error(e.getMessage(), e);
+				} catch (UnsupportedEncodingException e) {
+					// Should not happen
+					logger.error(e.getMessage(), e);
+				} catch (IOException e) {
+					if (!localeString.equals(Property.get("DEFAULT_LANGUAGE"))) {
+						logger.error("Unable to read language file. " + langFile + ". This file will be skiped.");
+						continue;
+					}
+					else {
+						logger.fatal("Unable to read default language file. " + langFile);
+						return;
+					}
+				}
 			}
 		}
+		if (languageProperties.size() == 0) {
+			logger.fatal("No language have been loaded. Check language files in: " + Property.get("PATH_TO_LANGUAGE_FILES"));
+			return;
+		} else {
+			String s = "Language properties:";
+			for (String key : languageProperties.keySet()) {
+				s += "\n\n\t" + languageProperties.get(key).getProperty("language") + ":";
+				for (Object langKey : languageProperties.get(key).keySet()) {
+					s += "\n\t\t" + langKey + " => " + languageProperties.get(key).getProperty((String) langKey); 
+				}
+			}
+			logger.debug(s);
+			logger.info("OK - " + languageProperties.size() + " language(s) successfully loaded.");
+		}
 		
 		// Creating velocity contexts
+		logger.debug("-------------------------------------------------------");
+		logger.debug("Initializing Velocity");
 		for (String locale : languageProperties.keySet()) {
 			VelocityContext context = new VelocityContext();
 			Properties langProps = languageProperties.get(locale);
@@ -459,25 +519,44 @@
 			context.put("param_prefix", Property.get("UNICORN_PARAMETER_PREFIX"));
 			languageContexts.put(locale, context);
 		}
-		
-		//for (String key : languageContexts.keySet()) {
-		//	logger.error("Context: " + key + " - " + languageContexts.get(key));
-		//}
+		logger.debug("> "+languageContexts.size()+" velocity context(s) created");
 		
 		// Creating velocity engine
 		velocityEngine = new VelocityEngine();
 		Properties bProperties = Property.getProps("velocity.properties");
 		bProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
 				.get("PATH_TO_TEMPLATES"));
-		velocityEngine.init(bProperties);
+		logger.debug("> Initializing velocity engine with FILE_RESOURCE_LOADER_PATH: " + Property.get("PATH_TO_TEMPLATES"));
+		try {
+			velocityEngine.init(bProperties);
+			logger.debug("> Velocity engine successfully initialized");
+		} catch (Exception e) {
+			logger.fatal("Error instanciating velocity engine. " + e.getMessage(), e);
+			return;
+		}
 		
-		// Creating velocity templates
-		velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
-		//velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
+		// TODO load all templates in the template directory
+		// Loading velocity templates
+		try {
+			velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
+		} catch (ResourceNotFoundException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (ParseErrorException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		logger.debug("> "+velocityTemplates.size()+" velocity template(s) loaded");
+		// TODO add debug information on the loaded templates
+		
+		logger.info("OK - Velocity successfully initialized");
 		
 		TemplateHelper.init();
 		
-		Framework.logger.info("End of initialisation of UniCORN.");
+		Framework.logger.info("Unicorn initialized successfully.");
 		isUcnInitialized = true;
 	}
 	
Received on Tuesday, 18 August 2009 11:56:48 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:38 UTC