示例#1
0
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            if (value.IndexOf('|') >= 0)
            {
                return(CompilePipeList(field, value));
            }

            if (value.IndexOf('&') >= 0)
            {
                return(CompileUrlString(field, value));
            }

            if (value.StartsWith("/sitecore", StringComparison.OrdinalIgnoreCase))
            {
                return(CompileDirectLink(field, value));
            }

            return(CompileInlineValue(field, value));
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var qualifiedName = field.Value.Trim();

            if (string.IsNullOrEmpty(qualifiedName))
            {
                return(string.Empty);
            }

            if (qualifiedName == "<image />" || qualifiedName == "<image/>")
            {
                return(string.Empty);
            }

            var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(qualifiedName);

            if (item == null)
            {
                var mediaFile = field.Item.Project.Files.FirstOrDefault(f => string.Equals(f.FilePath, qualifiedName, StringComparison.OrdinalIgnoreCase)) as MediaFile;
                if (mediaFile != null)
                {
                    item = field.Item.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri);
                }
            }

            if (item == null)
            {
                Trace.TraceError(Msg.C1044, Texts.Image_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName);
                return(string.Empty);
            }

            return($"<image mediapath=\"\" alt=\"\" width=\"\" height=\"\" hspace=\"\" vspace=\"\" showineditor=\"\" usethumbnail=\"\" src=\"\" mediaid=\"{item.Uri.Guid.Format()}\" />");
        }
示例#3
0
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var qualifiedName = field.Value.Trim();

            if (string.IsNullOrEmpty(qualifiedName))
            {
                return(string.Empty);
            }

            if (qualifiedName == "<link />" || qualifiedName == "<link/>")
            {
                return(string.Empty);
            }

            var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(qualifiedName);

            if (item == null)
            {
                item = field.Item.Project.Files.FirstOrDefault(f => string.Equals(f.FilePath, qualifiedName, StringComparison.OrdinalIgnoreCase));
            }

            if (item == null)
            {
                Trace.TraceError(Msg.C1049, Texts.Link_field_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName);
                return(string.Empty);
            }

            return($"<link text=\"\" linktype=\"internal\" url=\"\" anchor=\"\" title=\"\" class=\"\" target=\"\" querystring=\"\" id=\"{item.Uri.Guid.Format()}\" />");
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            if (value == "00010101T000000")
            {
                return(value);
            }

            // check if value is an ISO date
            if (value.FromIsoToDateTime() != DateTime.MinValue)
            {
                return(value);
            }

            DateTime dateTime;

            if (!DateTime.TryParse(value, context.Culture, DateTimeStyles.None, out dateTime))
            {
                return(string.Empty);
            }

            return(dateTime.ToString(@"yyyyMMdd") + "T000000Z");
        }
示例#5
0
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            if (field.ValueProperty.Flags.HasFlag(SourcePropertyFlags.IsFileName))
            {
                return(false);
            }

            // if the value contains a dot (.) it is probably a file name
            return(field.Value.IndexOf("/sitecore", StringComparison.OrdinalIgnoreCase) >= 0 && !field.Item.IsImport);
        }
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);
            if (!(textNode is JsonTextNode))
            {
                return false;
            }

            return string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.ValueHint.Contains("Layout");
        }
示例#7
0
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);

            if (!(textNode is JsonTextNode))
            {
                return(false);
            }

            return(string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase));
        }
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            // avoid being called by Json
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);
            if (!(textNode is XmlTextNode))
            {
                return false;
            }

            return string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.ValueHint.Contains("Layout") || field.FieldName == "__Renderings" || field.FieldName == "Final __Renderings";
        }
示例#9
0
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            // avoid being called by Json
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);

            if (!(textNode is XmlTextNode))
            {
                return(false);
            }

            return(string.Equals(field.TemplateField.Type, "layout", StringComparison.OrdinalIgnoreCase) || field.FieldName == "__Renderings" || field.FieldName == "Final __Renderings");
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var indicator = GetIndicatorToken(context.Configuration);

            // Trim indicator
            var wip = field.Value.Substring(indicator.Length);

            var transformer = new MarkdownSharp.Markdown();
            wip = transformer.Transform(wip);

            return wip;
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            var item = field.Item.Project.FindQualifiedItem<IProjectItem>(value);
            if (item == null)
            {
                context.Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value);
                return string.Empty;
            }

            return item.Uri.Guid.Format();
        }
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            if(string.IsNullOrEmpty(field.Value))
            {
                return false;
            }

            var fieldTypeCheck = string.Equals(field.TemplateField.Type, "rich text", StringComparison.OrdinalIgnoreCase);

            var indicator = GetIndicatorToken(context.Configuration);
            var indicatorCheck = indicator == null ? true : field.Value.StartsWith(indicator);

            return fieldTypeCheck && indicatorCheck;
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            if (string.Equals(value, "true", StringComparison.OrdinalIgnoreCase))
            {
                return("1");
            }

            if (value == "1")
            {
                return("1");
            }

            return(string.Empty);
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var qualifiedName = field.Value.Trim();
            if (string.IsNullOrEmpty(qualifiedName))
            {
                return string.Empty;
            }

            var item = field.Item.Project.FindQualifiedItem<IProjectItem>(qualifiedName);
            if (item == null)
            {
                context.Trace.TraceError(Msg.C1049, Texts.Link_field_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName);
                return string.Empty;
            }

            return $"<link text=\"\" linktype=\"internal\" url=\"\" anchor=\"\" title=\"\" class=\"\" target=\"\" querystring=\"\" id=\"{item.Uri.Guid.Format()}\" />";
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var qualifiedName = field.Value.Trim();
            if (string.IsNullOrEmpty(qualifiedName))
            {
                return string.Empty;
            }

            var item = field.Item.Project.FindQualifiedItem(qualifiedName);
            if (item == null)
            {
                context.Trace.TraceError(Msg.C1044, Texts.Image_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), qualifiedName);
                return string.Empty;
            }

            return $"<image mediapath=\"\" alt=\"\" width=\"\" height=\"\" hspace=\"\" vspace=\"\" showineditor=\"\" usethumbnail=\"\" src=\"\" mediaid=\"{item.Uri.Guid.Format()}\" />";
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);
            if (textNode == TextNode.Empty)
            {
                return field.Value;
            }

            var textSnapshot = textNode.Snapshot as ITextSnapshot;
            if (textSnapshot == null)
            {
                return field.Value;
            }

            var layoutCompileContext = new LayoutCompileContext(context, FileSystem, field, textSnapshot);

            var compiler = new JsonLayoutCompiler();
            return compiler.Compile(layoutCompileContext, textNode);
        }
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            if (!field.Value.StartsWith("~", StringComparison.Ordinal))
            {
                return(false);
            }

            if (field.ValueProperty.Flags.HasFlag(SourcePropertyFlags.IsFileName))
            {
                return(true);
            }

            if (_pathFields.Contains(field.FieldId.Format()))
            {
                return(true);
            }

            return(false);
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            var item = field.Item.Project.Indexes.FindQualifiedItem <IProjectItem>(value);

            if (item == null)
            {
                Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty, field), value);
                return(value);
            }

            return(item.Uri.Guid.Format());
        }
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            if (!field.Value.StartsWith("~", StringComparison.Ordinal))
            {
                return false;
            }

            if (field.ValueProperty.Flags.HasFlag(SourcePropertyFlags.IsFileName))
            {
                return true;
            }

            // guess: may actually not be a file name
            if (field.FieldName == "Path")
            {
                return true;
            }

            return false;
        }
示例#20
0
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var textNode = TraceHelper.GetTextNode(field.ValueProperty);

            if (textNode == TextNode.Empty)
            {
                return(field.Value);
            }

            var textSnapshot = textNode.Snapshot as ITextSnapshot;

            if (textSnapshot == null)
            {
                return(field.Value);
            }

            var layoutCompileContext = Factory.LayoutCompileContext(field.Item.Project, field.Database, textSnapshot);
            var layoutCompiler       = Factory.LayoutCompiler();

            return(layoutCompiler.Compile(layoutCompileContext, textNode));
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();

            if (!string.Equals(value, "true", StringComparison.OrdinalIgnoreCase) && !string.Equals(value, "false", StringComparison.OrdinalIgnoreCase) && 
                field.Item.Snapshots.All(s => s.Capabilities.HasFlag(SnapshotCapabilities.SupportsTrueAndFalseForBooleanFields)))
            {
                context.Trace.TraceError(Msg.C1043, Texts.Checkbox_field_value_must_be__true__or__false__, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value);
            }

            if (string.Equals(value, "true", StringComparison.OrdinalIgnoreCase))
            {
                return "1";
            }

            if (value == "1")
            {
                return "1";
            }

            return string.Empty;
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }

            // check if value is an ISO date
            if (value.FromIsoToDateTime() != DateTime.MinValue)
            {
                return value;
            }

            DateTime dateTime;
            if (!DateTime.TryParse(value, context.Culture, DateTimeStyles.None, out dateTime))
            {
                context.Trace.TraceError(Msg.C1058, "Date field must contain a valid date value", TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value);
                return string.Empty;
            }

            return dateTime.ToString(@"yyyyMMdd") + "T000000Z";
        }
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var value = field.Value.Trim();
            if (value.IndexOf('|') < 0)
            {
                var item = field.Item.Project.FindQualifiedItem<IProjectItem>(value);
                if (item == null)
                {
                    context.Trace.TraceError(Msg.C1045, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value);
                    return string.Empty;
                }

                return item.Uri.Guid.Format();
            }

            var sb = new StringBuilder();
            foreach (var itemPath in value.Split(Constants.Pipe, StringSplitOptions.RemoveEmptyEntries))
            {
                var item = field.Item.Project.FindQualifiedItem<IProjectItem>(itemPath);
                if (item == null)
                {
                    context.Trace.TraceError(Msg.C1046, Texts.Item_path_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), itemPath);
                }
                else
                {
                    if (sb.Length > 0)
                    {
                        sb.Append('|');
                    }

                    sb.Append(item.Uri.Guid.Format());
                }
            }

            return sb.ToString();
        }
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     return (field.ValueProperty.Flags & SourcePropertyFlags.IsFileName) == SourcePropertyFlags.IsFileName & field.Value.StartsWith("~", StringComparison.Ordinal);
 }
 public override bool CanCompile(IFieldCompileContext context, Field field) => string.Equals(field.TemplateField.Type, "reference", StringComparison.OrdinalIgnoreCase);
        public override string Compile(IFieldCompileContext context, Field field)
        {
            var htmlTemplate = field.Value.Trim();
            if (string.IsNullOrEmpty(htmlTemplate))
            {
                return string.Empty;
            }

            var value = htmlTemplate;

            var rendering = field.Item.Project.ProjectItems.OfType<Rendering>().FirstOrDefault(i => string.Equals(i.FilePath, value, StringComparison.OrdinalIgnoreCase));
            if (rendering == null)
            {
                context.Trace.TraceError(Msg.C1047, Texts.Rendering_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), value);
            }

            var layoutItem = field.Item.Project.ProjectItems.OfType<Item>().FirstOrDefault(i => i.ItemIdOrPath == "/sitecore/layout/Layouts/MvcLayout");
            if (layoutItem == null)
            {
                context.Trace.TraceError(Msg.C1048, Texts.Layout_reference_not_found, TraceHelper.GetTextNode(field.ValueProperty, field.FieldNameProperty), "/sitecore/layout/Layouts/MvcLayout");
            }

            if (rendering == null || layoutItem == null)
            {
                return string.Empty;
            }

            var renderingItemUri = rendering.RenderingItemUri;
            if (renderingItemUri == ProjectItemUri.Empty)
            {
                return string.Empty;
            }

            var renderingId = renderingItemUri.Guid.Format();

            var writer = new StringWriter();
            var output = new XmlTextWriter(writer);
            output.Formatting = Formatting.Indented;

            output.WriteStartElement("r");

            var deviceItems = field.Item.Project.ProjectItems.OfType<Item>().Where(i => string.Equals(i.TemplateIdOrPath, "/sitecore/templates/System/Layout/Device", StringComparison.OrdinalIgnoreCase) || string.Equals(i.TemplateIdOrPath, "{B6F7EEB4-E8D7-476F-8936-5ACE6A76F20B}", StringComparison.OrdinalIgnoreCase));
            foreach (var deviceItem in deviceItems)
            {
                if (!deviceItem.ItemIdOrPath.StartsWith("/sitecore/layout/Devices/"))
                {
                    continue;
                }

                output.WriteStartElement("d");
                output.WriteAttributeString("id", deviceItem.Uri.Guid.Format());
                output.WriteAttributeString("l", layoutItem.Uri.Guid.Format());

                output.WriteStartElement("r");
                output.WriteAttributeString("id", renderingId);
                output.WriteAttributeString("ph", "Page.Body");
                output.WriteEndElement();

                output.WriteEndElement();
            }

            output.WriteEndElement();

            return writer.ToString();
        }
示例#27
0
 public abstract bool CanCompile(IFieldCompileContext context, Field field);
示例#28
0
        public override bool CanCompile(IFieldCompileContext context, Field field)
        {
            var type = field.TemplateField.Type;

            return(string.Equals(type, "general link", StringComparison.OrdinalIgnoreCase) || string.Equals(type, "link", StringComparison.OrdinalIgnoreCase));
        }
示例#29
0
 public override string Compile(IFieldCompileContext context, Field field)
 {
     return Value;
 }
示例#30
0
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     return true;
 }
示例#31
0
 public abstract string Compile(IFieldCompileContext context, Field field);
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     return string.Equals(field.TemplateField.Type, "image", StringComparison.OrdinalIgnoreCase);
 }
 public abstract string Compile(IFieldCompileContext context, Field field);
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     return field.ValueHint.Contains("HtmlTemplate");
 }
 public abstract bool CanCompile(IFieldCompileContext context, Field field);
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     return(string.Equals(field.TemplateField.Type, "date", StringComparison.OrdinalIgnoreCase));
 }
 public override string Compile(IFieldCompileContext context, Field field) => PathHelper.NormalizeItemPath(field.Value.TrimStart('~'));
 public override string Compile(IFieldCompileContext context, Field field)
 {
     return field.Value.TrimStart('~');
 }
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     // if the value contains a dot (.) it is probably a file name
     return field.Value.IndexOf("/sitecore", StringComparison.OrdinalIgnoreCase) >= 0 && field.Value.IndexOf('.') < 0 && !field.Item.IsImport;
 }
 public override bool CanCompile(IFieldCompileContext context, Field field)
 {
     var type = field.TemplateField.Type;
     return string.Equals(type, "reference", StringComparison.OrdinalIgnoreCase);
 }