GetAttributeValue() public static method

public static GetAttributeValue ( XmlElement elt, string name ) : string
elt System.Xml.XmlElement
name string
return string
        /// <summary>
        /// We stick various classes on editable things to control order and visibility
        /// </summary>
        public static void UpdateContentLanguageClasses(XmlNode elementOrDom, BookData bookData,
                                                        string language1IsoCode, string language2IsoCode, string language3IsoCode)
        {
            var multilingualClass = "bloom-monolingual";
            var contentLanguages  = new Dictionary <string, string>();

            contentLanguages.Add(language1IsoCode, "bloom-content1");

            if (!String.IsNullOrEmpty(language2IsoCode) && language1IsoCode != language2IsoCode)
            {
                multilingualClass = "bloom-bilingual";
                contentLanguages.Add(language2IsoCode, "bloom-content2");
            }
            if (!String.IsNullOrEmpty(language3IsoCode) && language1IsoCode != language3IsoCode &&
                language2IsoCode != language3IsoCode)
            {
                multilingualClass = "bloom-trilingual";
                contentLanguages.Add(language3IsoCode, "bloom-content3");
                Debug.Assert(!String.IsNullOrEmpty(language2IsoCode), "shouldn't have a content3 lang with no content2 lang");
            }

            //Stick a class in the page div telling the stylesheet how many languages we are displaying (only makes sense for content pages, in Jan 2012).
            foreach (
                XmlElement pageDiv in
                elementOrDom.SafeSelectNodes(
                    "descendant-or-self::div[contains(@class,'bloom-page') and not(contains(@class,'bloom-frontMatter')) and not(contains(@class,'bloom-backMatter'))]")
                )
            {
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-monolingual");
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-bilingual");
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-trilingual");
                HtmlDom.AddClassIfMissing(pageDiv, multilingualClass);
            }


            // This is the "code" part of the visibility system: https://goo.gl/EgnSJo
            foreach (XmlElement group in GetTranslationGroups(elementOrDom))
            {
                var dataDefaultLanguages = HtmlDom.GetAttributeValue(@group, "data-default-languages").Split(new char[] { ',', ' ' },
                                                                                                             StringSplitOptions.RemoveEmptyEntries);

                //nb: we don't necessarily care that a div is editable or not
                foreach (XmlElement e in @group.SafeSelectNodes(".//textarea | .//div"))
                {
                    UpdateContentLanguageClassesOnElement(e, contentLanguages, bookData, language2IsoCode, language3IsoCode, dataDefaultLanguages);
                }
            }

            // Also correct bloom-contentX fields in the bloomDataDiv, which are not listed under translation groups
            foreach (XmlElement coverImageDescription in elementOrDom.SafeSelectNodes(".//*[@id='bloomDataDiv']/*[@data-book='coverImageDescription']"))
            {
                string[] dataDefaultLanguages = new string[] { " auto" };                       // bloomDataDiv contents don't have dataDefaultLanguages on them, so just go with "auto"
                //nb: we don't necessarily care that a div is editable or not
                foreach (XmlElement e in coverImageDescription.SafeSelectNodes(".//textarea | .//div"))
                {
                    UpdateContentLanguageClassesOnElement(e, contentLanguages, bookData, language2IsoCode, language3IsoCode, dataDefaultLanguages);
                }
            }
        }
        /// <summary>
        /// We stick 'contentLanguage2' and 'contentLanguage3' classes on editable things in bilingual and trilingual books
        /// </summary>
        public static void UpdateContentLanguageClasses(XmlNode elementOrDom, CollectionSettings settings,
                                                        string vernacularIso, string contentLanguageIso2, string contentLanguageIso3)
        {
            var multilingualClass = "bloom-monolingual";
            var contentLanguages  = new Dictionary <string, string>();

            contentLanguages.Add(vernacularIso, "bloom-content1");

            if (!String.IsNullOrEmpty(contentLanguageIso2) && vernacularIso != contentLanguageIso2)
            {
                multilingualClass = "bloom-bilingual";
                contentLanguages.Add(contentLanguageIso2, "bloom-content2");
            }
            if (!String.IsNullOrEmpty(contentLanguageIso3) && vernacularIso != contentLanguageIso3 &&
                contentLanguageIso2 != contentLanguageIso3)
            {
                multilingualClass = "bloom-trilingual";
                contentLanguages.Add(contentLanguageIso3, "bloom-content3");
                Debug.Assert(!String.IsNullOrEmpty(contentLanguageIso2), "shouldn't have a content3 lang with no content2 lang");
            }

            //Stick a class in the page div telling the stylesheet how many languages we are displaying (only makes sense for content pages, in Jan 2012).
            foreach (
                XmlElement pageDiv in
                elementOrDom.SafeSelectNodes(
                    "descendant-or-self::div[contains(@class,'bloom-page') and not(contains(@class,'bloom-frontMatter')) and not(contains(@class,'bloom-backMatter'))]")
                )
            {
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-monolingual");
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-bilingual");
                HtmlDom.RemoveClassesBeginingWith(pageDiv, "bloom-trilingual");
                HtmlDom.AddClassIfMissing(pageDiv, multilingualClass);
            }


            // This is the "code" part of the visibility system: https://goo.gl/EgnSJo
            foreach (XmlElement group in elementOrDom.SafeSelectNodes(".//*[contains(@class,'bloom-translationGroup')]"))
            {
                var dataDefaultLanguages = HtmlDom.GetAttributeValue(group, "data-default-languages").Split(new char[] { ',', ' ' },
                                                                                                            StringSplitOptions.RemoveEmptyEntries);

                //nb: we don't necessarily care that a div is editable or not
                foreach (XmlElement e in @group.SafeSelectNodes(".//textarea | .//div"))
                {
                    HtmlDom.RemoveClassesBeginingWith(e, "bloom-content");
                    var lang = e.GetAttribute("lang");

                    //These bloom-content* classes are used by some stylesheet rules, primarily to boost the font-size of some languages.
                    //Enhance: this is too complex; the semantics of these overlap with each other and with bloom-visibility-code-on, and with data-language-order.
                    //It would be better to have non-overlapping things; 1 for order, 1 for visibility, one for the lang's role in this collection.
                    string orderClass;
                    if (contentLanguages.TryGetValue(lang, out orderClass))
                    {
                        HtmlDom.AddClass(e, orderClass);                         //bloom-content1, bloom-content2, bloom-content3
                    }

                    //Enhance: it's even more likely that we can get rid of these by replacing them with bloom-content2, bloom-content3
                    if (lang == settings.Language2Iso639Code)
                    {
                        HtmlDom.AddClass(e, "bloom-contentNational1");
                    }
                    if (lang == settings.Language3Iso639Code)
                    {
                        HtmlDom.AddClass(e, "bloom-contentNational2");
                    }

                    HtmlDom.RemoveClassesBeginingWith(e, "bloom-visibility-code");
                    if (ShouldNormallyShowEditable(lang, dataDefaultLanguages, contentLanguageIso2, contentLanguageIso3, settings))
                    {
                        HtmlDom.AddClass(e, "bloom-visibility-code-on");
                    }

                    UpdateRightToLeftSetting(settings, e, lang);
                }
            }
        }