diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs new file mode 100644 index 0000000000..b917244790 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs @@ -0,0 +1,32 @@ +using System; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(int))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class IntegerValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.Integer).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + if (source == null) return 0; + + // in XML an integer is a string + var sourceString = source as string; + if (sourceString != null) + { + int i; + return (int.TryParse(sourceString, out i)) ? i : 0; + } + + // in the database an integer is an integer + // default value is zero + return (source is int) ? source : 0; + } + } +} diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs new file mode 100644 index 0000000000..0b7ae5c68a --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; +using System.Xml.Linq; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(IEnumerable))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class MultipleTextStringValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.MultipleTextstring).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + // data is (both in database and xml): + // + // + // Strong + // Flexible + // Efficient + // + // + + var sourceString = source.ToString(); + if (string.IsNullOrWhiteSpace(sourceString)) return Enumerable.Empty(); + + var values = new List(); + var pos = sourceString.IndexOf("", StringComparison.Ordinal); + while (pos >= 0) + { + pos += "".Length; + var npos = sourceString.IndexOf("<", pos, StringComparison.Ordinal); + var value = sourceString.Substring(pos, npos - pos); + values.Add(value); + pos = sourceString.IndexOf("", pos, StringComparison.Ordinal); + } + return values.ToArray(); + } + + public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview) + { + var d = new XmlDocument(); + var e = d.CreateElement("values"); + d.AppendChild(e); + + var values = (IEnumerable) source; + foreach (var value in values) + { + var ee = d.CreateElement("value"); + ee.InnerText = value; + e.AppendChild(ee); + } + + return d.CreateNavigator(); + } + } +} diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs new file mode 100644 index 0000000000..b237fb7278 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs @@ -0,0 +1,36 @@ +using System; +using System.Web; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(IHtmlString))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class SimpleEditorValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.UltraSimpleEditor).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + // in xml a string is: string + // in the database a string is: string + // default value is: null + return source; + } + + public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return new HtmlString(source == null ? string.Empty : (string)source); + } + + public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source; + } + } +} diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs new file mode 100644 index 0000000000..e01d9386bb --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(string))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class TextStringValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.Textbox).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + // in xml a string is: string + // in the database a string is: string + // default value is: null + return source; + } + + public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source ?? string.Empty; + } + + public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source; + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 0671b9a5b5..80b700209b 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -194,6 +194,10 @@ + + + + diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs new file mode 100644 index 0000000000..ceae50e93b --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/SimpleEditorValueConverter.cs @@ -0,0 +1,43 @@ +using System; +using System.Web; +using Umbraco.Core; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Templates; + +namespace Umbraco.Web.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(IHtmlString))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Request)] + public class SimpleEditorValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.UltraSimpleEditor).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + if (source == null) return null; + var sourceString = source.ToString(); + + // ensures string is parsed for {localLink} and urls are resolved correctly + sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview); + sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); + + return sourceString; + } + + public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return new HtmlString(source == null ? string.Empty : (string)source); + } + + public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source; + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs new file mode 100644 index 0000000000..e090abd4b9 --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs @@ -0,0 +1,42 @@ +using System; +using Umbraco.Core; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Templates; + +namespace Umbraco.Web.PropertyEditors.ValueConverters +{ + [PropertyValueType(typeof(string))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Request)] + public class TextStringValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Guid.Parse(Constants.PropertyEditors.Textbox).Equals(propertyType.PropertyEditorGuid); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + if (source == null) return null; + var sourceString = source.ToString(); + + // ensures string is parsed for {localLink} and urls are resolved correctly + sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview); + sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); + + return sourceString; + } + + public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source ?? string.Empty; + } + + public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview) + { + // source should come from ConvertSource and be a string (or null) already + return source; + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c508c3fc92..3129231960 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -298,6 +298,8 @@ + + diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 3092fd71ff..31d3ce42ed 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -293,8 +293,11 @@ namespace Umbraco.Web // discovered when CoreBootManager configures the converters. We HAVE to remove one of them // here because there cannot be two converters for one property editor - and we want the full // RteMacroRenderingValueConverter that converts macros, etc. So remove TinyMceValueConverter. - // (why it exists in in the first place, I'm not sure to understand) + // (the limited one, defined in Core, is there for tests) PropertyValueConvertersResolver.Current.RemoveType(); + // same for other converters + PropertyValueConvertersResolver.Current.RemoveType(); + PropertyValueConvertersResolver.Current.RemoveType(); PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches( new PublishedCache.XmlPublishedCache.PublishedContentCache(),