+2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
+
+ * README :
+ more description.
+ * NvdlBuiltInValidationProvider.cs :
+ When it is "allow", it should not always return false.
+ * NvdlFilteredXmlReader.cs :
+ Added support for PlanAtt validation.
+ * NvdlConfig.cs :
+ Removed unused code.
+ * NvdlSimplified.cs :
+ Attribute default rule is "attach", not "allow". Removed unused
+ code. Added attribute validation support.
+ * NvdlValidationProvider.cs :
+ Extended MIME type check to "*/*-xml" (not only text/xml).
+ Added CreateAttributeValidator() method for "schema rewriting for
+ attribute sections" support (FCD spec 8.7.3).
+
2005-03-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : code refactory.
public override bool Read ()
{
- if (Reader.Read () && !allow)
+ if (!Reader.Read ())
+ return false;
+ if (!allow)
throw new NvdlValidationException (String.Format ("The NVDL script does not allow an element whose namespace is '{0}'", Reader.NamespaceURI), Reader as IXmlLineInfo);
- return false;
+ return true;
}
}
}
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 virtual NvdlValidatorGenerator GetGenerator (string mimeType, string schemaAttribute, XmlElement schemaElement, NvdlValidate validate)
- {
- XmlReader schemaReader = null;
- if (schemaType == "text/xml") {
- if (schemaAttribute != null) {
- if (schemaElement != null)
- throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
- return GetSchemaXmlStream (schemaUri, config, validate);
- else if (validate.SchemaBody != null) {
- XmlReader r = new XmlNodeReader (validate.SchemaBody);
- r.MoveToContent ();
- r.Read (); // Skip "schema" element
- r.MoveToContent ();
- if (r.NodeType == XmlNodeType.Element)
- return r;
- else
- return GetSchemaXmlStream (r.ReadString (), config, validate);
- }
- else
- return null;
- }
- else
- throw new NvdlCompileException (String.Format ("Either MIME type '{0}' or the target schema document is not supported.", schemaType), validate);
-
- schemaReader.MoveToContent ();
-
- NvdlValidationProvider provider =
- ctx.Config.GetProvider (schemaReader.NamespaceURI);
-
- generator = provider.CreateGenerator (schemaReader, ctx.Config.XmlResolverInternal);
-
- foreach (NvdlOption option in validate.Options) {
- bool mustSupport = option.MustSupport != null ?
- XmlConvert.ToBoolean (option.MustSupport) : false;
- if (!generator.AddOption (option.Name,
- option.Arg) && mustSupport)
- throw new NvdlCompileException (String.Format ("Option '{0}' with argument '{1}' is not supported for schema type '{2}'.",
- option.Name, option.Arg,
- schemaType), validate);
- }
- }
-
- public static XmlReader GetSchemaXmlStream (string schemaUri, NvdlConfig config, NvdlValidate validate)
- {
- XmlResolver r = config.Resolver;
- if (r == null)
- return null;
- Uri uri = r.ResolveUri (null, validate.schemaUri);
- 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 bool ElementHasElementChild (XmlElement el)
- {
- foreach (XmlNode n in el.ChildNodes)
- if (n.NodeType == XmlNodeType.Element)
- return true;
- return false;
- }
-*/
}
}
namespace Commons.Xml.Nvdl
{
+#if false
+ internal class NvdlFilteredXmlReader : XmlDefaultReader
+ {
+ public NvdlFilteredXmlReader (XmlReader reader,
+ NvdlValidateInterp validate)
+ : base (reader)
+ {
+ }
+
+ public bool Read ()
+ {
+ return !Reader.EOF;
+ }
+
+ public void AttachPlaceHolder ()
+ {
+ }
+
+ public void DetachPlaceHolder ()
+ {
+ }
+ }
+#else
internal class NvdlFilteredXmlReader : XmlReader
{
int placeHolderDepth = -1;
AttributeInfo [] attributes = new AttributeInfo [10];
int attributeCount;
+ // PlanAtt validation cache.
+ Hashtable attributeValidators = new Hashtable ();
+
class AttributeInfo
{
public string LocalName;
if (reader.EOF)
return false;
+ MoveToElement ();
+ attributeCount = 0;
+
if (nextPlaceHolder != XmlNodeType.None) {
placeHolder = nextPlaceHolder;
nextPlaceHolder = XmlNodeType.None;
return true;
}
- MoveToElement ();
- attributeCount = 0;
-
if (!reader.MoveToFirstAttribute ())
return true;
+
+ // Attribute rule application
+ attributeValidators.Clear ();
do {
- if (reader.NamespaceURI == String.Empty) {
- AddAttribute ();
- continue;
- }
+ // FIXME: could be more efficient
SimpleRule rule = FindAttributeRule (
reader.NamespaceURI,
validate.CreatedMode);
AddAttribute ();
if (ra != null)
continue;
- // FIXME: validate global attribute (PlanAtt).
- SimpleValidate v = a as SimpleValidate;
+ attributeValidators [reader.NamespaceURI] = a;
}
} while (reader.MoveToNextAttribute ());
reader.MoveToElement ();
+
+ if (attributeValidators.Count > 0) {
+ foreach (string ns in attributeValidators.Keys) {
+ ((SimpleValidate) attributeValidators [
+ ns]).ValidateAttributes (reader, ns);
+ }
+ }
+
return true;
}
}
}
}
+#endif
}
ann.LineNumber = this.LineNumber;
ann.LinePosition = this.LinePosition;
- NvdlAllow allow = new NvdlAllow ();
- allow.SourceUri = this.SourceUri;
- allow.LineNumber = this.LineNumber;
- allow.LinePosition = this.LinePosition;
+ NvdlAttach attach = new NvdlAttach ();
+ attach.SourceUri = this.SourceUri;
+ attach.LineNumber = this.LineNumber;
+ attach.LinePosition = this.LinePosition;
ann.Match = NvdlRuleTarget.Attributes;
- ann.Actions.Add (allow);
+ ann.Actions.Add (attach);
al.Add (new SimpleRule (ann, true, ctx));
}
// 6.4.7
generator = ctx.Config.GetGenerator (validate,
ctx.Rules.SchemaType);
-/*
- this.resolver = ctx.Config.XmlResolverInternal;
-
- // 6.4.7
- string schemaType = validate.SchemaType;
- if (schemaType == null)
- schemaType = ctx.Rules.SchemaType;
- if (schemaType == null && validate.SchemaBody != null && !ElementHasElementChild (validate.SchemaBody))
- schemaType = validate.SchemaBody.InnerText;
- if (schemaType == null)
- schemaType = "text/xml";
-
- // FIXME: this part must be totally rewritten.
-
- XmlReader schemaReader = null;
- if (schemaType == "text/xml") {
- if (validate.SchemaUri != null) {
- if (validate.SchemaBody != null)
- throw new NvdlCompileException ("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
- // FIXME: use NvdlConfig
- schemaReader = new XmlTextReader (validate.SchemaUri);
- }
- else if (validate.SchemaBody != null) {
- schemaReader = new XmlNodeReader (validate.SchemaBody);
- schemaReader.MoveToContent ();
- schemaReader.Read (); // Skip "schema" element
- }
- else
- throw new NvdlCompileException ("Neither 'schema' attribute nor 'schema' element is specified in a 'validate' element.", validate);
- }
- else
- throw new NvdlCompileException (String.Format ("MIME type '{0}' is not supported at this moment.", schemaType), validate);
-
- schemaReader.MoveToContent ();
-
- NvdlValidationProvider provider =
- ctx.Config.GetProvider (schemaReader.NamespaceURI);
-
- if (provider == null)
- throw new NvdlCompileException (String.Format ("Schema type '{0}' is not supported in this configuration. Use custom provider that supports this schema type.", schemaType), validate);
-
- generator = provider.CreateGenerator (schemaReader, ctx.Config.XmlResolverInternal);
-
- foreach (NvdlOption option in validate.Options) {
- bool mustSupport = option.MustSupport != null ?
- XmlConvert.ToBoolean (option.MustSupport) : false;
- if (!generator.AddOption (option.Name,
- option.Arg) && mustSupport)
- throw new NvdlCompileException (String.Format ("Option '{0}' with argument '{1}' is not supported for schema type '{2}'.",
- option.Name, option.Arg,
- schemaType), validate);
- }
-*/
}
internal NvdlValidatorGenerator Generator {
{
return generator.CreateValidator (reader, resolver);
}
+
+ public void ValidateAttributes (XmlReader reader, string ns)
+ {
+ XmlDocument doc = new XmlDocument ();
+ XmlElement el = doc.CreateElement ("virtualElement",
+ Nvdl.PlaceHolderNamespace);
+ for (int i = 0; i < reader.AttributeCount; i++) {
+ reader.MoveToAttribute (i);
+ if (reader.NamespaceURI != ns)
+ continue;
+ el.SetAttribute (reader.LocalName,
+ reader.NamespaceURI, reader.Value);
+ }
+ reader.MoveToElement ();
+ XmlReader r = generator.CreateAttributeValidator (
+ new XmlNodeReader (el), resolver);
+ while (!r.EOF)
+ r.Read ();
+ }
}
internal class SimpleResultAction : SimpleAction
public virtual NvdlValidatorGenerator CreateGenerator (NvdlValidate validate, string schemaType, NvdlConfig 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;
{
// 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);
}