Gets the page on the language as specified by the language selector.

Namespace:  EPiServer.Core
Assembly:  EPiServer (in EPiServer.dll) Version: 5.2.375.236

Syntax

C#
protected abstract PageData GetLocalPage(
	PageReference pageLink,
	ILanguageSelector languageSelector
)

Parameters

pageLink
Type: EPiServer.Core..::.PageReference
The page link.
languageSelector
Type: EPiServer.Core..::.ILanguageSelector
The language selector.

Return Value

The page on the specified language

Remarks

The implementation should not call into SelectPageLanguage(LanguageSelectorContext) or LoadLanguage(LanguageSelectorContext) since that might cause recursive calls back to GetLocalPage. The suggested way to handle language is to call SetInitializedLanguageBranch(LanguageSelectorContext) to get the language the selector was initialized with (if any). And then return that language version or Master language if the selector was not initalized with some specific language.

Examples

The following example shows the suggested way to handle language
CopyC#
LanguageSelectorContext context = new LanguageSelectorContext(pageLink);
languageSelector.SetInitializedLanguageBranch(context);
if (context.SelectedLanguageBranch != null)
{
    //load language given by context.SelectedLanguage
}
else
{
    //load page on masterlanguage
}
The following code sample is an implementation of GetLocalPage() for XmlPageProvider.
CopyC#
protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector selector)
{
    //Get the page node from the XMl file (and also a list of all languages the page exist on)
    List<string> pageLanguages = new List<string>();
    XElement pageNode = GetPageNode(pageLink, selector, out pageLanguages);
    if (pageNode == null)
    {
        throw new PageNotFoundException(pageLink);
    }

    int parentId = int.Parse(pageNode.Attribute("parent").Value);
    //Children to entryPoint is stored with parentId = 0 in backing xml file to avoid hard coupling to EntryPoint id. Meaning
    //we can change entryPoint for provider without having to change in xml file.
    PageReference parentLink = parentId != 0 ? ConstructPageReference(parentId) : EntryPoint;

    Int32 pageTypeId = Int32.Parse(pageNode.Attribute("pagetypeid").Value);
    PageType pageType = PageType.Load(pageTypeId);
    if (pageType == null)
    {
        throw new EPiServerException(string.Format("Failed To Load Page Type with the ID = {0}\r\n Hints:Review the PageType value in the XML Page file {1}", pageTypeId, _filePath));
    }

    //Create a new "custom" PageData object, with security handler setup
    XmlPageData page = new XmlPageData(GetSecurityDescriptor(pageNode, parentLink));

    //We dont send in PageName and PageGUID here, they will be set later in call to SetProperties
    InitializePageData(page, "", pageType.Name, Guid.Empty, pageLink.CreateWritableClone(), parentLink, pageLanguages);

    //Now get all properties from page node and populate PageData object.
    Dictionary<string, string> properties = new Dictionary<string, string>();
    if (pageNode.HasElements)
    {
        foreach (XElement property in pageNode.Elements())
        {
            properties.Add(property.Attribute("name").Value, property.Value);
        }
    }
    SetPropertyValues(page, properties, 
        delegate(string propertyName, string Type, string propertyValue)
        {
            //We dont want to set PageLink or PageParentLink
            if (String.Equals(propertyName, "PageLink") || String.Equals(propertyName, "PageParentLink"))
            {
                return false;
            }
            else
            {
                return true;
            }
        });

    return page;
}

See Also