Exemplo n.º 1
0
        private static void CheckBrPosition(PortableHtmlContext context)
        {
            var brs = context.SourceXml.Descendants("br").Where(context.InChecking).ToArray();

            foreach (var e in brs)
            {
                if (!context.IsActive)
                {
                    break;
                }
                var parentTag = e.Parent.Name.LocalName;
                if (-1 == Array.IndexOf(ContentElements, parentTag))
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidBrPosition, e);
                    if (!context.InChecking(e))
                    {
                        continue;
                    }
                }
                if (!checkBrNeighbro(e.PreviousNode) || !checkBrNeighbro(e.NextNode))
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidBrPosition, e);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Проверяет наличие запрещенных атрибутов
 /// </summary>
 /// <param name="context"></param>
 private static void CheckDeprecatedAttributes(PortableHtmlContext context)
 {
     foreach (var e in context.SourceXml.DescendantsAndSelf().Where(context.InChecking))
     {
         if (!context.IsActive)
         {
             break;
         }
         foreach (var a in e.Attributes())
         {
             if (!context.IsActive)
             {
                 break;
             }
             if (!context.InChecking(e))
             {
                 break;
             }
             var state = context.GetAttributeErrorState(a.Name.LocalName, a.Parent.Name.LocalName);
             if (state != PortableHtmlSchemaErorr.None)
             {
                 context.SetError(state, a: a);
             }
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Проверяет наличие запрещенных атрибутов
 /// </summary>
 /// <param name="context"></param>
 private static void CheckUpperCase(PortableHtmlContext context)
 {
     foreach (var e in context.SourceXml.DescendantsAndSelf().Where(context.InChecking))
     {
         if (e.Name.LocalName.ToLowerInvariant() != e.Name.LocalName)
         {
             context.SetError(PortableHtmlSchemaErorr.UpperCaseDetected, e);
         }
         if (!context.InChecking(e))
         {
             continue;
         }
         foreach (var a in e.Attributes())
         {
             if (a.Name.LocalName.ToLowerInvariant() != a.Name.LocalName)
             {
                 context.SetError(PortableHtmlSchemaErorr.UpperCaseDetected, a: a);
             }
         }
     }
 }
Exemplo n.º 4
0
 private static void CheckNoTextElementsText(PortableHtmlContext context)
 {
     foreach (var e in context.SourceXml.Descendants())
     {
         if (!context.IsActive)
         {
             break;
         }
         if (!context.InChecking(e))
         {
             continue;
         }
         if (-1 != Array.IndexOf(NoTextElements, e.Name.LocalName))
         {
             if (e.Nodes().OfType <XText>().Any())
             {
                 context.SetError(PortableHtmlSchemaErorr.TextInNonTextElement, e);
             }
         }
     }
 }
Exemplo n.º 5
0
 private static void CheckNestedParas(PortableHtmlContext context)
 {
     foreach (var p in context.SourceXml.Descendants())
     {
         if (!context.IsActive)
         {
             break;
         }
         if (!context.InChecking(p))
         {
             continue;
         }
         if (-1 != Array.IndexOf(ParaElements, p.Name.LocalName))
         {
             if (p.Parent != context.SourceXml)
             {
                 context.SetError(PortableHtmlSchemaErorr.NestedParaElements, p);
             }
         }
     }
 }
		public void InForcedStrategiesMarksElementsNotToReproduce(){
			var ctx = new PortableHtmlContext{Strategy = PortableHtmlVerificationStrategy.Full};
			var e = new XElement("test");
			Assert.True(ctx.InChecking(e));
			ctx.SetError(PortableHtmlSchemaErorr.None, e);
			Assert.True(ctx.InChecking(e), "Full");
			ctx.Strategy = PortableHtmlVerificationStrategy.ForcedElementResult;
			e = new XElement("test");
			Assert.True(ctx.InChecking(e));
			ctx.SetError(PortableHtmlSchemaErorr.None, e);
			Assert.False(ctx.InChecking(e), "ForcedElement");
			ctx.Strategy = PortableHtmlVerificationStrategy.ForcedResult;
			e = new XElement("test");
			Assert.True(ctx.InChecking(e));
			ctx.SetError(PortableHtmlSchemaErorr.None, e);
			Assert.False(ctx.InChecking(e), "ForcedResult");
		}
Exemplo n.º 7
0
 private static void CheckNoTextElementsInlines(PortableHtmlContext context)
 {
     foreach (var e in context.SourceXml.Descendants())
     {
         if (!context.IsActive)
         {
             break;
         }
         if (!context.InChecking(e))
         {
             continue;
         }
         if (-1 != Array.IndexOf(NoTextElements, e.Name.LocalName))
         {
             foreach (var sube in e.Elements())
             {
                 if (-1 != Array.IndexOf(InlineElements, sube.Name.LocalName))
                 {
                     context.SetError(PortableHtmlSchemaErorr.InlineInNonTextElement, e);
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
		/// <summary>
		/// Проверяет наличие запрещенных атрибутов
		/// </summary>
		/// <param name="context"></param>
		private static void CheckDeprecatedAttributes(PortableHtmlContext context)
		{
			foreach (var e in context.SourceXml.DescendantsAndSelf().Where(context.InChecking))
			{
				if(!context.IsActive)break;
				foreach (var a in e.Attributes()){
					if (!context.IsActive) break;
					if(!context.InChecking(e))break;
					var state =  context.GetAttributeErrorState(a.Name.LocalName,a.Parent.Name.LocalName);
					if (state != PortableHtmlSchemaErorr.None){
						context.SetError(state, a:a);
					}					
				}
			}

		}
Exemplo n.º 9
0
		/// <summary>
		/// Проверяет наличие запрещенных атрибутов
		/// </summary>
		/// <param name="context"></param>
		private static void CheckUpperCase(PortableHtmlContext context){
			foreach (var e in context.SourceXml.DescendantsAndSelf().Where(context.InChecking))
			{
				if (e.Name.LocalName.ToLowerInvariant() != e.Name.LocalName){
					context.SetError(PortableHtmlSchemaErorr.UpperCaseDetected, e);
				}
				if (!context.InChecking(e)) continue;
				foreach (var a in e.Attributes()){
					if (a.Name.LocalName.ToLowerInvariant() != a.Name.LocalName){
						context.SetError(PortableHtmlSchemaErorr.UpperCaseDetected, a: a);
					}
				}
			}

		}
Exemplo n.º 10
0
		private static void CheckNoTextElementsInlines(PortableHtmlContext context){
			foreach (var e in context.SourceXml.Descendants()){
				if (!context.IsActive) break;
				if (!context.InChecking(e)) continue;
				if (-1 != Array.IndexOf(NoTextElements, e.Name.LocalName)){
					foreach (var sube in e.Elements()){
						if (-1 != Array.IndexOf(InlineElements, sube.Name.LocalName)){
							context.SetError(PortableHtmlSchemaErorr.InlineInNonTextElement, e);
						}
					}

				}
			}
		}
Exemplo n.º 11
0
		private static void CheckNoTextElementsText(PortableHtmlContext context)
		{
			foreach (var e in context.SourceXml.Descendants()){
				if(!context.IsActive)break;
				if(!context.InChecking(e))continue;
				if (-1 != Array.IndexOf(NoTextElements, e.Name.LocalName)){
					if (e.Nodes().OfType<XText>().Any()){
						context.SetError(PortableHtmlSchemaErorr.TextInNonTextElement,e);
					}
				}
			}
			
		}
Exemplo n.º 12
0
		private static void CheckNestedParas(PortableHtmlContext context){
			foreach (var p in context.SourceXml.Descendants()){
				if(!context.IsActive)break;
				if (!context.InChecking(p)) continue;
				if (-1 != Array.IndexOf(ParaElements, p.Name.LocalName)){
					if (p.Parent != context.SourceXml){
						context.SetError(PortableHtmlSchemaErorr.NestedParaElements, p);
					}	
				}
			}
		}
Exemplo n.º 13
0
		private static void CheckBrPosition(PortableHtmlContext context){
			var brs = context.SourceXml.Descendants("br").Where(context.InChecking).ToArray();
			foreach (var e in brs){
				if (!context.IsActive) break;
				var parentTag = e.Parent.Name.LocalName;
				if (-1 == Array.IndexOf(ContentElements, parentTag)){
					context.SetError(PortableHtmlSchemaErorr.InvalidBrPosition, e);
					if(!context.InChecking(e))continue;
				}
				if (!checkBrNeighbro(e.PreviousNode) || !checkBrNeighbro(e.NextNode))
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidBrPosition, e);
				}
			}
		}
Exemplo n.º 14
0
		private static void CheckTableSchema(PortableHtmlContext context){
			var tables = context.SourceXml.Descendants("table").Where(context.InChecking);
			var theads = context.SourceXml.Descendants("thead").Where(context.InChecking);
			var tbodies = context.SourceXml.Descendants("tbody").Where(context.InChecking);
			var trs = context.SourceXml.Descendants("tr").Where(context.InChecking);
			var tds = context.SourceXml.Descendants("td").Where(context.InChecking);
			var ths = context.SourceXml.Descendants("th").Where(context.InChecking);
			foreach (var e in ths){
				if (!context.IsActive) return;
				var p = e.Parent;
				var pp = p.Parent??new XElement("stub");
				if (p.Name.LocalName != "tr"){
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
				if (!context.InChecking(e)) continue;
				if (pp.Name.LocalName != "thead"){
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}

			}
			foreach (var e in tds)
			{
				if (!context.IsActive) return;
				var p = e.Parent;
				var pp = p.Parent ?? new XElement("stub");
				if (p.Name.LocalName != "tr")
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
				if (!context.InChecking(e)) continue;
				if (pp.Name.LocalName != "table" && pp.Name.LocalName != "tbody")
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
			}

			foreach (var e in trs)
			{
				if (!context.IsActive) return;
				var p = e.Parent;
				if (p.Name.LocalName != "table" && p.Name.LocalName!="tbody" && p.Name.LocalName!="thead")
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
				foreach (var cell in  e.Elements().Where(context.InChecking)){
					if (!context.IsActive) return;
					if (cell.Name.LocalName != "td" && cell.Name.LocalName != "th"){
						context.SetError(PortableHtmlSchemaErorr.InvalidTable, cell);	
					}
				}
			}

			foreach (var e in tbodies){
				if (!context.IsActive) return;
				if (e.Parent.Name.LocalName != "table"){
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
					if(!context.InChecking(e))continue;
				}
				if (e.ElementsAfterSelf().Any()){
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
					if (!context.InChecking(e)) continue;
				}
				var eb = e.ElementsBeforeSelf().ToArray();
				if (eb.Length>1 || (eb.Length==1 && eb[0].Name.LocalName!="thead")){
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
			}

			foreach (var e in theads)
			{
				if (!context.IsActive) return;
				if (e.Parent.Name.LocalName != "table")
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
					if (!context.InChecking(e)) continue;
				}
				if (e.ElementsBeforeSelf().Any())
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
					if (!context.InChecking(e)) continue;
				}
				var eb = e.ElementsAfterSelf().ToArray();
				if (eb.Length > 1 || (eb.Length == 1 && eb[0].Name.LocalName != "tbody"))
				{
					context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
				}
			}

			foreach (var table in tables){
				if (!context.IsActive) return;
				foreach (var t in table.Elements().Where(context.InChecking)){
					if (!context.IsActive) return;
					var tn = t.Name.LocalName;
					if (tn != "tbody" && tn != "tr" && tn != "thead"){
						context.SetError(PortableHtmlSchemaErorr.InvalidTable, t);	
					}
				}
			}
		}
Exemplo n.º 15
0
        private static void CheckTableSchema(PortableHtmlContext context)
        {
            var tables  = context.SourceXml.Descendants("table").Where(context.InChecking);
            var theads  = context.SourceXml.Descendants("thead").Where(context.InChecking);
            var tbodies = context.SourceXml.Descendants("tbody").Where(context.InChecking);
            var trs     = context.SourceXml.Descendants("tr").Where(context.InChecking);
            var tds     = context.SourceXml.Descendants("td").Where(context.InChecking);
            var ths     = context.SourceXml.Descendants("th").Where(context.InChecking);

            foreach (var e in ths)
            {
                if (!context.IsActive)
                {
                    return;
                }
                var p  = e.Parent;
                var pp = p.Parent ?? new XElement("stub");
                if (p.Name.LocalName != "tr")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
                if (!context.InChecking(e))
                {
                    continue;
                }
                if (pp.Name.LocalName != "thead")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
            }
            foreach (var e in tds)
            {
                if (!context.IsActive)
                {
                    return;
                }
                var p  = e.Parent;
                var pp = p.Parent ?? new XElement("stub");
                if (p.Name.LocalName != "tr")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
                if (!context.InChecking(e))
                {
                    continue;
                }
                if (pp.Name.LocalName != "table" && pp.Name.LocalName != "tbody")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
            }

            foreach (var e in trs)
            {
                if (!context.IsActive)
                {
                    return;
                }
                var p = e.Parent;
                if (p.Name.LocalName != "table" && p.Name.LocalName != "tbody" && p.Name.LocalName != "thead")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
                foreach (var cell in  e.Elements().Where(context.InChecking))
                {
                    if (!context.IsActive)
                    {
                        return;
                    }
                    if (cell.Name.LocalName != "td" && cell.Name.LocalName != "th")
                    {
                        context.SetError(PortableHtmlSchemaErorr.InvalidTable, cell);
                    }
                }
            }

            foreach (var e in tbodies)
            {
                if (!context.IsActive)
                {
                    return;
                }
                if (e.Parent.Name.LocalName != "table")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                    if (!context.InChecking(e))
                    {
                        continue;
                    }
                }
                if (e.ElementsAfterSelf().Any())
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                    if (!context.InChecking(e))
                    {
                        continue;
                    }
                }
                var eb = e.ElementsBeforeSelf().ToArray();
                if (eb.Length > 1 || (eb.Length == 1 && eb[0].Name.LocalName != "thead"))
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
            }

            foreach (var e in theads)
            {
                if (!context.IsActive)
                {
                    return;
                }
                if (e.Parent.Name.LocalName != "table")
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                    if (!context.InChecking(e))
                    {
                        continue;
                    }
                }
                if (e.ElementsBeforeSelf().Any())
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                    if (!context.InChecking(e))
                    {
                        continue;
                    }
                }
                var eb = e.ElementsAfterSelf().ToArray();
                if (eb.Length > 1 || (eb.Length == 1 && eb[0].Name.LocalName != "tbody"))
                {
                    context.SetError(PortableHtmlSchemaErorr.InvalidTable, e);
                }
            }

            foreach (var table in tables)
            {
                if (!context.IsActive)
                {
                    return;
                }
                foreach (var t in table.Elements().Where(context.InChecking))
                {
                    if (!context.IsActive)
                    {
                        return;
                    }
                    var tn = t.Name.LocalName;
                    if (tn != "tbody" && tn != "tr" && tn != "thead")
                    {
                        context.SetError(PortableHtmlSchemaErorr.InvalidTable, t);
                    }
                }
            }
        }