示例#1
0
 private void ResolveFromParent(DothtmlNode parentNode)
 {
     foreach (var childNode in parentNode.EnumerateChildNodes() )
     {
         childNode.ParentNode = parentNode;
     }
 }
        private IAbstractControl ProcessHtmlComment(DothtmlNode node, IDataContextStack dataContext, DotHtmlCommentNode commentNode)
        {
            var text = commentNode.IsServerSide ? "" : "<!--" + commentNode.Value + "-->";

            var literal = treeBuilder.BuildControl(rawLiteralMetadata.Value, node, dataContext);

            literal.ConstructorParameters = new object[] { text, commentNode.Value, true };
            return(literal);
        }
示例#3
0
 public static void CheckForErrors(DothtmlNode node)
 {
     foreach (var n in node.EnumerateNodes())
     {
         if (n.HasNodeErrors)
         {
             throw new DotvvmCompilationException(string.Join(", ", n.NodeErrors), n.Tokens);
         }
     }
 }
示例#4
0
 public ResolvedTreeRoot(ControlResolverMetadata metadata, DothtmlNode node, DataContextStack dataContext, IReadOnlyDictionary <string, IReadOnlyList <IAbstractDirective> > directives)
     : base(metadata, node, dataContext)
 {
     Directives = directives.ToDictionary(d => d.Key, d => d.Value.ToList());
     foreach (var ds in Directives.Values)
     {
         foreach (var d in ds)
         {
             ((ResolvedDirective)d).Parent = this;
         }
     }
 }
        private IAbstractControl ProcessBindingInText(DothtmlNode node, IDataContextStack dataContext)
        {
            var bindingNode = (DothtmlBindingNode)node;
            var literal     = treeBuilder.BuildControl(literalMetadata.Value, node, dataContext);

            var textBinding  = ProcessBinding(bindingNode, dataContext);
            var textProperty = treeBuilder.BuildPropertyBinding(Literal.TextProperty, textBinding, null);

            treeBuilder.SetProperty(literal, textProperty);

            var renderSpanElement = treeBuilder.BuildPropertyValue(Literal.RenderSpanElementProperty, false, null);

            treeBuilder.SetProperty(literal, renderSpanElement);

            return(literal);
        }
示例#6
0
        private IAbstractControl ProcessText(DothtmlNode node, IControlResolverMetadata parentMetadata, IDataContextStack dataContext, DothtmlLiteralNode literalNode)
        {
            var whitespace = string.IsNullOrWhiteSpace(literalNode.Value);

            string text;

            if (literalNode.Escape)
            {
                text = WebUtility.HtmlEncode(literalNode.Value);
            }
            else
            {
                text = literalNode.Value;
            }

            var literal = treeBuilder.BuildControl(rawLiteralMetadata.Value, node, dataContext);

            literal.ConstructorParameters = new object[] { text, literalNode.Value, whitespace };
            return(literal);
        }
示例#7
0
 public ResolvedContentNode(ControlResolverMetadata metadata, DothtmlNode node, DataContextStack dataContext)
     : this(metadata, node, new List <ResolvedControl>(), dataContext)
 {
 }
示例#8
0
 protected virtual bool LogError(Exception exception, DothtmlNode node)
 {
     return(false);
 }
示例#9
0
 /// <summary>
 /// Processes the parser node and builds a control.
 /// </summary>
 public IAbstractControl ProcessNode(IAbstractTreeNode parent, DothtmlNode node, IControlResolverMetadata parentMetadata, IDataContextStack dataContext)
 {
     try
     {
         if (node is DothtmlBindingNode)
         {
             // binding in text
             EnsureContentAllowed(parentMetadata, node);
             return(ProcessBindingInText(node, dataContext));
         }
         else if (node is DotHtmlCommentNode)
         {
             // HTML comment
             var commentNode = node as DotHtmlCommentNode;
             return(ProcessHtmlComment(node, dataContext, commentNode));
         }
         else if (node is DothtmlLiteralNode)
         {
             // text content
             var literalNode = (DothtmlLiteralNode)node;
             return(ProcessText(node, parentMetadata, dataContext, literalNode));
         }
         else if (node is DothtmlElementNode)
         {
             // HTML element
             EnsureContentAllowed(parentMetadata, node);
             var element = (DothtmlElementNode)node;
             return(ProcessObjectElement(element, dataContext));
         }
         else
         {
             throw new NotSupportedException($"The node of type '{node.GetType()}' is not supported!");
         }
     }
     catch (DotvvmCompilationException ex)
     {
         if (ex.Tokens == null)
         {
             ex.Tokens       = node.Tokens;
             ex.ColumnNumber = node.Tokens.First().ColumnNumber;
             ex.LineNumber   = node.Tokens.First().LineNumber;
         }
         if (!LogError(ex, node))
         {
             throw;
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         if (!LogError(ex, node))
         {
             throw new DotvvmCompilationException("", ex, node.Tokens);
         }
         else
         {
             return(null);
         }
     }
 }
示例#10
0
 public ResolvedTreeRoot(ControlResolverMetadata metadata, DothtmlNode node, DataContextStack dataContext, IReadOnlyDictionary <string, IReadOnlyList <IAbstractDirective> > directives)
     : base(metadata, node, dataContext)
 {
     Directives = directives.ToDictionary(d => d.Key, d => d.Value.ToList());
     directives.SelectMany(d => d.Value).ToList().ForEach(d => { ((ResolvedDirective)d).Parent = this; });
 }
示例#11
0
 public ResolvedTreeRoot(ControlResolverMetadata metadata, DothtmlNode node, DataContextStack dataContext)
     : base(metadata, node, dataContext)
 {
 }
示例#12
0
 public IAbstractPropertyValue BuildPropertyValue(IPropertyDescriptor property, object value, DothtmlNode sourceNode)
 {
     return(new ResolvedPropertyValue((DotvvmProperty)property, value)
     {
         DothtmlNode = sourceNode
     });
 }
示例#13
0
 public IAbstractControl BuildControl(IControlResolverMetadata metadata, DothtmlNode node, IDataContextStack dataContext)
 {
     return(new ResolvedControl((ControlResolverMetadata)metadata, node, (DataContextStack)dataContext));
 }
示例#14
0
        private ResolvedControl ProcessNode(DothtmlNode node, ControlResolverMetadata parentMetadata, DataContextStack dataContext)
        {
            try
            {
                if (node is DothtmlBindingNode)
                {
                    EnsureContentAllowed(parentMetadata);

                    // binding in text
                    var binding = (DothtmlBindingNode)node;
                    var literal = new ResolvedControl(controlResolver.ResolveControl(typeof(Literal)), node, dataContext);
                    literal.SetProperty(new ResolvedPropertyBinding(Literal.TextProperty, ProcessBinding(binding, dataContext)));
                    literal.SetProperty(new ResolvedPropertyValue(Literal.RenderSpanElementProperty, false));
                    return(literal);
                }
                else if (node is DotHtmlCommentNode)
                {
                    var commentNode = node as DotHtmlCommentNode;

                    string text    = commentNode.IsServerSide ?  "" : "<!--" + commentNode.Value + "-->";
                    var    literal = new ResolvedControl(controlResolver.ResolveControl(typeof(RawLiteral)), node, dataContext);
                    literal.ContructorParameters = new object[] { text, commentNode.Value, true };
                    return(literal);
                }
                else if (node is DothtmlLiteralNode)
                {
                    var literalNode = ((DothtmlLiteralNode)node);
                    // text content
                    var whitespace = string.IsNullOrWhiteSpace(literalNode.Value);
                    if (!whitespace)
                    {
                        EnsureContentAllowed(parentMetadata);
                    }

                    string text;

                    if (literalNode.Escape)
                    {
                        text = WebUtility.HtmlEncode(literalNode.Value);
                    }
                    else
                    {
                        text = literalNode.Value;
                    }

                    var literal = new ResolvedControl(controlResolver.ResolveControl(typeof(RawLiteral)), node, dataContext);
                    literal.ContructorParameters = new object[] { text, literalNode.Value, whitespace };
                    return(literal);
                }
                else if (node is DothtmlElementNode)
                {
                    // HTML element
                    var element = (DothtmlElementNode)node;
                    EnsureContentAllowed(parentMetadata);

                    // the element is the content
                    return(ProcessObjectElement(element, dataContext));
                }
                else
                {
                    throw new NotSupportedException($"The node of type '{node.GetType()}' is not supported!");
                }
            }
            catch (DotvvmCompilationException ex)
            {
                if (ex.Tokens == null)
                {
                    ex.Tokens       = node.Tokens;
                    ex.ColumnNumber = node.Tokens.First().ColumnNumber;
                    ex.LineNumber   = node.Tokens.First().LineNumber;
                }
                throw;
            }
            catch (Exception ex)
            {
                throw new DotvvmCompilationException("", ex, node.Tokens);
            }
        }
示例#15
0
 public bool Condition(DothtmlNode node)
 {
     return(true);
 }
示例#16
0
 public bool Condition(DothtmlNode node)
 {
     return true;
 }