2 using System.Collections;
3 using System.Collections.Specialized;
5 using System.Xml.Schema;
6 using Commons.Xml.Relaxng;
8 //using Map = Commons.Xml.Relaxng.ObjectMapping.RelaxngMapping;
9 //using Choice = Commons.Xml.Relaxng.ObjectMapping.RelaxngMappingChoice;
11 namespace Commons.Xml.Nvdl
15 public const string Namespace = "http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0";
16 public const string BuiltInValidationNamespace = "http://purl.oclc.org/dsdl/nvdl/ns/predefinedSchema/1.0";
18 public const string InstanceNamespace = "http://purl.oclc.org/dsdl/nvdl/ns/instance/1.0";
20 internal const string XmlNamespaceUri = "http://www.w3.org/xml/1998/namespace";
22 private static void OnDefaultEvent (object o,
23 NvdlMessageEventArgs e)
25 Console.WriteLine (e.Message);
28 public static NvdlMessageEventHandler HandlePrintMessage =
29 new NvdlMessageEventHandler (OnDefaultEvent);
31 readonly static NvdlConfig defaultConfig;
35 defaultConfig = new NvdlConfig ();
36 defaultConfig.AddProvider (new NvdlXsdValidatorProvider ());
37 defaultConfig.AddProvider (new NvdlRelaxngValidatorProvider ());
40 internal static NvdlConfig DefaultConfig {
41 get { return defaultConfig; }
44 internal static readonly char [] Whitespaces =
45 new char [] {' ', '\r', '\n', '\t'};
48 public static bool NSMatches (string n1, int i1, string w1,
49 string n2, int i2, string w2)
56 if (n1.Length <= i1 && n2.Length <= i2)
59 if (n1.Length <= i1 && n2 == w2 ||
60 n2.Length <= i2 && n1 == w1)
63 if (n1.Length > i1 && n2.Length > i2 &&
65 (w1.Length == 0 || n1 [i1] != w1 [0]) &&
66 (w2.Length == 0 || n2 [i2] != w2 [0]) &&
67 NSMatches (n1, i1 + 1, w1, n2, i2 + 1, w2))
71 n1.Length > i1 && n1 [i1] == w1 [0] &&
72 NSMatches (n1, i1, w1, n2, i2 + 1, w2))
76 n2.Length > i2 && n2 [i2] == w2 [0] &&
77 NSMatches (n1, i1 + 1, w1, n2, i2, w2))
83 public class NvdlMessageEventArgs : EventArgs
87 public NvdlMessageEventArgs (string message)
89 this.message = message;
92 public string Message {
93 get { return message; }
97 public delegate void NvdlMessageEventHandler (object o, NvdlMessageEventArgs e);
99 public class NvdlElementBase : IXmlLineInfo
104 public int LineNumber {
106 set { line = value; }
109 public int LinePosition {
110 get { return column; }
111 set { column = value; }
114 public bool HasLineInfo ()
116 return line > 0 && column > 0;
119 public string SourceUri {
120 get { return sourceUri; }
121 set { sourceUri = value; }
125 public class NvdlAttributable : NvdlElementBase
127 ArrayList foreign = new ArrayList ();
129 public ArrayList Foreign {
130 get { return foreign; }
138 (rule* | (attribute startMode { xsd:NCName }, mode+)))
142 public class NvdlRules : NvdlAttributable
145 NvdlTriggerList triggers = new NvdlTriggerList ();
146 NvdlRuleList rules = new NvdlRuleList ();
147 NvdlModeList modes = new NvdlModeList ();
152 public string SchemaType {
153 get { return schemaType; }
154 set { schemaType = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
158 public NvdlTriggerList Triggers {
159 get { return triggers; }
163 public NvdlRuleList Rules {
164 get { return rules; }
168 // [MapType ("NCName", XmlSchema.Namespace)]
169 public string StartMode {
170 get { return startMode; }
171 set { startMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
175 public NvdlModeList Modes {
176 get { return modes; }
182 (attribute ns { xsd:string },
183 attribute name { xsd:NCName })
187 public class NvdlTrigger : NvdlAttributable
199 // [MapType ("NCName", XmlSchema.Namespace)]
202 set { name = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
208 (attribute name { xsd:NCName },
214 public abstract class NvdlModeBase : NvdlAttributable
216 NvdlModeList includedModes = new NvdlModeList ();
217 NvdlRuleList rules = new NvdlRuleList ();
220 public NvdlModeList IncludedModes {
221 get { return includedModes; }
225 public NvdlRuleList Rules {
226 get { return rules; }
230 public class NvdlNestedMode : NvdlModeBase
234 public class NvdlMode : NvdlModeBase
239 // [MapType ("NCName", XmlSchema.Namespace)]
242 set { name = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
246 public class NvdlIncludedMode : NvdlModeBase
252 // [MapType ("NCName", XmlSchema.Namespace)]
255 set { name = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
259 public enum NvdlRuleTarget {
266 public abstract class NvdlRule : NvdlAttributable
268 NvdlRuleTarget match;
269 NvdlActionList actions = new NvdlActionList ();
271 public NvdlRuleTarget Match {
272 get { return match; }
273 set { match = value; }
276 public NvdlActionList Actions {
277 get { return actions; }
283 (attribute ns { xsd:string },
284 attribute wildcard {xsd:string{maxLength = "1"}}?,
289 public class NvdlNamespace : NvdlRule
301 public string Wildcard {
302 get { return wildcard; }
304 if (value != null && value.Length > 1)
305 throw new ArgumentException ("wildcard attribute can contain at most one character.");
312 element anyNamespace { ruleModel & foreign}
314 public class NvdlAnyNamespace : NvdlRule
318 public abstract class NvdlAction : NvdlAttributable
323 element cancelNestedActions {foreign}
325 public class NvdlCancelAction : NvdlAction
329 public abstract class NvdlNoCancelAction : NvdlAction
331 NvdlModeUsage modeUsage;
333 NvdlMessageList messages = new NvdlMessageList ();
335 public NvdlModeUsage ModeUsage {
336 get { return modeUsage; }
337 set { modeUsage = value; }
340 public string SimpleMessage {
341 get { return messageAttr; }
342 set { messageAttr = value; }
345 public NvdlMessageList Messages {
346 get { return messages; }
350 public abstract class NvdlNoResultAction : NvdlNoCancelAction
354 public enum NvdlResultType {
360 public abstract class NvdlResultAction : NvdlNoCancelAction
362 public abstract NvdlResultType ResultType { get; }
365 public class NvdlAttach : NvdlResultAction
367 public override NvdlResultType ResultType {
368 get { return NvdlResultType.Attach; }
372 public class NvdlAttachPlaceHolder : NvdlResultAction
374 public override NvdlResultType ResultType {
375 get { return NvdlResultType.AttachPlaceHolder; }
379 public class NvdlUnwrap : NvdlResultAction
381 public override NvdlResultType ResultType {
382 get { return NvdlResultType.Unwrap; }
395 attribute schema { xsd:anyURI } |
396 element schema {(text | foreignElement), foreignAttribute*}
398 public class NvdlValidate : NvdlNoResultAction
401 NvdlOptionList options = new NvdlOptionList ();
403 XmlElement schemaBody;
406 // [MapType ("NCName", XmlSchema.Namespace)]
407 public string SchemaType {
408 get { return schemaType; }
409 set { schemaType = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
412 public NvdlOptionList Options {
413 get { return options; }
416 // [MapType ("anyURI", XmlSchema.Namespace)]
417 public string SchemaUri {
418 get { return schemaUri; }
419 set { schemaUri = value; }
422 public XmlElement SchemaBody {
423 get { return schemaBody; }
424 set { schemaBody = value; }
428 public class NvdlAllow : NvdlNoResultAction
432 public class NvdlReject : NvdlNoResultAction
436 public class NvdlMessage : NvdlElementBase
440 ArrayList foreignAttributes = new ArrayList ();
444 set { text = value; }
447 public string XmlLang {
448 get { return xmlLang; }
449 set { xmlLang = value; }
452 public ArrayList ForeignAttributes {
453 get { return foreignAttributes; }
457 public class NvdlOption : NvdlAttributable
465 set { name = value; }
473 public string MustSupport {
474 get { return mustSupport; }
475 set { mustSupport = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
480 (attribute useMode { xsd:NCName } | nestedMode)?,
482 (attribute path { path },
483 (attribute useMode { xsd:NCName } | nestedMode)?)
487 public class NvdlModeUsage
490 NvdlNestedMode nestedMode;
491 NvdlContextList contexts = new NvdlContextList ();
493 public string UseMode {
494 get { return useMode; }
495 set { useMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
498 public NvdlNestedMode NestedMode {
499 get { return nestedMode; }
500 set { nestedMode = value; }
503 public NvdlContextList Contexts {
504 get { return contexts; }
508 public class NvdlContext : NvdlAttributable
512 NvdlNestedMode nestedMode;
516 set { path = value; }
519 public string UseMode {
520 get { return useMode; }
521 set { useMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
524 public NvdlNestedMode NestedMode {
525 get { return nestedMode; }
526 set { nestedMode = value; }
530 public class NvdlTriggerList : CollectionBase
532 public NvdlTrigger this [int i] {
533 get { return (NvdlTrigger) List [i]; }
534 set { List [i] = (NvdlTrigger) value; }
537 public void Add (NvdlTrigger item)
542 public void Remove (NvdlTrigger item)
548 public class NvdlRuleList : CollectionBase
550 public NvdlRule this [int i] {
551 get { return (NvdlRule) List [i]; }
552 set { List [i] = (NvdlRule) value; }
555 public void Add (NvdlRule item)
560 public void Remove (NvdlRule item)
566 public class NvdlModeList : CollectionBase
568 public NvdlModeBase this [int i] {
569 get { return (NvdlModeBase) List [i]; }
570 set { List [i] = (NvdlModeBase) value; }
573 public void Add (NvdlModeBase item)
578 public void Remove (NvdlModeBase item)
584 public class NvdlContextList : CollectionBase
586 public NvdlContext this [int i] {
587 get { return (NvdlContext) List [i]; }
588 set { List [i] = (NvdlContext) value; }
591 public void Add (NvdlContext item)
596 public void Remove (NvdlContext item)
602 public class NvdlActionList : CollectionBase
604 public NvdlAction this [int i] {
605 get { return (NvdlAction) List [i]; }
606 set { List [i] = (NvdlAction) value; }
609 public void Add (NvdlAction item)
614 public void Remove (NvdlAction item)
620 public class NvdlOptionList : CollectionBase
622 public NvdlOption this [int i] {
623 get { return (NvdlOption) List [i]; }
624 set { List [i] = (NvdlOption) value; }
627 public void Add (NvdlOption item)
632 public void Remove (NvdlOption item)
638 public class NvdlMessageList : CollectionBase
640 public NvdlMessage this [int i] {
641 get { return (NvdlMessage) List [i]; }
642 set { List [i] = (NvdlMessage) value; }
645 public void Add (NvdlMessage item)
650 public void Remove (NvdlMessage item)