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

2006/unicorn/src/org/w3c/unicorn Framework.java,1.1.2.3,1.1.2.4

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 13 Aug 2009 13:42:44 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MbaZo-0000hg-Go@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv2554/src/org/w3c/unicorn

Modified Files:
      Tag: dev2
	Framework.java 
Log Message:
more actions in Framework
+ IndexAction
+ language negociation structure

Index: Framework.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Attic/Framework.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -d -r1.1.2.3 -r1.1.2.4
--- Framework.java	12 Aug 2009 17:28:05 -0000	1.1.2.3
+++ Framework.java	13 Aug 2009 13:42:42 -0000	1.1.2.4
@@ -18,7 +18,6 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -26,12 +25,14 @@
 import javax.xml.namespace.NamespaceContext;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
+import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
 import org.w3c.unicorn.contract.Observer;
 import org.w3c.unicorn.contract.WADLUnmarshaller;
 import org.w3c.unicorn.contract.WADLUnmarshallerXPath;
 import org.w3c.unicorn.language.Language;
-import org.w3c.unicorn.output.OutputFactory;
 import org.w3c.unicorn.response.parser.ResponseParser;
 import org.w3c.unicorn.tasklist.RDFUnmarshaller;
 import org.w3c.unicorn.tasklist.RDFUnmarshallerJena;
@@ -67,7 +68,7 @@
 	//public static Properties aPropertiesExtension;
 
 	/**
-	 * List of availables output lang in PATH_TO_OUTPUT_TEMPLATES
+	 * List of available output languages in PATH_TO_OUTPUT_TEMPLATES
 	 */
 	public static Set<String> outputLang;
 
@@ -90,16 +91,22 @@
 	 * True if initialization did not throw any exception
 	 */
 	public static boolean isUcnInitialized = false;
-	
 	private static Hashtable<String, Properties> unicornPropertiesFiles;
 	private static Hashtable<String, VelocityContext> languageContexts;
 	private static Hashtable<String, Properties> languageProperties;
+	private static VelocityEngine velocityEngine;
+	private static Hashtable<String, Template> velocityTemplates;
 	
 	/**
 	 * Initialize Unicorn
 	 * @throws Exception 
 	 */
 	public static void init() throws Exception {
+		unicornPropertiesFiles = new Hashtable<String, Properties>();
+		languageContexts = new Hashtable<String, VelocityContext>();
+		languageProperties = new Hashtable<String, Properties>();
+		velocityTemplates = new Hashtable<String, Template>();
+		
 		// Checks that unicorn.home (JVM parameter) is set to an existing directory
 		String ucnHome = System.getProperty("unicorn.home");
 		System.err.println(ucnHome);
@@ -185,21 +192,9 @@
 			}
 		}
 		
-		if (!Language.isISOLanguageCode(Property.get("DEFAULT_LANGUAGE")))
-			logger.error("Property DEFAULT_LANGUAGE is not a valid ISO639 code: " + Property.get("DEFAULT_LANGUAGE"));
 		
-		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");
-		} 
 		
-		File[] languageFiles = ListFiles.listFiles(Property
-				.get("PATH_TO_LANGUAGE_FILES") + "/test", "\\.properties$");
 		
-		for (File langFile : languageFiles) {
-			Language.addLanguageFile(langFile);
-			
-		}
 		
 		TemplateHelper.init();
 		
@@ -260,7 +255,7 @@
 				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "value"));
 		
 		// Initialize OutputFactory
-		OutputFactory.setPropertiesSpecialFormaters(Property.getProps("specialFormaters.properties"));
+		//OutputFactory.setPropertiesSpecialFormaters(Property.getProps("specialFormaters.properties"));
 		
 		//WADLUnmarshallerXPath.init();
 		//RDFUnmarshallerJena.init();
@@ -425,6 +420,66 @@
 			outputLang.add((listFD[i].getName().split("_"))[0]);
 		}
 
+		
+		
+		
+		// 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"));
+		
+		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");
+		} 
+		
+		File[] languageFiles = ListFiles.listFiles(Property
+				.get("PATH_TO_LANGUAGE_FILES"), "\\.properties$");
+		
+		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.");
+			else {
+				Properties props = new Properties();
+				props.load(langFile.toURI().toURL().openStream());
+				props.put("lang", localeString);
+				props.put("tasklist", mapOfTask);
+				languageProperties.put(localeString, props);
+				logger.debug("Added language file: " + localeString + " - " + props.getProperty("language"));
+			}
+		}
+		//for (String locale : languageProperties.keySet()) {
+		//	logger.error(locale + " - " + languageProperties.get(locale));
+		//}
+		
+		// Creating velocity contexts
+		for (String locale : languageProperties.keySet()) {
+			VelocityContext context = new VelocityContext();
+			Properties langProps = languageProperties.get(locale);
+			for (Object key : langProps.keySet()) {
+		    	context.put((String) key, langProps.get(key));
+		    }
+			context.put("tasklist", mapOfTask);
+			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));
+		//}
+		
+		// Creating velocity engine
+		velocityEngine = new VelocityEngine();
+		Properties aProperties = Property.getProps("velocity.properties");
+		aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
+				.get("PATH_TO_TEMPLATES"));
+		velocityEngine.init(aProperties);
+		
+		// Creating velocity templates
+		velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
+		//velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
+		
+		
 		Framework.logger.info("End of initialisation of UniCORN.");
 		isUcnInitialized = true;
 	}
@@ -432,4 +487,18 @@
 	public static Hashtable<String, Properties> getUnicornPropertiesFiles() {
 		return unicornPropertiesFiles;
 	}
+
+	public static Hashtable<String, VelocityContext> getLanguageContexts() {
+		return languageContexts;
+	}
+
+	public static VelocityEngine getVelocityEngine() {
+		return velocityEngine;
+	}
+
+	public static Template getTemplate(String name) {
+		return velocityTemplates.get(name);
+	}
+	
+	
 }
Received on Thursday, 13 August 2009 13:42:57 UTC

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