Exemplo n.º 1
0
    /// <summary>
    /// Builds the region section
    /// </summary>
    /// <param name="cldrMainXmlPath">The file path to the main CLDR file</param>
    private void BuildRegionSection(string cldrMainXmlPath)
    {
        const string RegionFilenameFormat = "{0}.gif";
        string xsltPath = new Uri(Request.Url, "territoryList.xsl").AbsoluteUri;
        Ektron.Cms.Xslt.ArgumentList args = new Ektron.Cms.Xslt.ArgumentList();
        args.AddParam("controlId", string.Empty, RegionSelector.ClientID);
        args.AddParam("subset", string.Empty, RegionSet.Text);
        args.AddParam("selectedLanguage", string.Empty, this.selectedLanguage);
        if (!String.IsNullOrEmpty(this.selectedLanguageTag.ScriptSubtag))
        {
            args.AddParam("selectedScript", string.Empty, this.selectedLanguageTag.ScriptSubtag);
        }

        if (!String.IsNullOrEmpty(this.selectedLanguageTag.RegionSubtag))
        {
            args.AddParam("selectedTerritory", string.Empty, this.selectedLanguageTag.RegionSubtag);
        }

        args.AddParam("lang", string.Empty, this.userLang);
        RegionSelector.Text = ContentApi.XSLTransform(cldrMainXmlPath, xsltPath, true, true, args, false);

        if (!String.IsNullOrEmpty(this.selectedLanguageTag.RegionSubtag))
        {
            string mapArea = this.GetRegionValue(this.selectedLanguageTag.RegionSubtag, "chtm");
            bool isMultinationalRegion = !String.IsNullOrEmpty(mapArea);
            CountryMap.Visible = isMultinationalRegion;
            LocatorMap.Visible = !isMultinationalRegion;
            if (isMultinationalRegion)
            {
                // Get list of country codes to highlight in CountryMap
                args.Clear();
                args.AddParam("countriesInTree", string.Empty, true);
                args.AddParam("selectedLanguage", string.Empty, this.selectedLanguage);
                if (!String.IsNullOrEmpty(this.selectedLanguageTag.ScriptSubtag))
                {
                    args.AddParam("selectedScript", string.Empty, this.selectedLanguageTag.ScriptSubtag);
                }

                if (!String.IsNullOrEmpty(this.selectedLanguageTag.RegionSubtag))
                {
                    args.AddParam("selectedTerritory", string.Empty, this.selectedLanguageTag.RegionSubtag);
                }

                args.AddParam("lang", string.Empty, this.userLang);
                xsltPath = new Uri(Request.Url, "territoryTree.xsl").AbsoluteUri;
                string regionTree = ContentApi.XSLTransform(cldrMainXmlPath, xsltPath, true, true, args, false);

                System.Xml.XPath.XPathDocument docRegionTree = new System.Xml.XPath.XPathDocument(new System.Xml.XmlTextReader(new System.IO.StringReader(regionTree)));
                System.Xml.XPath.XPathNavigator navRegionTree = docRegionTree.CreateNavigator();
                if (navRegionTree != null)
                {
                    string countryCodesXPath = String.Format("//li[@id='{0}']/descendant-or-self::li[not(ul)]/@id", this.selectedLanguageTag.RegionSubtag);
                    System.Xml.XPath.XPathNodeIterator countryNodes = navRegionTree.Select(countryCodesXPath);
                    if (countryNodes != null)
                    {
                        string[] countryCodes = new string[countryNodes.Count];
                        for (int i = 0; i < countryNodes.Count; i++)
                        {
                            countryNodes.MoveNext();
                            countryCodes[i] = countryNodes.Current.Value;
                        }

                        CountryMap.CountryCodes = countryCodes;
                    }
                }

                // Determine map area to display, e.g., whole world, europe, africa, in CountryMap
                CountryMap.MapArea = controls_reports_CountryMap.GeographicalArea.World;
                if (String.IsNullOrEmpty(mapArea))
                {
                    // Single country regions are handled elsewhere, but this will handle single country regions should the need arise.
                    System.Xml.XPath.XPathNavigator countryNode = navRegionTree.SelectSingleNode(String.Format("//li[@id='{0}']/../../@id", this.selectedLanguageTag.RegionSubtag));
                    if (countryNode != null)
                    {
                        string countryRegion = countryNode.Value;
                        mapArea = this.GetRegionValue(countryRegion, "chtm");
                    }
                }

                controls_reports_CountryMap.GeographicalArea[] areas = (controls_reports_CountryMap.GeographicalArea[])Enum.GetValues(typeof(controls_reports_CountryMap.GeographicalArea));
                foreach (controls_reports_CountryMap.GeographicalArea area in areas)
                {
                    if (mapArea == EnumExtensions.ToDescriptionString(area))
                    {
                        CountryMap.MapArea = area;
                        break; // exit, we found it
                    }
                }
            }
            else
            {
                // Single country
                LocatorMap.ImageUrl = CommonApi.AppImgPath + "locators/" + String.Format(RegionFilenameFormat, this.selectedLanguageTag.RegionSubtag);
            }
        }
    }