////////////////////////////////////////////////////////
public static void ReadKeywordMappings ()
{
property_table = new Hashtable ();
// FIXME: No need for a SerializerFactory here, since we need the serializer
// only once
XmlSerializerFactory xsf = new XmlSerializerFactory();
XmlSerializer xs = xsf.CreateSerializer (typeof (QueryMapping), new Type[] { typeof (QueryKeywordMapping)});
QueryMapping query_mapping = null;
// <keyword name, can override>
Dictionary<string, bool> mapping_override = new Dictionary<string, bool> ();
using (Stream s = File.OpenRead (Path.Combine (PathFinder.ConfigDataDir, "query-mapping.xml"))) {
try {
query_mapping = (QueryMapping) xs.Deserialize (s);
foreach (QueryKeywordMapping mapping in query_mapping.Mappings) {
PropertyKeywordFu.RegisterMapping (mapping);
mapping_override [mapping.Keyword] = true;
}
} catch (XmlException e) {
Logger.Log.Error (e, "Unable to parse global query-mapping.xml");
}
}
// Override global mappings by local mappings
if (! File.Exists (Path.Combine (PathFinder.StorageDir, "query-mapping.xml")))
return;
using (Stream s = File.OpenRead (Path.Combine (PathFinder.StorageDir, "query-mapping.xml"))) {
try {
query_mapping = (QueryMapping) xs.Deserialize (s);
foreach (QueryKeywordMapping mapping in query_mapping.Mappings) {
if (mapping_override.ContainsKey (mapping.Keyword)) {
property_table.Remove (mapping.Keyword);
mapping_override [mapping.Keyword] = false;
}
PropertyKeywordFu.RegisterMapping (mapping);
}
} catch (XmlException e) {
Logger.Log.Error (e, "Unable to parse local query-mapping.xml");
}
}
}