// Copyright (c) Umbraco. // See LICENSE for more details. using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using Umbraco.Cms.Core.Configuration.UmbracoSettings; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Configuration.Models { /// /// Typed configuration options for request handler settings. /// [UmbracoOptions(Constants.Configuration.ConfigRequestHandler)] public class RequestHandlerSettings { internal const bool StaticAddTrailingSlash = true; internal const string StaticConvertUrlsToAscii = "try"; internal const bool StaticEnableDefaultCharReplacements = true; internal static readonly Umbraco.Cms.Core.Configuration.Models.CharItem[] DefaultCharCollection = { new () { Char = " ", Replacement = "-" }, new () { Char = "\"", Replacement = string.Empty }, new () { Char = "'", Replacement = string.Empty }, new () { Char = "%", Replacement = string.Empty }, new () { Char = ".", Replacement = string.Empty }, new () { Char = ";", Replacement = string.Empty }, new () { Char = "/", Replacement = string.Empty }, new () { Char = "\\", Replacement = string.Empty }, new () { Char = ":", Replacement = string.Empty }, new () { Char = "#", Replacement = string.Empty }, new () { Char = "+", Replacement = "plus" }, new () { Char = "*", Replacement = "star" }, new () { Char = "&", Replacement = string.Empty }, new () { Char = "?", Replacement = string.Empty }, new () { Char = "æ", Replacement = "ae" }, new () { Char = "ä", Replacement = "ae" }, new () { Char = "ø", Replacement = "oe" }, new () { Char = "ö", Replacement = "oe" }, new () { Char = "å", Replacement = "aa" }, new () { Char = "ü", Replacement = "ue" }, new () { Char = "ß", Replacement = "ss" }, new () { Char = "|", Replacement = "-" }, new () { Char = "<", Replacement = string.Empty }, new () { Char = ">", Replacement = string.Empty } }; /// /// Gets or sets a value indicating whether to add a trailing slash to URLs. /// [DefaultValue(StaticAddTrailingSlash)] public bool AddTrailingSlash { get; set; } = StaticAddTrailingSlash; /// /// Gets or sets a value indicating whether to convert URLs to ASCII (valid values: "true", "try" or "false"). /// [DefaultValue(StaticConvertUrlsToAscii)] public string ConvertUrlsToAscii { get; set; } = StaticConvertUrlsToAscii; /// /// Gets a value indicating whether URLs should be converted to ASCII. /// public bool ShouldConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("true"); /// /// Gets a value indicating whether URLs should be tried to be converted to ASCII. /// public bool ShouldTryConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("try"); /// /// Disable all default character replacements /// [DefaultValue(StaticEnableDefaultCharReplacements)] public bool EnableDefaultCharReplacements { get; set; } = StaticEnableDefaultCharReplacements; /// /// Add additional character replacements, or override defaults /// [Obsolete("Use the GetCharReplacements extension method in the Umbraco.Extensions namespace instead. Scheduled for removal in V11")] public IEnumerable CharCollection { get; set; } = DefaultCharCollection; /// /// Add additional character replacements, or override defaults /// public IEnumerable? UserDefinedCharCollection { get; set; } } }