New test.
[mono.git] / mcs / class / Commons.Xml.Relaxng / Commons.Xml.Nvdl / NvdlValidationProvider.cs
old mode 100755 (executable)
new mode 100644 (file)
index 3f46033..0501b0e
@@ -8,10 +8,21 @@ namespace Commons.Xml.Nvdl
 {
        public class NvdlValidationProvider
        {
+               NvdlValidate validate;
+               string schema_type;
+               NvdlConfig config;
+
                public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig config)
                {
+                       this.validate = validate;
+                       this.schema_type = schemaType;
+                       this.config = config;
+
                        XmlReader schema = null;
-                       if (schemaType != "text/xml")
+                       // 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;
@@ -39,6 +50,18 @@ namespace Commons.Xml.Nvdl
                        return CreateGenerator (schema, config);
                }
 
+               public NvdlValidate ValidateAction {
+                       get { return validate; }
+               }
+
+               public NvdlConfig Config {
+                       get { return config; }
+               }
+
+               public string SchemaType {
+                       get { return schema_type; }
+               }
+
                public virtual NvdlValidatorGenerator CreateGenerator (XmlReader schema, NvdlConfig config)
                {
                        return null;
@@ -61,7 +84,8 @@ namespace Commons.Xml.Nvdl
                        XmlResolver r = config.XmlResolverInternal;
                        if (r == null)
                                return null;
-                       Uri uri = r.ResolveUri (null, validate.SchemaUri);
+                       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)
@@ -77,8 +101,21 @@ namespace Commons.Xml.Nvdl
        {
                // creates individual validator with schema
                // (which should be provided in derived constructor).
-               public abstract XmlReader CreateValidator (XmlReader reader, XmlResolver resolver);
+               public abstract XmlReader CreateValidator (XmlReader reader, 
+                       XmlResolver resolver);
+
+               public virtual XmlReader CreateAttributeValidator (
+                       XmlReader reader,
+                       XmlResolver resolver)
+               {
+                       throw new NotSupportedException ();
+               }
 
                public abstract bool AddOption (string name, string arg);
+
+               public virtual bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
+               {
+                       return false;
+               }
        }
 }