Example #1
0
        /// ---------------------------------------------------------------------------------------
        /// <summary>Constructs a list of IMDIListItems that can be used as the data source of a
        /// combo or list box</summary>
        /// <param name="listName">Name of the XML file that contains the desired list. It is suggested to
        ///     use values from IMDI_Schema.ListTypes class. If not found on the local system, we will attempt
        ///     to download from http://www.mpi.nl/IMDI/Schema.
        /// </param>
        /// <param name="uppercaseFirstCharacter">Make first character of each item uppercase</param>
        /// <param name="removeUnknown">Specify which values of "unknown" to remove</param>
        internal IMDIItemList(string listName, bool uppercaseFirstCharacter, ListConstructor.RemoveUnknown removeUnknown)
        {
            Debug.Assert(listName.EndsWith(".xml"));
            _listname = listName.Substring(0, listName.Length - 4);

            PopulateList(GetNodeList(listName), uppercaseFirstCharacter, removeUnknown);

            InitializeThis();
        }
Example #2
0
        /// ---------------------------------------------------------------------------------------
        /// <summary>Constructs a list of IMDIListItems that can be used as the data source of a
        /// combo or list box</summary>
        /// <param name="listName">Name of the XML file that contains the desired list. It is suggested to
        ///     use values from IMDI_Schema.ListTypes class. If not found on the local system, we will attempt
        ///     to download from http://www.mpi.nl/IMDI/Schema.
        /// </param>
        /// <param name="uppercaseFirstCharacter">Make first character of each item uppercase</param>
        /// <param name="removeUnknown">Specify which values of "unknown" to remove</param>
        internal IMDIItemList(string listName, bool uppercaseFirstCharacter, ListConstructor.RemoveUnknown removeUnknown)
        {
            Debug.Assert(listName.EndsWith(".xml"));
            _listname = listName.Substring(0, listName.Length - 4);

            if (listName == "MPI-Languages.xml")
            {
                // This file is woefully incomplete (only ~345 languages, less than 5% of the total).  A comment inside it even says
                // "When a language name and identifier that you need is not in this list, please look it up under www.ethnologue.com/web.asp.".
                // So we use the information from SIL.WritingSystems, which is based on the complete Ethnologue data.
                AddLanguagesFromEthnologue();
            }
            else
            {
                PopulateList(GetNodeList(listName), uppercaseFirstCharacter, removeUnknown);
            }
            InitializeThis();
        }
Example #3
0
        /// ---------------------------------------------------------------------------------------
        protected void PopulateList(XmlNodeList nodes, bool uppercaseFirstCharacter, ListConstructor.RemoveUnknown removeUnknown)
        {
            foreach (XmlNode node in nodes)
            {
                if (node.Attributes == null)
                {
                    continue;
                }

                var value = node.Attributes["Value"].Value;                 // the "Value" attribute contains the meta-data value to save

                switch (value.ToLower())
                {
                case "unknown":
                    if (removeUnknown == ListConstructor.RemoveUnknown.RemoveAll)
                    {
                        continue;
                    }
                    break;

                case "unspecified":
                case "undetermined":
                case "undefined":
                    if (removeUnknown != ListConstructor.RemoveUnknown.RemoveNone)
                    {
                        continue;
                    }
                    break;
                }

                var definition = node.InnerText.Replace("Definition:", "").Replace("\t", " ").Replace("\r", "").Replace("\n", " ").Trim();                  // if InnerText is set, it may contain the value for the meta-data file (some files do, some don't)

                if (uppercaseFirstCharacter && !string.IsNullOrEmpty(value) &&
                    (value.Substring(0, 1) != value.Substring(0, 1).ToUpper()))
                {
                    value = value.ToUpperFirstLetter();
                }

                AddItem(value, definition);
            }
        }