2020-12-06 10:46:04 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.UmbracoSettings;
|
|
|
|
|
using Umbraco.Extensions;
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Core.Configuration.Models
|
2020-08-23 23:36:48 +02:00
|
|
|
{
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Typed configuration options for request handler settings.
|
|
|
|
|
/// </summary>
|
2021-06-24 08:47:37 +02:00
|
|
|
[UmbracoOptions(Constants.Configuration.ConfigRequestHandler)]
|
2020-08-23 23:36:48 +02:00
|
|
|
public class RequestHandlerSettings
|
|
|
|
|
{
|
2020-08-24 16:06:09 +02:00
|
|
|
internal static readonly CharItem[] DefaultCharCollection =
|
2020-08-23 23:36:48 +02:00
|
|
|
{
|
|
|
|
|
new CharItem { Char = " ", Replacement = "-" },
|
2020-12-06 10:46:04 +01:00
|
|
|
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 },
|
2020-08-23 23:36:48 +02:00
|
|
|
new CharItem { Char = "+", Replacement = "plus" },
|
|
|
|
|
new CharItem { Char = "*", Replacement = "star" },
|
2020-12-06 10:46:04 +01:00
|
|
|
new CharItem { Char = "&", Replacement = string.Empty },
|
|
|
|
|
new CharItem { Char = "?", Replacement = string.Empty },
|
2020-08-23 23:36:48 +02:00
|
|
|
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 = "-" },
|
2020-12-06 10:46:04 +01:00
|
|
|
new CharItem { Char = "<", Replacement = string.Empty },
|
|
|
|
|
new CharItem { Char = ">", Replacement = string.Empty }
|
2020-08-23 23:36:48 +02:00
|
|
|
};
|
|
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether to add a trailing slash to URLs.
|
|
|
|
|
/// </summary>
|
2020-08-23 23:36:48 +02:00
|
|
|
public bool AddTrailingSlash { get; set; } = true;
|
|
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether to convert URLs to ASCII (valid values: "true", "try" or "false").
|
|
|
|
|
/// </summary>
|
2020-08-25 10:45:54 +02:00
|
|
|
public string ConvertUrlsToAscii { get; set; } = "try";
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether URLs should be converted to ASCII.
|
|
|
|
|
/// </summary>
|
2020-08-25 10:45:54 +02:00
|
|
|
public bool ShouldConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("true");
|
|
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether URLs should be tried to be converted to ASCII.
|
|
|
|
|
/// </summary>
|
2020-08-25 10:45:54 +02:00
|
|
|
public bool ShouldTryConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("try");
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
// We need to special handle ":", as this character is special in keys
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-08-24 16:06:09 +02:00
|
|
|
// TODO: implement from configuration
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
//// var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren()
|
|
|
|
|
//// .Select(x => new CharItem()
|
|
|
|
|
//// {
|
|
|
|
|
//// Char = x.GetValue<string>("Char"),
|
|
|
|
|
//// Replacement = x.GetValue<string>("Replacement"),
|
|
|
|
|
//// }).ToArray();
|
|
|
|
|
|
|
|
|
|
//// if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x =>
|
|
|
|
|
//// x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
//// {
|
|
|
|
|
//// return collection;
|
|
|
|
|
//// }
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
//// return DefaultCharCollection;
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value for the default character collection for replacements.
|
|
|
|
|
/// </summary>
|
2020-08-25 12:30:43 +02:00
|
|
|
public IEnumerable<IChar> CharCollection { get; set; } = DefaultCharCollection;
|
2020-08-23 23:36:48 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Defines a character replacement.
|
|
|
|
|
/// </summary>
|
2020-08-23 23:36:48 +02:00
|
|
|
public class CharItem : IChar
|
|
|
|
|
{
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <inheritdoc/>
|
2020-08-23 23:36:48 +02:00
|
|
|
public string Char { get; set; }
|
2020-08-24 16:06:09 +02:00
|
|
|
|
2020-12-06 10:46:04 +01:00
|
|
|
/// <inheritdoc/>
|
2020-08-23 23:36:48 +02:00
|
|
|
public string Replacement { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|