2006/unicorn/src/org/w3c/unicorn Framework.java,1.1.2.5,1.1.2.6

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn
In directory hutz:/tmp/cvs-serv15822/src/org/w3c/unicorn

Modified Files:
      Tag: dev2
	Framework.java 
Log Message:
new logs, new initialization actions

Index: Framework.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Attic/Framework.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -d -r1.1.2.5 -r1.1.2.6
--- Framework.java	13 Aug 2009 17:28:34 -0000	1.1.2.5
+++ Framework.java	17 Aug 2009 09:11:09 -0000	1.1.2.6
@@ -22,9 +22,11 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.Map.Entry;
 import javax.xml.namespace.NamespaceContext;
-import org.apache.log4j.Logger;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
@@ -46,6 +48,8 @@
 import org.w3c.unicorn.util.TemplateHelper;
 import org.w3c.unicorn.util.UCNProperties;
 
+import com.hp.hpl.jena.rdf.model.Model;
+
 /**
  * Main class of the central module of UniCORN.
  * 
@@ -64,11 +68,6 @@
 	public static Map<String, Task> mapOfTask = null;
 
 	/**
-	 * Properties of the framework
-	 */
-	//public static Properties aPropertiesExtension;
-
-	/**
 	 * List of available output languages in PATH_TO_OUTPUT_TEMPLATES
 	 */
 	public static Set<String> outputLang;
@@ -79,9 +78,9 @@
 	public static Map<String, ResponseParser> mapOfReponseParser = null;
 	
 	/**
-	 * Log4j Logger
+	 * Logger
 	 */
-	public static Logger logger;
+	public static Log logger = LogFactory.getLog("Framework");
 	
 	/**
 	 * URI to unicorn home
@@ -97,108 +96,100 @@
 	private static Hashtable<String, Properties> languageProperties;
 	private static VelocityEngine velocityEngine;
 	private static Hashtable<String, Template> velocityTemplates;
-	
+	private static String[] mandatoryProperties = {
+		"PATH_TO_CONF_FILES",
+		"PATH_TO_CACHE"};
+	private static String[] configFiles = {
+		"extensions.properties",
+		"responseParsers.properties",
+		"specialFormaters.properties",
+		"velocity.properties"};
+
 	/**
 	 * Initialize Unicorn
-	 * @throws Exception 
 	 */
-	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>();
 		velocityTemplates = new Hashtable<String, Template>();
+		mapOfObserver = new LinkedHashMap<String, Observer>();
+		mapOfReponseParser = new LinkedHashMap<String, ResponseParser>();
 		
 		// Checks that unicorn.home (JVM parameter) is set to an existing directory
 		String ucnHome = System.getProperty("unicorn.home");
-		System.err.println(ucnHome);
-		File ucnHomeFile = new File(ucnHome);
 		if (ucnHome == null) {
-			String error = "ERROR: \"unicorn.home\" is not set in the JVM parameters. Please read the README file before trying to install Unicorn";
-			System.err.println(error);
-			throw new Exception(error);
-		} else if (!ucnHomeFile.exists() && ucnHomeFile.isDirectory()) {
-			String error = "ERROR: \"unicorn.home\" is not an existing directory: " + System.getProperty("unicorn.home");
-			System.err.println(error);
-			throw new Exception(error);
+			String fatal = "\"unicorn.home\" is not set in the JVM parameters. Please read the README file before trying to install Unicorn";
+			System.err.println("FATAL: " + fatal);
+			logger.fatal(fatal);
+			return;
 		} else {
-			unicornHome = ucnHomeFile.toURI();
-			System.out.println("OK - \"unicorn.home\" was found: " + unicornHome.getPath());
+			File ucnHomeFile = new File(ucnHome);
+			if (!ucnHomeFile.exists() || !ucnHomeFile.isDirectory()) {
+				String fatal = "JVM parameter \"unicorn.home\" is not an existing directory: " + System.getProperty("unicorn.home");
+				System.err.println("FATAL: " + fatal);
+				logger.fatal(fatal);
+				return;
+			} else {
+				unicornHome = ucnHomeFile.toURI();
+				logger.info("OK - JVM parameter \"unicorn.home\" was found: " + unicornHome.getPath());
+			}
 		}
 		
 		// Log4j initialization attempt
 		String log4jPath = unicornHome.getPath() + "/WEB-INF/conf/log4j.properties";
-		File log4jPropFile = new File(log4jPath);
-		if (!log4jPropFile.exists()) {
-			String error = "WARN: \"log4j.properties\" could not be found: " + log4jPath;
-			System.err.println(error);
-			System.err.println("WARN: Log4j will not be initialized.");
-		} else {
-			System.out.println("OK - Log4j initialized with file: " + log4jPath);
-			PropertyConfigurator.configure(log4jPropFile.toURI().toURL());
-			logger = Logger.getLogger("Framework");
-			logger.info("Unicorn home directory was found");
-			logger.debug("Unicorn home path = " + unicornHome.getPath());
-			logger.info("Log4j has been successfully initialized");
-			logger.debug("Log4j properties file = " + log4jPropFile.toURI().getPath());
+		try {
+			loadConfigFile(log4jPath, true);
+			PropertyConfigurator.configure(unicornPropertiesFiles.get("log4j.properties"));
+			logger.info("OK - JVM parameter \"unicorn.home\" was found: " + unicornHome.getPath());
+			logger.info("OK - Log4j successfully initialized");
+			logger.debug("> Used log4j.properties file: " + log4jPath);
+		} catch (FileNotFoundException e) {
+			logger.warn("Log4j config file \"log4j.properties\" could not be found: " + log4jPath);
+			logger.warn("Log4j will not be initialized");
+		} catch (IOException e) {
+			logger.error("Error reading \"log4j.properties\": ", e);
+			logger.warn("Log4j will not be initialized");
 		}
 		
-		// Loading unicorn.properties
-		logger.debug("Loading unicorn.properties");		
+		// Load unicorn.properties	
+		logger.debug("-------------------------------------------------------");
 		String unicornPath = unicornHome.getPath() + "/WEB-INF/conf/unicorn.properties";
-		logger.debug("Unicorn properties file = " + unicornPath);
-		File unicornPropFile = new File(unicornPath);
-		if (!unicornPropFile.exists()) {
-			String error = "ERROR: \"unicorn.properties\" could not be found: " + unicornPath;
-			System.err.println(error);
-			logger.error("Unicorn properties file does not exists! Path is: " + unicornPath);
-			throw new Exception(error);
-		} else {
-			UCNProperties ucnProperties = new UCNProperties();
-			ucnProperties.put("UNICORN_HOME", unicornHome.getPath());
-			ucnProperties.load(unicornPropFile.toURI().toURL().openStream());
-			unicornPropertiesFiles.put("unicorn.properties", ucnProperties);
-			//Property.setUnicornProps(ucnProperties);
-			logger.info("Unicorn properties file successfully loaded");
-			logger.debug("Loaded properties: " + ucnProperties);
+		try {
+			loadConfigFile(unicornPath, true);
+			logger.info("OK - Config file unicorn.properties successfully loaded");
+		} catch (FileNotFoundException e) {
+			logger.fatal("Unicorn config file \"unicorn.properties\" could not be found: " + unicornPath);
+			return;
+		} catch (IOException e) {
+			logger.fatal("Error reading \"unicorn.properties\": ", e);
+			return;
 		}
 		
-		// Checking Unicorn properties
-		String[] mandatoryProperties = {"PATH_TO_CONF_FILES","ROUTE_XML","PATH_TO_CACHE"};
-		for (String property: mandatoryProperties) {
+		// Checking that mandatory properties are set in unicorn.properties
+		for (String property : mandatoryProperties) {
 			if (Property.get(property) == null) {
-				String error = "\""+ property +"\" is not defined in unicorn.properties. This property is mandatory.";
-				logger.error(error);
-				throw new Exception(error);
+				logger.fatal("\""+ property +"\" is not defined in unicorn.properties. This property is mandatory.");
+				return;
 			}
 		}
-		
+
 		// Loading config files
-		String[] propertyFiles = {"extensions.properties", "responseParsers.properties", "specialFormaters.properties", "velocity.properties"};
-		for (String fileName : propertyFiles) {
-			logger.debug("Loading " + fileName);	
+		for (String fileName : configFiles) {
 			String path = Property.get("PATH_TO_CONF_FILES") + fileName;
-			logger.debug(fileName + " path = " + path);
-			File file = new File(path);
-			if (!file.exists()) {
-				String error = "ERROR: \"" + fileName + "\" could not be found: " + path;
-				System.err.println(error);
-				logger.error(fileName + " file does not exists! Path is: " + path);
-				throw new Exception(error);
-			} else {
-				Properties properties = new Properties();
-				properties.load(file.toURI().toURL().openStream());
-				unicornPropertiesFiles.put(fileName, properties);
-				logger.info(fileName + " file successfully loaded");
-				logger.debug("Loaded properties: " + properties);
+			logger.debug("-------------------------------------------------------");
+			try {
+				loadConfigFile(path, false);
+				logger.info("OK - Config file " + fileName + " successfully loaded");
+			} catch (FileNotFoundException e) {
+				logger.fatal("Mandatory config file \"" + fileName + "\" could not be found: " + path);
+				return;
+			} catch (IOException e) {
+				logger.fatal("Error reading \"" + fileName + "\": ", e);
+				return;
 			}
 		}
 		
-		
-		
-		
-		
-		TemplateHelper.init();
-		
 		// Initialize WADLUnmarshallerXPath (Gets the Namespace URI and the prefix)
 		WADLUnmarshallerXPath.setNamespaceContext(new NamespaceContext() {
 			public String getNamespaceURI(final String sPrefix) {
@@ -225,199 +216,186 @@
 			}
 		});
 		
-		
 		// Initialize RDFUnmarshallerJena
-		FileInputStream fis = new FileInputStream(org.w3c.unicorn.util.Property
-				.get("TASKLIST_RDF_MODEL"));
-		RDFUnmarshallerJena.getModel().read(fis, null);
-		
-		/*FileReader fr = new FileReader(org.w3c.unicorn.util.Property
-				.get("TASKLIST_RDF_MODEL"));
-
-		
-
-		RDFUnmarshallerJena.getModel().read(fr, null);*/
+		logger.debug("-------------------------------------------------------");
+		logger.debug("Initializing RDFUnmarshallerJena");
+		try {
+			FileInputStream fis = new FileInputStream(Property.get("TASKLIST_RDF_MODEL"));
+			RDFUnmarshallerJena.getModel().read(fis, null);
+			logger.debug("> Used model: " + Property.get("TASKLIST_RDF_MODEL"));
+		} catch (FileNotFoundException e) {
+			logger.fatal("The tasklist rdf model could not be found: " + Property.get("TASKLIST_RDF_MODEL"));
+			return;
+		}
+		Model model = RDFUnmarshallerJena.getModel();
+		String namespace = RDFUnmarshallerJena.getUcnNamespace();
 		// define resource use to find information into the RDF graph
-		RDFUnmarshallerJena.setRESOURCE_TASK(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "Task"));
+		RDFUnmarshallerJena.setRESOURCE_TASK(model.getProperty(
+				namespace + "Task"));
 		// define property use to find information into the RDF graph
-		RDFUnmarshallerJena.setPROPERTY_DESCRIPTION(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "description"));
-		RDFUnmarshallerJena.setPROPERTY_HASMAPPING(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasMapping"));
-		RDFUnmarshallerJena.setPROPERTY_HASPARAMETER(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasParameter"));
-		RDFUnmarshallerJena.setPROPERTY_HASVALUE(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasValue"));
-		RDFUnmarshallerJena.setPROPERTY_LONGNAME(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "longName"));
-		RDFUnmarshallerJena.setPROPERTY_OBSERVER(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "observer"));
-		RDFUnmarshallerJena.setPROPERTY_PARAMETER(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "parameter"));
-		RDFUnmarshallerJena.setPROPERTY_REFERENCE(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "reference"));
-		RDFUnmarshallerJena.setPROPERTY_TYPE(RDFUnmarshallerJena.getModel()
-				.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
-		RDFUnmarshallerJena.setPROPERTY_VALUE(RDFUnmarshallerJena.getModel()
-				.getProperty(RDFUnmarshallerJena.getUcnNamespace() + "value"));
-		
-		// Initialize OutputFactory
-		//OutputFactory.setPropertiesSpecialFormaters(Property.getProps("specialFormaters.properties"));
-		
-		//WADLUnmarshallerXPath.init();
-		//RDFUnmarshallerJena.init();
-		//Framework.init();
-		//OutputFactory.init();
-		//IndexGenerator.init();
-			
-		//Framework.aPropertiesExtension = Property.getProps("extensions.properties");
+		RDFUnmarshallerJena.setPROPERTY_DESCRIPTION(model.getProperty(
+				namespace + "description"));
+		RDFUnmarshallerJena.setPROPERTY_HASMAPPING(model.getProperty(
+				namespace + "hasMapping"));
+		RDFUnmarshallerJena.setPROPERTY_HASPARAMETER(model.getProperty(
+				namespace + "hasParameter"));
+		RDFUnmarshallerJena.setPROPERTY_HASVALUE(model.getProperty(
+				namespace + "hasValue"));
+		RDFUnmarshallerJena.setPROPERTY_LONGNAME(model.getProperty(
+				namespace + "longName"));
+		RDFUnmarshallerJena.setPROPERTY_OBSERVER(model.getProperty(
+				namespace + "observer"));
+		RDFUnmarshallerJena.setPROPERTY_PARAMETER(model.getProperty(
+				namespace + "parameter"));
+		RDFUnmarshallerJena.setPROPERTY_REFERENCE(model.getProperty(
+				namespace + "reference"));
+		RDFUnmarshallerJena.setPROPERTY_TYPE(model.getProperty(
+				"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
+		RDFUnmarshallerJena.setPROPERTY_VALUE(model.getProperty(
+				namespace + "value"));
+		logger.info("OK - RDFUnmarshallerJena successfully initialized.");
 		
-	    //Load the map of ResponseParser
-	 
-		if (Framework.logger.isDebugEnabled()) {
-			Framework.logger.debug("Loading available parsers...");
-		}
-		try {
-			// Retrieve the properties of the response parsers in the resources
-			mapOfReponseParser = new LinkedHashMap<String, ResponseParser>();
-
-			Properties aProperties = Property.getProps("responseParsers.properties");
-
-			for (Entry<Object, Object> e : aProperties.entrySet()) {
-				ResponseParser aResponseParser = (ResponseParser) (Class
-						.forName((String) (e.getValue())).newInstance());
-				mapOfReponseParser.put((String) (e.getKey()), aResponseParser);
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		} finally {
-			if (Framework.logger.isDebugEnabled()) {
-				Framework.logger.debug("... Parsers loaded");
+	    // Load the map of ResponseParser
+		logger.debug("-------------------------------------------------------");
+		logger.debug("Loading available parsers form responseParsers.properties");
+		Properties aProperties = Property.getProps("responseParsers.properties");
+		for (Object key : aProperties.keySet()) {
+			String className = aProperties.getProperty(key.toString());
+			try {
+				ResponseParser aResponseParser = (ResponseParser) Class
+					.forName(className).newInstance();
+				mapOfReponseParser.put(key.toString(), aResponseParser);
+				logger.debug("> Parser loaded: " + mapOfReponseParser.get(key).getClass().toString());
+			} catch (ClassNotFoundException e) {
+				logger.warn("Class not found: " + className + ". Check responseParsers.properties.", e);
+			} catch (Exception e) {
+				logger.warn("Error trying to instanciate: " + className, e);
 			}
 		}
-
-		// Static operations to initialize framework the first time this class is used.
-		if (Framework.logger.isDebugEnabled()) {
-			Framework.logger.debug("Loading available observers...");
-		}
-		final String sLanguage = Property.get("DEFAULT_LANGUAGE");
-		if (null != sLanguage) {
-			LocalizedString.DEFAULT_LANGUAGE = sLanguage;
+		if (mapOfReponseParser.size() == 0) {
+			logger.fatal("There is no parser loaded. Check responseParsers.properties.");
+			return;
+		} else {
+			logger.info("OK - " + mapOfReponseParser.size() + " parser(s) successfully loaded.");
 		}
-		Framework.mapOfObserver = new LinkedHashMap<String, Observer>();
-		try {
-			// Add all observer contract
-			final BufferedReader aBufferedReader;
-
-			aBufferedReader = new BufferedReader(new FileReader(Property
-					.get("OBSERVER_LIST_FILE")));
-
-			// Observer list file contains URL contracts of observers
-			for (String sReadLine = aBufferedReader.readLine(); null != sReadLine; sReadLine = aBufferedReader
-					.readLine()) {
-
-				if ("".equals(sReadLine.trim())) {
-					continue;
-				}
 
-				// Get URL of the contract. If the name of wadl file is not
-				// defined, the contract's name will be observer.wadl
-				final String sWADL;
-				if (sReadLine.matches(".*\\.wadl$")) {
-					sWADL = sReadLine;
-				} else {
-					sWADL = sReadLine + "/"
-							+ Property.get("OBSERVER_XML_FILENAME");
-				}
-
-				try {
-					if (Framework.logger.isDebugEnabled()) {
-						Framework.logger.debug("Observer WADL file : " + sWADL
-								+ ".");
-					}
-					// Create each observer
-					final Observer aObserver = new Observer();
-					final WADLUnmarshaller aWADLUnmarshaller = new WADLUnmarshallerXPath();
-					aWADLUnmarshaller.addURL(new URL(sWADL));
-					aWADLUnmarshaller.unmarshal();
-
-					aObserver.setListOfCallMethod(aWADLUnmarshaller
-							.getListOfCallMethod());
-					aObserver.setParamLangName(aWADLUnmarshaller
-							.getNameOfLangParameter());
-					aObserver.setID(aWADLUnmarshaller.getID());
-					aObserver.setName(aWADLUnmarshaller.getName());
-					aObserver
-							.setDescription(aWADLUnmarshaller.getDescription());
-					aObserver.setHelpLocation(aWADLUnmarshaller
-							.getHelpLocation());
-					aObserver.setProvider(aWADLUnmarshaller.getProvider());
-					aObserver.setMapOfInputMethod(aWADLUnmarshaller
-							.getMapOfInputMethod());
-					aObserver.setResponseType(aWADLUnmarshaller
-							.getResponseType());
-					aObserver.setSupportedMimeTypes(aWADLUnmarshaller
-							.getSupportedMimeTypes());
-					Framework.mapOfObserver.put(new String(aObserver.getID()),
-							aObserver);
-				} catch (final Exception e) {
-					Framework.logger.error("Exception : " + e.getMessage(), e);
-					e.printStackTrace();
-				}
+		// 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")));
+			logger.debug("Using file: " + Property.get("OBSERVER_LIST_FILE"));
+		} catch (FileNotFoundException e) {
+			logger.fatal("The list of observers could not be found: " + Property.get("OBSERVER_LIST_FILE"));
+			return;
+		}
+		String readLine;
+		do {
+			try {
+				readLine = aBufferedReader.readLine();
+				if (readLine == null)
+					break;
+			} catch (IOException e) {
+				logger.fatal("Error while reading the observer list file", e);
+				return;
 			}
-			if (Framework.logger.isDebugEnabled()) {
-				Framework.logger.debug("... Observers loaded.");
+			if ("".equals(readLine.trim()))
+				continue;
+			String sWADL = readLine;
+			if (!readLine.matches(".*\\.wadl$")) {
+				sWADL += "/" + Property.get("OBSERVER_XML_FILENAME");
 			}
-		} catch (final FileNotFoundException aFileNotFoundException) {
-			Framework.logger.error("FileNotFoundException : "
-					+ aFileNotFoundException.getMessage(),
-					aFileNotFoundException);
-			aFileNotFoundException.printStackTrace();
-		}
-
-		catch (final IOException ioe) {
-			Framework.logger.error("IOException : " + ioe.getMessage(), ioe);
-			ioe.printStackTrace();
-		}
-
-		if (Framework.logger.isDebugEnabled()) {
-			Framework.logger.debug("Task initialisation.");
+			logger.debug("> Loading observer contract: " + sWADL);
+			Observer obs = new Observer();
+			WADLUnmarshaller unmarshaller;
+			try {
+				unmarshaller = new WADLUnmarshallerXPath();
+				unmarshaller.addURL(new URL(sWADL));
+				unmarshaller.unmarshal();
+			} catch (MalformedURLException e) {
+				logger.error("Invalid observer contract URL \"" + sWADL + "\". Check the observers list file.");
+				logger.warn("> This observer will be skiped");
+				continue;
+			} catch (ParserConfigurationException e) {
+				logger.fatal(e.getMessage(), e);
+				return;
+			} catch (IOException e) {
+				logger.error("Unable to read observer contract: " + sWADL, e);
+				logger.warn("> This observer will be skiped");
+				continue;
+			} catch (Exception e) {
+				logger.error("Error unmarshalling contract: " + sWADL, e);
+				logger.warn("> This observer will be skiped");
+				continue;
+			}
+			obs.setListOfCallMethod(unmarshaller.getListOfCallMethod());
+			obs.setParamLangName(unmarshaller.getNameOfLangParameter());
+			obs.setID(unmarshaller.getID());
+			obs.setName(unmarshaller.getName());
+			obs.setDescription(unmarshaller.getDescription());
+			obs.setHelpLocation(unmarshaller.getHelpLocation());
+			obs.setProvider(unmarshaller.getProvider());
+			obs.setMapOfInputMethod(unmarshaller.getMapOfInputMethod());
+			obs.setResponseType(unmarshaller.getResponseType());
+			obs.setSupportedMimeTypes(unmarshaller.getSupportedMimeTypes());
+			mapOfObserver.put(new String(obs.getID()), obs);
+		} while (readLine != null);
+		if (mapOfObserver.size() == 0) {
+			logger.fatal("There is no observer loaded. Check the observers list file.");
+			return;
+		} else {
+			logger.info("OK - " + mapOfObserver.size() + " observer(s) successfully loaded.");
 		}
-		try {
-			// parse all the task files
-			final File[] tFileXML = ListFiles.listFiles(Property
-					.get("PATH_TO_TASKLIST"), "\\.xml$");
-
-			final TasksListUnmarshaller aTaskListUnmarshaller = new TaskListUnmarshallerBeans(
-					Framework.mapOfObserver);
-			for (final File aFile : tFileXML) {
+		
+		logger.debug("-------------------------------------------------------");
+		logger.debug("Loading task files from tasklist directory: " + Property.get("PATH_TO_TASKLIST"));
+		TasksListUnmarshaller aTaskListUnmarshaller = new TaskListUnmarshallerBeans(mapOfObserver);
+		File[] tFileXML = ListFiles.listFiles(Property.get("PATH_TO_TASKLIST"), "\\.xml$");
+		for (File aFile : tFileXML) {
+			try {
 				aTaskListUnmarshaller.addURL(aFile.toURI().toURL());
+				aTaskListUnmarshaller.unmarshal();
+			} catch (MalformedURLException e) {
+				logger.error(e.getMessage(), e);
+			} catch (IOException e) {
+				logger.error("Error reading file: " + aFile.getName(), e);
+				logger.warn("> This task file will be skiped");
+			} catch (Exception e) {
+				logger.error("Error unmarshalling file: " + aFile.getName(), e);
+				logger.warn("> This task file will be skiped");
 			}
-			aTaskListUnmarshaller.unmarshal();
-
-			final File[] tFileRDF = ListFiles.listFiles(Property
-					.get("PATH_TO_TASKLIST"), "\\.rdf$");
-			final RDFUnmarshaller aRDFUnmarshaller = new RDFUnmarshallerJena();
-			aRDFUnmarshaller.setMapOfTask(aTaskListUnmarshaller.getMapOfTask());
-			aRDFUnmarshaller.setMapOfObserver(Framework.mapOfObserver);
-			for (final File aFile : tFileRDF) {
+		}
+		File[] tFileRDF = ListFiles.listFiles(Property.get("PATH_TO_TASKLIST"), "\\.rdf$");
+		RDFUnmarshaller aRDFUnmarshaller = new RDFUnmarshallerJena();
+		aRDFUnmarshaller.setMapOfTask(aTaskListUnmarshaller.getMapOfTask());
+		aRDFUnmarshaller.setMapOfObserver(mapOfObserver);
+		for (final File aFile : tFileRDF) {
+			try {
 				aRDFUnmarshaller.addURL(aFile.toURI().toURL());
+				aRDFUnmarshaller.unmarshal();
+			} catch (MalformedURLException e) {
+				logger.error(e.getMessage(), e);
+			} catch (IOException e) {
+				logger.error("Error reading file: " + aFile.getName(), e);
+				logger.warn("> This task file will be skiped");
+			} catch (Exception e) {
+				logger.error("Error unmarshalling file: " + aFile.getName(), e);
+				logger.warn("> This task file will be skiped");
 			}
-			aRDFUnmarshaller.unmarshal();
-
-			Framework.mapOfTask = aTaskListUnmarshaller.getMapOfTask();
-		} catch (final MalformedURLException e) {
-			Framework.logger.error("MalformedURLException : " + e.getMessage(),
-					e);
-			e.printStackTrace();
-		} catch (final Exception e) {
-			Framework.logger.error("Exception : " + e.getMessage(), e);
-			e.printStackTrace();
+		}
+		mapOfTask = aTaskListUnmarshaller.getMapOfTask();
+		if (mapOfTask.size() == 0) {
+			logger.fatal("No task have been loaded. Check task files in: " + Property.get("PATH_TO_TASKLIST"));
+			return;
+		} else {
+			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")))
+		/*File[] listFD = (new File(Property.get("PATH_TO_TEMPLATES")))
 				.listFiles(new FileFilter() {
 					public boolean accept(File pathname) {
 						return pathname.getName().matches(".*\\.vm$");
@@ -426,9 +404,9 @@
 		outputLang = new HashSet<String>();
 		for (int i = 0; i < listFD.length; i++) {
 			outputLang.add((listFD[i].getName().split("_"))[0]);
-		}
+		}*/
 
-		
+		outputLang = new HashSet<String>();
 		
 		
 		// Loading language files
@@ -448,17 +426,16 @@
 			if (!Language.isISOLanguageCode(localeString))
 				logger.warn(langFile.getName() + " is not a language file: " + localeString + " is not a valid locale.");
 			else {
+				FileInputStream fis1 = new FileInputStream(langFile);
+				InputStreamReader os = new InputStreamReader(fis1, "UTF-8");
 				Properties props = new Properties();
-				props.load(langFile.toURI().toURL().openStream());
+				props.load(os);
 				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()) {
@@ -478,20 +455,35 @@
 		
 		// Creating velocity engine
 		velocityEngine = new VelocityEngine();
-		Properties aProperties = Property.getProps("velocity.properties");
-		aProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
+		Properties bProperties = Property.getProps("velocity.properties");
+		bProperties.put(Velocity.FILE_RESOURCE_LOADER_PATH, Property
 				.get("PATH_TO_TEMPLATES"));
-		velocityEngine.init(aProperties);
+		velocityEngine.init(bProperties);
 		
 		// Creating velocity templates
 		velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
 		//velocityTemplates.put("index", velocityEngine.getTemplate("index.vm", "UTF-8"));
 		
+		TemplateHelper.init();
 		
 		Framework.logger.info("End of initialisation of UniCORN.");
 		isUcnInitialized = true;
 	}
 	
+	private static void loadConfigFile(String path, boolean addUnicornHome) throws FileNotFoundException, IOException {		
+		UCNProperties properties = new UCNProperties();
+		File configFile = new File(path);
+		String fileName = configFile.getName();
+		if (fileName != null) {
+			logger.debug("Loading config file: " + fileName);
+			if (addUnicornHome)
+				properties.put("UNICORN_HOME", unicornHome.getPath());
+			properties.load(new FileInputStream(configFile));
+			unicornPropertiesFiles.put(fileName, properties);
+			logger.debug("> " + fileName + ":" + properties);
+		}
+	}
+	
 	public static Hashtable<String, Properties> getUnicornPropertiesFiles() {
 		return unicornPropertiesFiles;
 	}
@@ -511,6 +503,4 @@
 	public static Hashtable<String, Properties> getLanguageProperties() {
 		return languageProperties;
 	}
-	
-	
 }

Received on Monday, 17 August 2009 09:19:07 UTC