protected virtual void ParseFieldsTextNode([NotNull] ItemParseContext context, [NotNull] Item item, [NotNull] ITextNode textNode)
        {
            var languageVersionContext = new LanguageVersionContext();

            foreach (var childNode in textNode.ChildNodes)
            {
                switch (childNode.Key)
                {
                    case "Field":
                        ParseFieldTextNode(context, item, languageVersionContext, childNode);
                        break;

                    case "Unversioned":
                        ParseUnversionedTextNode(context, item, childNode);
                        break;

                    case "Versioned":
                        ParseVersionedTextNode(context, item, childNode);
                        break;

                    case "Layout":
                        ParseLayoutTextNode(context, item, childNode);
                        break;

                    default:
                        ParseUnknownTextNode(context, item, languageVersionContext, childNode);
                        break;
                }
            }
        }
        public override void Parse(ItemParseContext context, ITextNode textNode)
        {
            var itemNameTextNode = GetItemNameTextNode(context.ParseContext, textNode);
            var parentItemPath = textNode.GetAttributeValue("ParentItemPath", context.ParentItemPath);
            var itemIdOrPath = PathHelper.CombineItemPath(parentItemPath, itemNameTextNode.Value);
            var guid = StringHelper.GetGuid(context.ParseContext.Project, textNode.GetAttributeValue("Id", itemIdOrPath));
            var databaseName = textNode.GetAttributeValue("Database", context.DatabaseName);
            var templateIdOrPath = textNode.Key.UnescapeXmlElementName();

            var item = context.ParseContext.Factory.Item(context.ParseContext.Project, textNode, guid, databaseName, itemNameTextNode.Value, itemIdOrPath, templateIdOrPath);
            item.ItemNameProperty.AddSourceTextNode(itemNameTextNode);
            item.TemplateIdOrPathProperty.AddSourceTextNode(new AttributeNameTextNode(textNode));
            item.IsEmittable = !string.Equals(textNode.GetAttributeValue(Constants.Fields.IsEmittable), "False", StringComparison.OrdinalIgnoreCase);
            item.IsImport = string.Equals(textNode.GetAttributeValue(Constants.Fields.IsExtern, context.IsExtern.ToString()), "True", StringComparison.OrdinalIgnoreCase);

            if (!item.IsImport)
            {
                item.References.AddRange(context.ParseContext.ReferenceParser.ParseReferences(item, item.TemplateIdOrPathProperty));
            }

            var fieldContext = new LanguageVersionContext();
            ParseAttributes(context, item, fieldContext, textNode);

            ParseChildNodes(context, item, textNode);

            context.ParseContext.Project.AddOrMerge(item);
        }
 protected override void ParseUnversionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
 {
     foreach (var languageChildNode in textNode.ChildNodes)
     {
         var fieldContext = new LanguageVersionContext();
         fieldContext.LanguageProperty.SetValue(new AttributeNameTextNode(languageChildNode));
         ParseUnversionedOrVersionedTreeNode(context, item, fieldContext, languageChildNode);
     }
 }
        protected override void ParseUnversionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            var fieldContext = new LanguageVersionContext();
            fieldContext.LanguageProperty.Parse(textNode);

            foreach (var unversionedChildNode in textNode.ChildNodes)
            {
                ParseFieldTextNode(context, item, fieldContext, unversionedChildNode);
            }
        }
        protected override void ParseFieldTextNode(ItemParseContext context, Item item, LanguageVersionContext languageVersionContext, ITextNode textNode)
        {
            var fieldNameTextNode = string.IsNullOrEmpty(textNode.Value) ? textNode.GetAttribute("Name") : textNode;
            if (fieldNameTextNode == null)
            {
                context.ParseContext.Trace.TraceError(Msg.P1015, Texts.Expected__Name__attribute, textNode);
                return;
            }

            ParseFieldTextNode(context, item, languageVersionContext, textNode, fieldNameTextNode);
        }
        protected override void ParseFieldsTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            var fieldContext = new LanguageVersionContext();

            foreach (var attribute in textNode.Attributes)
            {
                ParseFieldTextNode(context, item, fieldContext, attribute);
            }

            base.ParseFieldsTextNode(context, item, textNode);
        }
        protected override void ParseUnversionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            var firstChildNode = textNode.ChildNodes.First();

            var fieldContext = new LanguageVersionContext();
            fieldContext.LanguageProperty.SetValue(new AttributeNameTextNode(firstChildNode));

            foreach (var unversionedChildNode in firstChildNode.ChildNodes)
            {
                ParseFieldTextNode(context, item, fieldContext, unversionedChildNode);
            }
        }
        protected override void ParseVersionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            context.ParseContext.SchemaService.ValidateTextNodeSchema(textNode);

            foreach (var versionChildNode in textNode.ChildNodes)
            {
                var fieldContext = new LanguageVersionContext();
                fieldContext.LanguageProperty.Parse(textNode);
                fieldContext.VersionProperty.Parse(versionChildNode);

                foreach (var versionedChildNode in versionChildNode.ChildNodes)
                {
                    ParseFieldTextNode(context, item, fieldContext, versionedChildNode);
                }
            }
        }
        protected override void ParseFieldTextNode(ItemParseContext context, Item item, LanguageVersionContext languageVersionContext, ITextNode textNode)
        {
            var fieldNameTextNode = textNode.Key == "Field" ? textNode.GetAttribute("Name") : new AttributeNameTextNode(textNode);
            if (fieldNameTextNode == null)
            {
                context.ParseContext.Trace.TraceError(Msg.P1014, Texts.Expected__Name__attribute, textNode);
                return;
            }

            if (textNode.Attributes.Any() || textNode.ChildNodes.Any())
            {
                base.ParseFieldTextNode(context, item, languageVersionContext, textNode, fieldNameTextNode);
                return;
            }

            base.ParseFieldTextNode(context, item, languageVersionContext, textNode, fieldNameTextNode, textNode);
        }
예제 #10
0
        public override void Parse(ItemParseContext context, ITextNode textNode)
        {
            SchemaService.ValidateTextNodeSchema(textNode, "Item");

            var itemNameTextNode = GetItemNameTextNode(context.ParseContext, textNode);
            var parentItemPath   = textNode.GetAttributeValue("ParentItemPath", context.ParentItemPath);
            var itemIdOrPath     = textNode.GetAttributeValue("ItemPath");

            if (string.IsNullOrEmpty(itemIdOrPath))
            {
                itemIdOrPath = PathHelper.CombineItemPath(parentItemPath, itemNameTextNode.Value);
            }
            else if (itemNameTextNode.Value != Path.GetFileName(itemIdOrPath))
            {
                Trace.TraceError(Msg.P1027, "Item name in 'ItemPath' and 'Name' does not match. Using 'Name'");
            }

            var guid             = StringHelper.GetGuid(context.ParseContext.Project, textNode.GetAttributeValue("Id", itemIdOrPath));
            var databaseName     = textNode.GetAttributeValue("Database", context.Database.DatabaseName);
            var database         = context.ParseContext.Project.GetDatabase(databaseName);
            var templateIdOrPath = textNode.GetAttributeValue("TemplateName", textNode.Key.UnescapeXmlElementName());

            var item = Factory.Item(database, guid, itemNameTextNode.Value, itemIdOrPath, templateIdOrPath).With(textNode);

            item.ItemNameProperty.AddSourceTextNode(itemNameTextNode);
            item.TemplateIdOrPathProperty.AddSourceTextNode(new AttributeNameTextNode(textNode));
            item.SortorderProperty.Parse(textNode, context.Sortorder);
            item.IsEmittable = textNode.GetAttributeBool(Constants.Fields.IsEmittable, true);
            item.IsImport    = textNode.GetAttributeBool(Constants.Fields.IsImport, context.IsImport);

            if (!item.IsImport)
            {
                item.References.AddRange(ReferenceParser.ParseReferences(item, item.TemplateIdOrPathProperty));
            }

            // parse shared fields
            var fieldContext = new LanguageVersionContext();

            ParseAttributes(context, item, fieldContext, textNode);

            // parse Fields, Layout and Items child text nodes
            ParseChildNodes(context, item, textNode);

            context.ParseContext.Project.AddOrMerge(item);
        }
        protected override void ParseVersionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            var firstChildNode = textNode.ChildNodes.First();

            context.ParseContext.SchemaService.ValidateTextNodeSchema(firstChildNode);

            foreach (var node in firstChildNode.ChildNodes)
            {
                var fieldContext = new LanguageVersionContext();

                fieldContext.LanguageProperty.SetValue(new AttributeNameTextNode(firstChildNode));
                fieldContext.VersionProperty.SetValue(new AttributeNameTextNode(node));

                foreach (var versionedChildNode in node.ChildNodes)
                {
                    ParseFieldTextNode(context, item, fieldContext, versionedChildNode);
                }
            }
        }
예제 #12
0
        protected virtual void ParseFieldTextNode([NotNull] ItemParseContext context, [NotNull] Item item, [NotNull] LanguageVersionContext languageVersionContext, [NotNull] ITextNode fieldTextNode)
        {
            SchemaService.ValidateTextNodeSchema(fieldTextNode, "Field");

            var fieldName = fieldTextNode.Key.UnescapeXmlElementName();

            if (fieldName == "Name" || fieldName == "Id" || fieldName == "Database" || fieldName == "TemplateName" || fieldName == "ItemPath" || fieldName == "ParentItemPath" || fieldName == Constants.Fields.IsEmittable || fieldName == Constants.Fields.IsImport)
            {
                return;
            }

            var field = Factory.Field(item).With(fieldTextNode);

            field.FieldNameProperty.SetValue(new AttributeNameTextNode(fieldTextNode));
            field.LanguageProperty.SetValue(languageVersionContext.LanguageProperty);
            field.VersionProperty.SetValue(languageVersionContext.VersionProperty);
            field.ValueProperty.SetValue(fieldTextNode);

            // check if field is already defined
            var duplicate = item.Fields.FirstOrDefault(f => string.Equals(f.FieldName, field.FieldName, StringComparison.OrdinalIgnoreCase) && f.Language == field.Language && f.Version == field.Version);

            if (duplicate == null)
            {
                item.Fields.Add(field);
            }
            else
            {
                Trace.TraceError(Msg.P1008, Texts.Field_is_already_defined, fieldTextNode, duplicate.FieldName);
            }

            if (!item.IsImport)
            {
                item.References.AddRange(ReferenceParser.ParseReferences(field));
            }
        }
 protected override void ParseUnknownTextNode(ItemParseContext context, Item item, LanguageVersionContext languageVersionContext, ITextNode textNode)
 {
     var fieldNameTextNode = new AttributeNameTextNode(textNode);
     ParseFieldTextNode(context, item, languageVersionContext, textNode, fieldNameTextNode);
 }
        protected virtual void ParseUnversionedTextNode([NotNull] ItemParseContext context, [NotNull] Item item, [NotNull] ITextNode childNode)
        {
            var fieldContext = new LanguageVersionContext();
            fieldContext.LanguageProperty.Parse(childNode);

            ParseAttributes(context, item, fieldContext, childNode);
        }
 protected override void ParseUnknownTextNode(ItemParseContext context, Item item, LanguageVersionContext languageVersionContext, ITextNode textNode)
 {
     ParseFieldTextNode(context, item, languageVersionContext, textNode);
 }
예제 #16
0
 protected virtual void ParseAttributes([NotNull] ItemParseContext context, [NotNull] Item item, [NotNull] LanguageVersionContext languageVersionContext, [NotNull] ITextNode textNode)
 {
     foreach (var childNode in textNode.Attributes)
     {
         ParseFieldTextNode(context, item, languageVersionContext, childNode);
     }
 }
        protected override void ParseVersionedTextNode(ItemParseContext context, Item item, ITextNode textNode)
        {
            context.ParseContext.SchemaService.ValidateTextNodeSchema(textNode);

            foreach (var languageChildNode in textNode.ChildNodes)
            {
                foreach (var versionChildNode in languageChildNode.ChildNodes)
                {
                    var fieldContext = new LanguageVersionContext();
                    fieldContext.LanguageProperty.SetValue(new AttributeNameTextNode(languageChildNode));
                    fieldContext.VersionProperty.SetValue(new AttributeNameTextNode(versionChildNode));
                    ParseUnversionedOrVersionedTreeNode(context, item, fieldContext, versionChildNode);
                }
            }
        }