Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
 protected override void Visit(EndElementNode node)
 {
     if (NameUtility.IsMatch("include", Constants.XIncludeNamespace, node.Name, node.Namespace, Context.Namespaces))
     {
         if (FrameData.Mode != Mode.FailedInclude &&
             FrameData.Mode != Mode.SuccessfulInclude)
         {
             throw new CompilerException("Unexpected </include> element");
         }
         if (FrameData.RedundantDepth-- == 0)
         {
             EndInclude();
         }
         return;
     }
     if (NameUtility.IsMatch("fallback", Constants.XIncludeNamespace, node.Name, node.Namespace, Context.Namespaces))
     {
         if (FrameData.Mode != Mode.NormalContent &&
             FrameData.Mode != Mode.IgnoringFallback)
         {
             throw new CompilerException("Unexpected </fallback> element");
         }
         if (FrameData.RedundantDepth-- == 0)
         {
             EndFallback();
         }
         return;
     }
     base.Visit(node);
 }
        protected override void Visit(SpecialNode node)
        {
            bool flag = false;

            if ((NameUtility.IsMatch("else", base.Context.Namespaces, node.Element.Name, node.Element.Namespace) && node.Element.IsEmptyElement) && (this._frame.TestParentNodes != null))
            {
                flag = true;
            }
            if (flag)
            {
                SpecialNode item = new SpecialNode(node.Element);
                this._frame.TestParentNodes.Add(item);
                this._frame.Nodes = item.Body;
            }
            else
            {
                SpecialNode node3 = new SpecialNode(node.Element);
                this.Nodes.Add(node3);
                IList <Node> nodes = this._frame.Nodes;
                this.PushFrame();
                this._frame.Nodes = node3.Body;
                if (NameUtility.IsMatch("if", base.Context.Namespaces, node.Element.Name, node.Element.Namespace) || NameUtility.IsMatch("test", base.Context.Namespaces, node.Element.Name, node.Element.Namespace))
                {
                    this._frame.TestParentNodes = nodes;
                }
                base.Accept(node.Body);
                this.PopFrame();
            }
        }
Ejemplo n.º 4
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
                });
            }
        }
 protected override void Visit(EndElementNode node)
 {
     if (NameUtility.IsMatch("include", "http://www.w3.org/2001/XInclude", node.Name, node.Namespace, base.Context.Namespaces))
     {
         int num;
         if ((base.FrameData.Mode != Mode.FailedInclude) && (base.FrameData.Mode != Mode.SuccessfulInclude))
         {
             throw new CompilerException("Unexpected </include> element");
         }
         Frame frameData = base.FrameData;
         frameData.RedundantDepth = (num = frameData.RedundantDepth) - 1;
         if (num == 0)
         {
             this.EndInclude();
         }
     }
     else if (NameUtility.IsMatch("fallback", "http://www.w3.org/2001/XInclude", node.Name, node.Namespace, base.Context.Namespaces))
     {
         int num2;
         if ((base.FrameData.Mode != Mode.NormalContent) && (base.FrameData.Mode != Mode.IgnoringFallback))
         {
             throw new CompilerException("Unexpected </fallback> element");
         }
         Frame local2 = base.FrameData;
         local2.RedundantDepth = (num2 = local2.RedundantDepth) - 1;
         if (num2 == 0)
         {
             this.EndFallback();
         }
     }
     else
     {
         base.Visit(node);
     }
 }
        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);
        }
Ejemplo n.º 7
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();
            }
        }
 private bool IsMatchingSpec(PrefixSpecs specs, ElementNode node)
 {
     if (base.Context.Namespaces == NamespacesType.Unqualified)
     {
         return(specs.Prefix == NameUtility.GetPrefix(node.Name));
     }
     return(specs.Namespace == node.Namespace);
 }
Ejemplo n.º 9
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)
        {
            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));
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
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);
        }
 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)));
 }
Ejemplo n.º 14
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));
        }
 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);
         }
     }
 }
Ejemplo n.º 16
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)));
        }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
0
        protected override void Visit(ElementNode node)
        {
            var prefix = NameUtility.GetPrefix(node.Name);

            if (!string.IsNullOrEmpty(prefix))
            {
                var specs = _prefixes.FirstOrDefault(spec => IsMatchingSpec(spec, node));
                if (specs != null)
                {
                    PushReconstructedNode(node, specs);
                    return;
                }
            }

            base.Visit(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");
 }
 protected override void Visit(ElementNode node)
 {
     if (NameUtility.IsMatch("include", "http://www.w3.org/2001/XInclude", node.Name, node.Namespace, base.Context.Namespaces))
     {
         if ((base.FrameData.Mode == Mode.SuccessfulInclude) || (base.FrameData.Mode == Mode.FailedInclude))
         {
             if (!node.IsEmptyElement)
             {
                 Frame frameData = base.FrameData;
                 frameData.RedundantDepth++;
             }
         }
         else
         {
             AttributeNode node2 = node.Attributes.FirstOrDefault <AttributeNode>(a => a.Name == "href");
             AttributeNode node3 = node.Attributes.FirstOrDefault <AttributeNode>(a => a.Name == "parse");
             this.BeginInclude(node2.Value, (node3 == null) ? "xml" : node3.Value);
             if (node.IsEmptyElement)
             {
                 this.EndInclude();
             }
         }
     }
     else if (NameUtility.IsMatch("fallback", "http://www.w3.org/2001/XInclude", node.Name, node.Namespace, base.Context.Namespaces))
     {
         if (base.FrameData.Mode == Mode.IgnoringFallback)
         {
             if (!node.IsEmptyElement)
             {
                 Frame local2 = base.FrameData;
                 local2.RedundantDepth++;
             }
         }
         else
         {
             this.BeginFallback();
             if (node.IsEmptyElement)
             {
                 this.EndFallback();
             }
         }
     }
     else
     {
         base.Visit(node);
     }
 }
Ejemplo n.º 21
0
        protected override void Visit(ElementNode node)
        {
            if (NameUtility.IsMatch("include", Constants.XIncludeNamespace, node.Name, node.Namespace, Context.Namespaces))
            {
                if (FrameData.Mode == Mode.SuccessfulInclude ||
                    FrameData.Mode == Mode.FailedInclude)
                {
                    if (!node.IsEmptyElement)
                    {
                        FrameData.RedundantDepth++;
                    }
                    return;
                }

                var href  = node.Attributes.FirstOrDefault(a => a.Name == "href");
                var parse = node.Attributes.FirstOrDefault(a => a.Name == "parse");
                BeginInclude(href.Value, parse == null ? "xml" : parse.Value);
                if (node.IsEmptyElement)
                {
                    EndInclude();
                }
                return;
            }

            if (NameUtility.IsMatch("fallback", Constants.XIncludeNamespace, node.Name, node.Namespace, Context.Namespaces))
            {
                if (FrameData.Mode == Mode.IgnoringFallback)
                {
                    if (!node.IsEmptyElement)
                    {
                        FrameData.RedundantDepth++;
                    }
                    return;
                }

                BeginFallback();
                if (node.IsEmptyElement)
                {
                    EndFallback();
                }
                return;
            }

            base.Visit(node);
        }
        protected override void Visit(ElementNode node)
        {
            Func <PrefixSpecs, bool> predicate = null;

            if (!string.IsNullOrEmpty(NameUtility.GetPrefix(node.Name)))
            {
                if (predicate == null)
                {
                    predicate = spec => this.IsMatchingSpec(spec, node);
                }
                PrefixSpecs specs = this._prefixes.FirstOrDefault <PrefixSpecs>(predicate);
                if (specs != null)
                {
                    this.PushReconstructedNode(node, specs);
                    return;
                }
            }
            base.Visit(node);
        }
Ejemplo n.º 23
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");
        }
Ejemplo n.º 24
0
        protected override void Visit(SpecialNode node)
        {
            bool detachFromParent = false;

            if (NameUtility.IsMatch("else", Context.Namespaces, node.Element.Name, node.Element.Namespace) &&
                node.Element.IsEmptyElement &&
                _frame.TestParentNodes != null)
            {
                detachFromParent = true;
            }

            if (detachFromParent)
            {
                var reconstructed = new SpecialNode(node.Element);
                _frame.TestParentNodes.Add(reconstructed);
                _frame.Nodes = reconstructed.Body;
            }
            else
            {
                var reconstructed = new SpecialNode(node.Element);
                Nodes.Add(reconstructed);

                var parentNodes = _frame.Nodes;

                PushFrame();

                _frame.Nodes = reconstructed.Body;
                if (NameUtility.IsMatch("if", Context.Namespaces, node.Element.Name, node.Element.Namespace) ||
                    NameUtility.IsMatch("test", Context.Namespaces, node.Element.Name, node.Element.Namespace))
                {
                    _frame.TestParentNodes = parentNodes;
                }

                Accept(node.Body);

                PopFrame();
            }
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 27
0
 private string AttrName(AttributeNode attr)
 {
     return(Context.Namespaces == NamespacesType.Qualified
                ? NameUtility.GetName(attr.Name)
                : attr.Name);
 }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
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);
        }