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
17 public const string Namespace = "http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0";
18 public const string BuiltInValidationNamespace = "http://purl.oclc.org/dsdl/nvdl/ns/predefinedSchema/1.0";
20 public const string InstanceNamespace = "http://purl.oclc.org/dsdl/nvdl/ns/instance/1.0";
22 internal const string XmlNamespaceUri = "http://www.w3.org/xml/1998/namespace";
24 private static void OnDefaultEvent (object o,
25 NvdlMessageEventArgs e)
27 Console.WriteLine (e.Message);
30 internal static NvdlMessageEventHandler HandlePrintMessage =
31 new NvdlMessageEventHandler (OnDefaultEvent);
33 readonly static NvdlConfig defaultConfig;
37 defaultConfig = new NvdlConfig ();
38 defaultConfig.AddProvider (new NvdlXsdValidatorProvider ());
39 defaultConfig.AddProvider (new NvdlRelaxngValidatorProvider ());
42 internal static NvdlConfig DefaultConfig {
43 get { return defaultConfig; }
46 internal static readonly char [] Whitespaces =
47 new char [] {' ', '\r', '\n', '\t'};
50 internal static bool NSMatches (string n1, int i1, string w1,
51 string n2, int i2, string w2)
58 if (n1.Length <= i1 && n2.Length <= i2)
61 if (n1.Length <= i1 && n2 == w2 ||
62 n2.Length <= i2 && n1 == w1)
65 if (n1.Length > i1 && n2.Length > i2 &&
67 (w1.Length == 0 || n1 [i1] != w1 [0]) &&
68 (w2.Length == 0 || n2 [i2] != w2 [0]) &&
69 NSMatches (n1, i1 + 1, w1, n2, i2 + 1, w2))
73 n1.Length > i1 && n1 [i1] == w1 [0] &&
74 NSMatches (n1, i1, w1, n2, i2 + 1, w2))
78 n2.Length > i2 && n2 [i2] == w2 [0] &&
79 NSMatches (n1, i1 + 1, w1, n2, i2, w2))
85 public class NvdlMessageEventArgs : EventArgs
89 public NvdlMessageEventArgs (string message)
91 this.message = message;
94 public string Message {
95 get { return message; }
99 public delegate void NvdlMessageEventHandler (object o, NvdlMessageEventArgs e);
101 public class NvdlElementBase : IXmlLineInfo
106 public int LineNumber {
108 set { line = value; }
111 public int LinePosition {
112 get { return column; }
113 set { column = value; }
116 public bool HasLineInfo ()
118 return line > 0 && column > 0;
121 public string SourceUri {
122 get { return sourceUri; }
123 set { sourceUri = value; }
127 public class NvdlAttributable : NvdlElementBase
129 ArrayList foreign = new ArrayList ();
131 public ArrayList Foreign {
132 get { return foreign; }
140 (rule* | (attribute startMode { xsd:NCName }, mode+)))
144 public class NvdlRules : NvdlAttributable
147 NvdlTriggerList triggers = new NvdlTriggerList ();
148 NvdlRuleList rules = new NvdlRuleList ();
149 NvdlModeList modes = new NvdlModeList ();
154 public string SchemaType {
155 get { return schemaType; }
156 set { schemaType = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
160 public NvdlTriggerList Triggers {
161 get { return triggers; }
165 public NvdlRuleList Rules {
166 get { return rules; }
170 // [MapType ("NCName", XmlSchema.Namespace)]
171 public string StartMode {
172 get { return startMode; }
173 set { startMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
177 public NvdlModeList Modes {
178 get { return modes; }
184 (attribute ns { xsd:string },
185 attribute nameList { list { xsd:NCName } })
189 public class NvdlTrigger : NvdlAttributable
202 public string NameList {
203 get { return nameList; }
204 set { nameList = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
210 (attribute name { xsd:NCName },
216 public abstract class NvdlModeBase : NvdlAttributable
218 NvdlModeList includedModes = new NvdlModeList ();
219 NvdlRuleList rules = new NvdlRuleList ();
222 public NvdlModeList IncludedModes {
223 get { return includedModes; }
227 public NvdlRuleList Rules {
228 get { return rules; }
232 public class NvdlNestedMode : NvdlModeBase
236 public class NvdlMode : NvdlModeBase
241 // [MapType ("NCName", XmlSchema.Namespace)]
244 set { name = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
248 public class NvdlIncludedMode : NvdlModeBase
254 // [MapType ("NCName", XmlSchema.Namespace)]
257 set { name = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
261 public enum NvdlRuleTarget {
268 public abstract class NvdlRule : NvdlAttributable
270 NvdlRuleTarget match;
271 NvdlActionList actions = new NvdlActionList ();
273 public NvdlRuleTarget Match {
274 get { return match; }
275 set { match = value; }
278 public NvdlActionList Actions {
279 get { return actions; }
285 (attribute ns { xsd:string },
286 attribute wildCard {xsd:string{maxLength = "1"}}?,
291 public class NvdlNamespace : NvdlRule
303 public string Wildcard {
304 get { return wildcard; }
306 if (value != null && value.Length > 1)
307 throw new ArgumentException ("wildCard attribute can contain at most one character.");
314 element anyNamespace { ruleModel & foreign}
316 public class NvdlAnyNamespace : NvdlRule
320 public abstract class NvdlAction : NvdlAttributable
325 element cancelNestedActions {foreign}
327 public class NvdlCancelAction : NvdlAction
331 public abstract class NvdlNoCancelAction : NvdlAction
333 NvdlModeUsage modeUsage;
335 NvdlMessageList messages = new NvdlMessageList ();
337 public NvdlModeUsage ModeUsage {
338 get { return modeUsage; }
339 set { modeUsage = value; }
342 public string SimpleMessage {
343 get { return messageAttr; }
344 set { messageAttr = value; }
347 public NvdlMessageList Messages {
348 get { return messages; }
352 public abstract class NvdlNoResultAction : NvdlNoCancelAction
356 public enum NvdlResultType {
362 public abstract class NvdlResultAction : NvdlNoCancelAction
364 public abstract NvdlResultType ResultType { get; }
367 public class NvdlAttach : NvdlResultAction
369 public override NvdlResultType ResultType {
370 get { return NvdlResultType.Attach; }
374 public class NvdlAttachPlaceholder : NvdlResultAction
376 public override NvdlResultType ResultType {
377 get { return NvdlResultType.AttachPlaceholder; }
381 public class NvdlUnwrap : NvdlResultAction
383 public override NvdlResultType ResultType {
384 get { return NvdlResultType.Unwrap; }
397 attribute schema { xsd:anyURI } |
398 element schema {(text | foreignElement), foreignAttribute*}
400 public class NvdlValidate : NvdlNoResultAction
403 NvdlOptionList options = new NvdlOptionList ();
405 XmlElement schemaBody;
408 // [MapType ("NCName", XmlSchema.Namespace)]
409 public string SchemaType {
410 get { return schemaType; }
411 set { schemaType = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
414 public NvdlOptionList Options {
415 get { return options; }
418 // [MapType ("anyURI", XmlSchema.Namespace)]
419 public string SchemaUri {
420 get { return schemaUri; }
421 set { schemaUri = value; }
424 public XmlElement SchemaBody {
425 get { return schemaBody; }
426 set { schemaBody = value; }
430 public class NvdlAllow : NvdlNoResultAction
434 public class NvdlReject : NvdlNoResultAction
438 public class NvdlMessage : NvdlElementBase
442 ArrayList foreignAttributes = new ArrayList ();
446 set { text = value; }
449 public string XmlLang {
450 get { return xmlLang; }
451 set { xmlLang = value; }
454 public ArrayList ForeignAttributes {
455 get { return foreignAttributes; }
459 public class NvdlOption : NvdlAttributable
467 set { name = value; }
475 public string MustSupport {
476 get { return mustSupport; }
477 set { mustSupport = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
482 (attribute useMode { xsd:NCName } | nestedMode)?,
484 (attribute path { path },
485 (attribute useMode { xsd:NCName } | nestedMode)?)
489 public class NvdlModeUsage
492 NvdlNestedMode nestedMode;
493 NvdlContextList contexts = new NvdlContextList ();
495 public string UseMode {
496 get { return useMode; }
497 set { useMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
500 public NvdlNestedMode NestedMode {
501 get { return nestedMode; }
502 set { nestedMode = value; }
505 public NvdlContextList Contexts {
506 get { return contexts; }
510 public class NvdlContext : NvdlAttributable
514 NvdlNestedMode nestedMode;
518 set { path = value; }
521 public string UseMode {
522 get { return useMode; }
523 set { useMode = value != null ? value.Trim (Nvdl.Whitespaces) : null; }
526 public NvdlNestedMode NestedMode {
527 get { return nestedMode; }
528 set { nestedMode = value; }
532 public class NvdlTriggerList : CollectionBase
534 public NvdlTrigger this [int i] {
535 get { return (NvdlTrigger) List [i]; }
536 set { List [i] = (NvdlTrigger) value; }
539 public void Add (NvdlTrigger item)
544 public void Remove (NvdlTrigger item)
550 public class NvdlRuleList : CollectionBase
552 public NvdlRule this [int i] {
553 get { return (NvdlRule) List [i]; }
554 set { List [i] = (NvdlRule) value; }
557 public void Add (NvdlRule item)
562 public void Remove (NvdlRule item)
568 public class NvdlModeList : CollectionBase
570 public NvdlModeBase this [int i] {
571 get { return (NvdlModeBase) List [i]; }
572 set { List [i] = (NvdlModeBase) value; }
575 public void Add (NvdlModeBase item)
580 public void Remove (NvdlModeBase item)
586 public class NvdlContextList : CollectionBase
588 public NvdlContext this [int i] {
589 get { return (NvdlContext) List [i]; }
590 set { List [i] = (NvdlContext) value; }
593 public void Add (NvdlContext item)
598 public void Remove (NvdlContext item)
604 public class NvdlActionList : CollectionBase
606 public NvdlAction this [int i] {
607 get { return (NvdlAction) List [i]; }
608 set { List [i] = (NvdlAction) value; }
611 public void Add (NvdlAction item)
616 public void Remove (NvdlAction item)
622 public class NvdlOptionList : CollectionBase
624 public NvdlOption this [int i] {
625 get { return (NvdlOption) List [i]; }
626 set { List [i] = (NvdlOption) value; }
629 public void Add (NvdlOption item)
634 public void Remove (NvdlOption item)
640 public class NvdlMessageList : CollectionBase
642 public NvdlMessage this [int i] {
643 get { return (NvdlMessage) List [i]; }
644 set { List [i] = (NvdlMessage) value; }
647 public void Add (NvdlMessage item)
652 public void Remove (NvdlMessage item)