Esempio n. 1
0
        private void PushReconstructedNode(ElementNode original, PrefixSpecs specs)
        {
            // For element <foo:blah> add an additional attributes like name="blah"
            var attributes = new List <AttributeNode>
            {
                new AttributeNode(specs.AttributeName, NameUtility.GetName(original.Name))
            };

            attributes.AddRange(original.Attributes);

            // Replace <foo:blah> with <foo>
            var reconstructed = new ElementNode(specs.ElementName, attributes, original.IsEmptyElement)
            {
                OriginalNode = original, Namespace = Constants.Namespace
            };

            Nodes.Add(reconstructed);

            // If it's not empty, add a frame to watch for the matching end element
            if (!original.IsEmptyElement)
            {
                PushFrame(Nodes, new Frame {
                    OriginalElementName = original.Name, Specs = specs
                });
            }
        }
Esempio n. 2
0
        protected override void Visit(SpecialNode node)
        {
            SpecialNode   item  = new SpecialNode(node.Element);
            string        name  = NameUtility.GetName(node.Element.Name);
            AttributeNode node3 = null;

            if (name != "for")
            {
                node3 = item.Element.Attributes.FirstOrDefault <AttributeNode>(attr => this.IsSpecialAttribute(node.Element, attr));
            }
            if (node3 != null)
            {
                SpecialNode node4 = this.CreateWrappingNode(node3, item.Element);
                item.Element.Attributes.Remove(node3);
                this.Nodes.Add(node4);
                base.PushFrame(node4.Body, new Frame());
            }
            this.Nodes.Add(item);
            base.PushFrame(item.Body, new Frame());
            base.Accept(node.Body);
            base.PopFrame();
            if (node3 != null)
            {
                base.PopFrame();
            }
        }
        protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attr)
        {
            switch (NameUtility.GetName(element.Name))
            {
            case "test":
            case "if":
            case "elseif":
            case "else":
                return(false);
            }
            if (base.Context.Namespaces == NamespacesType.Unqualified)
            {
                if (!(attr.Name == "if") && !(attr.Name == "elseif"))
                {
                    return(attr.Name == "unless");
                }
                return(true);
            }
            if (attr.Namespace != "http://sparkviewengine.com/")
            {
                return(false);
            }
            string name = NameUtility.GetName(attr.Name);

            if (!(name == "if") && !(name == "elseif"))
            {
                return(name == "unless");
            }
            return(true);
        }
Esempio n. 4
0
        protected override void Visit(SpecialNode node)
        {
            var reconstructed = new SpecialNode(node.Element);

            var nqName = NameUtility.GetName(node.Element.Name);

            AttributeNode specialAttr = null;

            if (nqName != "for")
            {
                specialAttr = reconstructed.Element.Attributes.FirstOrDefault(attr => IsSpecialAttribute(node.Element, attr));
            }

            if (specialAttr != null)
            {
                var wrapping = CreateWrappingNode(specialAttr, reconstructed.Element);
                reconstructed.Element.Attributes.Remove(specialAttr);
                Nodes.Add(wrapping);
                PushFrame(wrapping.Body, new Frame());
            }

            Nodes.Add(reconstructed);
            PushFrame(reconstructed.Body, new Frame());
            Accept(node.Body);
            PopFrame();

            if (specialAttr != null)
            {
                PopFrame();
            }
        }
Esempio n. 5
0
 private string AttrName(AttributeNode attr)
 {
     if (base.Context.Namespaces != NamespacesType.Qualified)
     {
         return(attr.Name);
     }
     return(NameUtility.GetName(attr.Name));
 }
        protected override SpecialNode CreateWrappingNode(AttributeNode attr, ElementNode node)
        {
            var fakeAttribute = new AttributeNode("condition", attr.Nodes);
            var fakeElement   = new ElementNode(NameUtility.GetName(attr.Name), new[] { fakeAttribute }, false)
            {
                OriginalNode = attr
            };

            return(new SpecialNode(fakeElement));
        }
        protected override SpecialNode CreateWrappingNode(AttributeNode attr, ElementNode node)
        {
            AttributeNode node2   = new AttributeNode("condition", '"', attr.Nodes);
            ElementNode   element = new ElementNode(NameUtility.GetName(attr.Name), new AttributeNode[] { node2 }, false)
            {
                OriginalNode = attr
            };

            return(new SpecialNode(element));
        }
Esempio n. 8
0
        protected override void Visit(SpecialNode specialNode)
        {
            string name = NameUtility.GetName(specialNode.Element.Name);

            if (!string.IsNullOrEmpty(specialNode.Element.PreceedingWhitespace) && this.specialNodeMap.ContainsKey(name))
            {
                Action <SpecialNode, SpecialNodeInspector> action = this.specialNodeMap[name];
                action(specialNode, new SpecialNodeInspector(specialNode));
            }
            base.Visit(specialNode);
        }
Esempio n. 9
0
        protected override void Visit(SpecialNode specialNode)
        {
            string name = NameUtility.GetName(specialNode.Element.Name);

            if (!this.SpecialNodeMap.ContainsKey(name))
            {
                throw new CompilerException(string.Format("Unknown special node {0}", specialNode.Element.Name));
            }
            Action <SpecialNode, SpecialNodeInspector> action = this.SpecialNodeMap[name];

            action(specialNode, new SpecialNodeInspector(specialNode));
        }
 private bool IsPartialFileElement(string name, string ns)
 {
     if (base.Context.Namespaces == NamespacesType.Unqualified)
     {
         return(base.Context.PartialFileNames.Contains(name));
     }
     if (ns != "http://sparkviewengine.com/")
     {
         return(false);
     }
     return(base.Context.PartialFileNames.Contains(NameUtility.GetName(name)));
 }
 protected override void Visit(ElementNode node)
 {
     if (this.IsContainingElement(node.Name, node.Namespace))
     {
         this.PushSpecial(node);
         if (node.IsEmptyElement)
         {
             this.PopSpecial(node.Name);
         }
     }
     else if (this.IsNonContainingElement(node.Name, node.Namespace))
     {
         this.PushSpecial(node);
         this.PopSpecial(node.Name);
     }
     else
     {
         ISparkExtension extension;
         if (this.TryCreateExtension(node, out extension))
         {
             ExtensionNode item = new ExtensionNode(node, extension);
             this.Nodes.Add(item);
             if (!node.IsEmptyElement)
             {
                 this._extensionNodes.Push(item);
                 this._stack.Push(this.Nodes);
                 this._nodes = item.Body;
             }
         }
         else if (this.IsPartialFileElement(node.Name, node.Namespace))
         {
             List <AttributeNode> attributeNodes = new List <AttributeNode>(node.Attributes)
             {
                 new AttributeNode("file", "_" + NameUtility.GetName(node.Name))
             };
             ElementNode element = new ElementNode("use", attributeNodes, node.IsEmptyElement)
             {
                 OriginalNode = node
             };
             this.PushSpecial(element);
             if (node.IsEmptyElement)
             {
                 this.PopSpecial("use");
             }
         }
         else
         {
             this.Add(node);
         }
     }
 }
Esempio n. 12
0
        private bool IsPartialFileElement(string name, string ns)
        {
            if (Context.Namespaces == NamespacesType.Unqualified)
            {
                return(Context.PartialFileNames.Contains(name));
            }

            if (ns != Constants.Namespace)
            {
                return(false);
            }

            return(Context.PartialFileNames.Contains(NameUtility.GetName(name)));
        }
Esempio n. 13
0
        protected override void Visit(ElementNode node)
        {
            ISparkExtension extension;

            if (IsContainingElement(node.Name, node.Namespace))
            {
                PushSpecial(node);
                if (node.IsEmptyElement)
                {
                    PopSpecial(node.Name);
                }
            }
            else if (IsNonContainingElement(node.Name, node.Namespace))
            {
                PushSpecial(node);
                PopSpecial(node.Name);
            }
            else if (TryCreateExtension(node, out extension))
            {
                ExtensionNode extensionNode = new ExtensionNode(node, extension);
                Nodes.Add(extensionNode);

                if (!node.IsEmptyElement)
                {
                    _extensionNodes.Push(extensionNode);
                    _stack.Push(Nodes);
                    _nodes = extensionNode.Body;
                }
            }
            else if (IsPartialFileElement(node.Name, node.Namespace))
            {
                var attributes = new List <AttributeNode>(node.Attributes);
                attributes.Add(new AttributeNode("file", "_" + NameUtility.GetName(node.Name)));
                var useFile = new ElementNode("use", attributes, node.IsEmptyElement)
                {
                    OriginalNode = node
                };
                PushSpecial(useFile);
                if (node.IsEmptyElement)
                {
                    PopSpecial("use");
                }
            }
            else
            {
                Add(node);
            }
        }
 protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attribute)
 {
     if (NameUtility.GetName(element.Name) == "for")
     {
         return(false);
     }
     if (base.Context.Namespaces == NamespacesType.Unqualified)
     {
         return(attribute.Name == "each");
     }
     if (attribute.Namespace != "http://sparkviewengine.com/")
     {
         return(false);
     }
     return(NameUtility.GetName(attribute.Name) == "each");
 }
Esempio n. 15
0
        protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attribute)
        {
            var eltName = NameUtility.GetName(element.Name);

            if (eltName == "for")
            {
                return(false);
            }

            if (Context.Namespaces == NamespacesType.Unqualified)
            {
                return(attribute.Name == "each");
            }

            if (attribute.Namespace != Constants.Namespace)
            {
                return(false);
            }

            return(NameUtility.GetName(attribute.Name) == "each");
        }
Esempio n. 16
0
        protected override bool IsSpecialAttribute(ElementNode element, AttributeNode attr)
        {
            var eltName = NameUtility.GetName(element.Name);

            if (eltName == "test" || eltName == "if" || eltName == "elseif" || eltName == "else")
            {
                return(false);
            }

            if (Context.Namespaces == NamespacesType.Unqualified)
            {
                return(attr.Name == "if" || attr.Name == "elseif");
            }

            if (attr.Namespace != Constants.Namespace)
            {
                return(false);
            }

            var nqName = NameUtility.GetName(attr.Name);

            return(nqName == "if" || nqName == "elseif");
        }
        private void PushReconstructedNode(ElementNode original, PrefixSpecs specs)
        {
            List <AttributeNode> attributeNodes = new List <AttributeNode> {
                new AttributeNode(specs.AttributeName, NameUtility.GetName(original.Name))
            };

            attributeNodes.AddRange(original.Attributes);
            ElementNode item = new ElementNode(specs.ElementName, attributeNodes, original.IsEmptyElement)
            {
                OriginalNode = original,
                Namespace    = "http://sparkviewengine.com/"
            };

            this.Nodes.Add(item);
            if (!original.IsEmptyElement)
            {
                Frame frameData = new Frame {
                    OriginalElementName = original.Name,
                    Specs = specs
                };
                base.PushFrame(this.Nodes, frameData);
            }
        }
Esempio n. 18
0
 private string AttrName(AttributeNode attr)
 {
     return(Context.Namespaces == NamespacesType.Qualified
                ? NameUtility.GetName(attr.Name)
                : attr.Name);
 }
Esempio n. 19
0
        public AttributeNode TakeAttribute(string name, NamespacesType nsType)
        {
            AttributeNode attr;

            if (nsType == NamespacesType.Unqualified)
            {
                attr = Attributes.FirstOrDefault(a => a.Name == name);
            }
            else
            {
                attr = Attributes.FirstOrDefault(a =>
                                                 (_node.Element.Namespace == Constants.Namespace && a.Name == name) ||
                                                 (a.Namespace == Constants.Namespace && NameUtility.GetName(a.Name) == name));
            }

            Attributes.Remove(attr);
            return(attr);
        }
Esempio n. 20
0
        public AttributeNode TakeAttribute(string name, NamespacesType nsType)
        {
            AttributeNode node;
            Func <AttributeNode, bool> predicate = null;
            Func <AttributeNode, bool> func2     = null;

            if (nsType == NamespacesType.Unqualified)
            {
                if (predicate == null)
                {
                    predicate = a => a.Name == name;
                }
                node = this.Attributes.FirstOrDefault <AttributeNode>(predicate);
            }
            else
            {
                if (func2 == null)
                {
                    func2 = a => ((this._node.Element.Namespace == "http://sparkviewengine.com/") && (a.Name == name)) || ((a.Namespace == "http://sparkviewengine.com/") && (NameUtility.GetName(a.Name) == name));
                }
                node = this.Attributes.FirstOrDefault <AttributeNode>(func2);
            }
            this.Attributes.Remove(node);
            return(node);
        }