// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
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 static readonly CharItem[] DefaultCharCollection =
{
new CharItem { Char = " ", Replacement = "-" },
new CharItem { Char = "\"", Replacement = string.Empty },
new CharItem { Char = "'", Replacement = string.Empty },
new CharItem { Char = "%", Replacement = string.Empty },
new CharItem { Char = ".", Replacement = string.Empty },
new CharItem { Char = ";", Replacement = string.Empty },
new CharItem { Char = "/", Replacement = string.Empty },
new CharItem { Char = "\\", Replacement = string.Empty },
new CharItem { Char = ":", Replacement = string.Empty },
new CharItem { Char = "#", Replacement = string.Empty },
new CharItem { Char = "+", Replacement = "plus" },
new CharItem { Char = "*", Replacement = "star" },
new CharItem { Char = "&", Replacement = string.Empty },
new CharItem { Char = "?", Replacement = string.Empty },
new CharItem { Char = "æ", Replacement = "ae" },
new CharItem { Char = "ä", Replacement = "ae" },
new CharItem { Char = "ø", Replacement = "oe" },
new CharItem { Char = "ö", Replacement = "oe" },
new CharItem { Char = "å", Replacement = "aa" },
new CharItem { Char = "ü", Replacement = "ue" },
new CharItem { Char = "ß", Replacement = "ss" },
new CharItem { Char = "|", Replacement = "-" },
new CharItem { Char = "<", Replacement = string.Empty },
new CharItem { Char = ">", Replacement = string.Empty }
};
///
/// Gets or sets a value indicating whether to add a trailing slash to URLs.
///
public bool AddTrailingSlash { get; set; } = true;
///
/// Gets or sets a value indicating whether to convert URLs to ASCII (valid values: "true", "try" or "false").
///
public string ConvertUrlsToAscii { get; set; } = "try";
///
/// 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");
// We need to special handle ":", as this character is special in keys
// TODO: implement from configuration
//// var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren()
//// .Select(x => new CharItem()
//// {
//// Char = x.GetValue("Char"),
//// Replacement = x.GetValue("Replacement"),
//// }).ToArray();
//// if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x =>
//// x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase)))
//// {
//// return collection;
//// }
//// return DefaultCharCollection;
///
/// Gets or sets a value for the default character collection for replacements.
///
public IEnumerable CharCollection { get; set; } = DefaultCharCollection;
///
/// Defines a character replacement.
///
public class CharItem : IChar
{
///
public string Char { get; set; }
///
public string Replacement { get; set; }
}
}
}