public NvdlValidatorGenerator GetGenerator(NvdlValidate validate, string inheritSchemaType) { this.resolver = this.XmlResolverInternal; string schemaType = validate.SchemaType; if (schemaType == null) { schemaType = inheritSchemaType; } if (schemaType == null) { schemaType = "application/xml"; } foreach (NvdlValidationProvider p in providers) { NvdlValidatorGenerator g = p.CreateGenerator(validate, schemaType, this); if (g != null) { return(g); } } throw new NvdlCompileException(String.Format("Either schema type '{0}' or the target schema document is not supported in this configuration. Add custom provider that supports this schema type.", schemaType), validate); }
public override NvdlValidatorGenerator CreateGenerator ( NvdlValidate validate, string schemaType, NvdlConfig config) { if (schemaType == RncMimeType) return CreateRncGenerator (validate, config); return base.CreateGenerator (validate, schemaType, config); }
public override NvdlValidatorGenerator CreateGenerator( NvdlValidate validate, string schemaType, NvdlConfig config) { if (schemaType == RncMimeType) { return(CreateRncGenerator(validate, config)); } return(base.CreateGenerator(validate, schemaType, config)); }
public SimpleValidate( NvdlValidate validate, NvdlCompileContext ctx) : base(validate) { // 6.4.7 generator = ctx.Config.GetGenerator(validate, ctx.Rules.SchemaType); }
public string GetSchemaUri (NvdlValidate validate) { if (validate.SchemaUri != null) return validate.SchemaUri; if (validate.SchemaBody == null) return null; for (XmlNode n = validate.SchemaBody.FirstChild; n != null; n = n.NextSibling) if (n.NodeType == XmlNodeType.Element) return null; // not a URI return validate.SchemaBody.InnerText; }
public virtual NvdlValidatorGenerator CreateGenerator(NvdlValidate validate, string schemaType, NvdlConfig config) { this.validate = validate; this.schema_type = schemaType; this.config = config; XmlReader schema = null; // FIXME: we need a bit more strict check. if (schemaType.Length < 5 || !schemaType.EndsWith("xml") || Char.IsLetter(schemaType, schemaType.Length - 4)) { return(null); } string schemaUri = validate.SchemaUri; XmlElement schemaBody = validate.SchemaBody; if (schemaUri != null) { if (schemaBody != null) { throw new NvdlCompileException("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate); } schema = GetSchemaXmlStream(schemaUri, config, validate); } else if (validate.SchemaBody != null) { XmlReader r = new XmlNodeReader(schemaBody); r.MoveToContent(); r.Read(); // Skip "schema" element r.MoveToContent(); if (r.NodeType == XmlNodeType.Element) { schema = r; } else { schema = GetSchemaXmlStream(r.ReadString(), config, validate); } } if (schema == null) { return(null); } return(CreateGenerator(schema, config)); }
private NvdlValidatorGenerator CreateRncGenerator (NvdlValidate validate, NvdlConfig config) { XmlResolver resolver = config.XmlResolverInternal; string schemaUri = GetSchemaUri (validate); if (schemaUri == null) return null; Uri baseUri = resolver.ResolveUri (null, validate.SourceUri); Uri absUri = resolver.ResolveUri (baseUri, schemaUri); RelaxngPattern p = RncParser.ParseRnc ( new StreamReader ((Stream) resolver.GetEntity ( absUri, null, typeof (Stream))), null, absUri.ToString ()); return new NvdlRelaxngValidatorGenerator (p, config); }
private static XmlReader GetSchemaXmlStream (string schemaUri, NvdlConfig config, NvdlValidate validate) { XmlResolver r = config.XmlResolverInternal; if (r == null) return null; Uri baseUri = r.ResolveUri (null, validate.SourceUri); Uri uri = r.ResolveUri (baseUri, validate.SchemaUri); Stream stream = (Stream) r.GetEntity ( uri, null, typeof (Stream)); if (stream == null) return null; XmlTextReader xtr = new XmlTextReader (uri != null ? uri.ToString () : String.Empty, stream); xtr.XmlResolver = r; xtr.MoveToContent (); return xtr; }
static NvdlValidate CreateBuiltInValidate(NvdlAction a) { bool allow = a is NvdlAllow; NvdlValidate v = new NvdlValidate(); v.SourceUri = a.SourceUri; v.LineNumber = a.LineNumber; v.LinePosition = a.LinePosition; v.ModeUsage = new NvdlModeUsage(); var doc = new XDocument(); var el = new XElement(XNamespace.Get(Nvdl.BuiltInValidationNamespace).GetName(allow ? "allow" : "reject")); doc.Add(new XElement(XNamespace.Get(Nvdl.Namespace).GetName("schema"))); doc.Root.Add(el); v.SchemaBody = doc.Root; return(v); }
public string GetSchemaUri(NvdlValidate validate) { if (validate.SchemaUri != null) { return(validate.SchemaUri); } if (validate.SchemaBody == null) { return(null); } for (var n = validate.SchemaBody.FirstNode; n != null; n = n.NextNode) { if (n.NodeType == XmlNodeType.Element) { return(null); // not a URI } } return(validate.SchemaBody.Value); }
private NvdlValidatorGenerator CreateRncGenerator(NvdlValidate validate, NvdlConfig config) { XmlResolver resolver = config.XmlResolverInternal; string schemaUri = GetSchemaUri(validate); if (schemaUri == null) { return(null); } Uri baseUri = resolver.ResolveUri(null, validate.SourceUri); Uri absUri = resolver.ResolveUri(baseUri, schemaUri); RelaxngPattern p = RncParser.ParseRnc( new StreamReader((Stream)resolver.GetEntity( absUri, null, typeof(Stream))), null, absUri.ToString()); return(new NvdlRelaxngValidatorGenerator(p, config)); }
public string GetSchemaUri(NvdlValidate validate) { if (validate.SchemaUri != null) { return(validate.SchemaUri); } if (validate.SchemaBody == null) { return(null); } for (XmlNode n = validate.SchemaBody.FirstChild; n != null; n = n.NextSibling) { if (n.NodeType == XmlNodeType.Element) { return(null); // not a URI } } return(validate.SchemaBody.InnerText); }
public NvdlValidatorGenerator GetGenerator (NvdlValidate validate, string inheritSchemaType) { this.resolver = this.XmlResolverInternal; string schemaType = validate.SchemaType; if (schemaType == null) schemaType = inheritSchemaType; if (schemaType == null) schemaType = "application/xml"; foreach (NvdlValidationProvider p in providers) { NvdlValidatorGenerator g = p.CreateGenerator (validate, schemaType, this); if (g != null) return g; } throw new NvdlCompileException (String.Format ("Either schema type '{0}' or the target schema document is not supported in this configuration. Add custom provider that supports this schema type.", schemaType), validate); }
static NvdlValidate CreateBuiltInValidate(NvdlAction a) { bool allow = a is NvdlAllow; NvdlValidate v = new NvdlValidate(); v.SourceUri = a.SourceUri; v.LineNumber = a.LineNumber; v.LinePosition = a.LinePosition; v.ModeUsage = new NvdlModeUsage(); XmlDocument doc = new XmlDocument(); XmlElement el = doc.CreateElement( allow ? "allow" : "reject", Nvdl.BuiltInValidationNamespace); doc.AppendChild(doc.CreateElement("schema", Nvdl.Namespace)); doc.DocumentElement.AppendChild(el); v.SchemaBody = doc.DocumentElement; return(v); }
public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig config) { this.validate = validate; this.schema_type = schemaType; this.config = config; XmlReader schema = null; // FIXME: we need a bit more strict check. if (schemaType.Length < 5 || !schemaType.EndsWith ("xml") || Char.IsLetter (schemaType, schemaType.Length - 4)) return null; string schemaUri = validate.SchemaUri; XmlElement schemaBody = validate.SchemaBody; if (schemaUri != null) { if (schemaBody != null) throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate); schema = GetSchemaXmlStream (schemaUri, config, validate); } else if (validate.SchemaBody != null) { XmlReader r = new XmlNodeReader (schemaBody); r.MoveToContent (); r.Read (); // Skip "schema" element r.MoveToContent (); if (r.NodeType == XmlNodeType.Element) schema = r; else schema = GetSchemaXmlStream (r.ReadString (), config, validate); } if (schema == null) return null; return CreateGenerator (schema, config); }
static NvdlValidate CreateBuiltInValidate (NvdlAction a) { bool allow = a is NvdlAllow; NvdlValidate v = new NvdlValidate (); v.SourceUri = a.SourceUri; v.LineNumber = a.LineNumber; v.LinePosition = a.LinePosition; v.ModeUsage = new NvdlModeUsage (); XmlDocument doc = new XmlDocument (); XmlElement el = doc.CreateElement ( allow ? "allow" : "reject", Nvdl.BuiltInValidationNamespace); doc.AppendChild (doc.CreateElement ("schema", Nvdl.Namespace)); doc.DocumentElement.AppendChild (el); v.SchemaBody = doc.DocumentElement; return v; }
private static XmlReader GetSchemaXmlStream(string schemaUri, NvdlConfig config, NvdlValidate validate) { XmlResolver r = config.XmlResolverInternal; if (r == null) { return(null); } Uri baseUri = r.ResolveUri(null, validate.SourceUri); Uri uri = r.ResolveUri(baseUri, validate.SchemaUri); Stream stream = (Stream)r.GetEntity( uri, null, typeof(Stream)); if (stream == null) { return(null); } XmlTextReader xtr = new XmlTextReader(uri != null ? uri.ToString() : String.Empty, stream); xtr.XmlResolver = r; xtr.MoveToContent(); return(xtr); }
private NvdlValidate ReadValidate() { NvdlValidate el = new NvdlValidate(); NvdlModeUsage mu = new NvdlModeUsage(); el.ModeUsage = mu; FillLocation(el); el.SchemaType = reader.GetAttribute("schemaType"); el.SimpleMessage = reader.GetAttribute("message"); el.SchemaUri = reader.GetAttribute("schema"); mu.UseMode = reader.GetAttribute("useMode"); FillForeignAttribute(el); if (reader.IsEmptyElement) { reader.Skip(); return(el); } reader.Read(); do { reader.MoveToContent(); if (reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NamespaceURI != Nvdl.Namespace) { el.Foreign.Add(XDocument.ReadFrom(reader)); continue; } switch (reader.LocalName) { case "message": el.Messages.Add(ReadMessage()); break; case "option": el.Options.Add(ReadOption()); break; case "schema": el.SchemaBody = (XElement)XDocument.ReadFrom(reader); break; case "mode": mu.NestedMode = ReadNestedMode(); break; case "context": mu.Contexts.Add(ReadContext()); break; default: throw new NotSupportedException(); } } while (!reader.EOF); if (!reader.EOF) { reader.Read(); } return(el); }
public SimpleValidate ( NvdlValidate validate, NvdlCompileContext ctx) : base (validate) { // 6.4.7 generator = ctx.Config.GetGenerator (validate, ctx.Rules.SchemaType); }
private NvdlValidate ReadValidate () { NvdlValidate el = new NvdlValidate (); NvdlModeUsage mu = new NvdlModeUsage (); el.ModeUsage = mu; FillLocation (el); el.SchemaType = reader.GetAttribute ("schemaType"); el.SimpleMessage = reader.GetAttribute ("message"); el.SchemaUri = reader.GetAttribute ("schema"); mu.UseMode = reader.GetAttribute ("useMode"); FillForeignAttribute (el); if (reader.IsEmptyElement) { reader.Skip (); return el; } reader.Read (); do { reader.MoveToContent (); if (reader.NodeType == XmlNodeType.EndElement) break; if (reader.NamespaceURI != Nvdl.Namespace) { el.Foreign.Add (doc.ReadNode (reader)); continue; } switch (reader.LocalName) { case "message": el.Messages.Add (ReadMessage ()); break; case "option": el.Options.Add (ReadOption ()); break; case "schema": el.SchemaBody = (XmlElement) doc.ReadNode (reader); break; case "mode": mu.NestedMode = ReadNestedMode (); break; case "context": mu.Contexts.Add (ReadContext ()); break; default: throw new NotSupportedException (); } } while (!reader.EOF); if (!reader.EOF) reader.Read (); return el; }