Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
//
// AssemblyInfo.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
// (C) 2004 Novell (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion (Consts.FxVersion)]
//[assembly: AssemblyTitle ("")]
[assembly: AssemblyDescription ("Commons.Xml.Relaxng.dll")]
[assembly: CLSCompliant (true)]
[assembly: AssemblyFileVersion ("0.0.0.1")]
[assembly: ComVisible (false)]
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../mono.pub")]

View File

@@ -0,0 +1,9 @@
2005-02-06 Atsushi Enomoto <atsushi@ximian.com>
* AssemblyInfo.cs : minimum information.
2004-04-30 Sebastien Pouliot <sebastien@ximian.com>
* AssemblyInfo.cs: Added
* ChangeLog: Added
* Locale.cs: Added

View File

@@ -0,0 +1,112 @@
2009-01-20 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng_test.dll.sources : forgot to add
RelaxngDatatypeProviderTests.cs.
2008-11-11 Atsushi Enomoto <atsushi@ximian.com>
* Makefile: what a messy EXTRA_DISTFILES.
2007-04-18 Atsushi Enomoto <atsushi@ximian.com>
* Makefile (EXTRA_DISTFILES) :
added schemas-xmlsoap-or-ws-2005-05-identity.rnc
2006-06-15 Raja R Harinath <rharinath@novell.com>
* Makefile (EXTRA_DISTFILES): Add Test/XmlFiles/nvdl.rng.
2006-04-11 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng_test.dll.sources :
added NvdlValidatingReaderTests.cs.
* README: some updates.
2005-12-28 Atsushi Enomoto <atsushi@ximian.com>
* README : updated the status.
2005-03-28 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxnf.dll.sources : added XmlChar.cs
2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
* README :
more description.
2005-03-06 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng.dll.sources : added NvdlFilteredXmlReader.
2005-03-01 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng.dll.sources : added NVDL support files.
* README : added halfbaked description.
2005-01-26 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng.dll.sources :
added RncWriter.cs and RelaxngInference.cs.
2004-12-06 Raja R Harinath <rharinath@novell.com>
* Makefile (RESOURCE_FILES): List only filenames.
(LIB_MCS_FLAGS): Strip off directory of resource files to get
resource names.
(EXTRA_DISTFILES): Add $(RESOURCE_FILES).
(BUILT_SOURCES): Add Common.Xml.Relaxng.Rnc/RncParser.cs.
($(the_lib)): Depend on resource files too.
* Common.Xml.Relaxng.dll.sources: Remove RncParser.cs.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : added relaxng.rng as a resource.
2004-11-25 Raja R Harinath <rharinath@novell.com>
* Makefile (Commons.Xml.Relaxng.Rnc/RncParser.cs): Depend on jay/skeleton.cs.
2004-11-04 Raja R Harinath <rharinath@novell.com>
* Makefile (EXTRA_DISTFILES): Fix for 'make dist'.
2004-03-18 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : It was incorrect fix, and more fix on command line.
2004-03-18 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : path to jay should be supplied.
2004-03-17 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng.dll.sources : Added RncParser.cs and RncTokenizer.cs.
* Commons.Xml.Relaxng_test.dll.sources : Added RncTests.cs.
* Makefile : Added RncParser.jay build support.
* README : updated.
2004-03-01 Atsushi Enomoto <atsushi@ximian.com>
* README : added usage descriptions.
2004-02-28 Atsushi Enomoto <atsushi@ximian.com>
* Commons.Xml.Relaxng_test.dll.sources : Added XsdDatatypeTests.cs
2004-02-25 Atsushi Enomoto <atsushi@ximian.com>
* Added README.
* Commons.Xml.Relaxng.dll.sources : added many new files.
2003-04-30 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* list.unix,
list: fixed incorrect reference to Util.cs (Misc.cs).
2003-04-29 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* Started.
* added ChangeLog, list, list.unix, makefile.gnu and
Commons.Xml.Relaxng.build.

View File

@@ -0,0 +1,204 @@
2007-12-27 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : pass baseUri to RncParser.
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs :
Made placeholder element as "empty" i.e. IsEmptyElement = true.
As long as it is at placeholder state, it keeps being placeholder
empty element until DetachPlaceholder() is explicitly called. It
makes this reader simpler.
* NvdlValidator.cs : (NvdlResultInterp) for AttachPlaceHolder it does
not have to do anything other than AttachPlaceholder().
(NvdlValidateInterp) Now that placeholder becomes an empty element
it does not have to validate content anymore at DetachPlaceholder().
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlReader.cs, NvdlFilteredXmlReader.cs :
placeHolder -> placeholder. Also reject unrecognized NVDL elements
in NvdlReader.
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlException.cs : provide BaseURI in such case that argument
IXmlLineInfo is XmlReader.
* NvdlValidator.cs : NvdlDispatcher was incorrectly replacing
current section when an empty element appears (it kept such empty
element section).
2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : It seems that the validating grammar for
planAtt should always contain a definition for virtualElement i.e.
it is not something that NVDL validator should provide
automatically. (It makes sense since RELAX NG does not support
attribute-only grammar definition.)
* NvdlFilteredXmlReader.cs : for validating attributes, filter xmlns
attributes out.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs, NvdlValidator.cs :
Support for revised "trigger" in FDIS was not enough. The validator
must not trigger such element that has a parent which could be
triggered (the parent does not have to be actually triggered).
Thus, introduced a new class SimpleTrigger which holds own qname
array.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs : according to the section 6.4.10 overriden rules
should be filtered out, and rules with cancelNestedAction should be
removed *after* filtering overriden rules out.
2006-04-18 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs, NvdlValidator.cs :
fixed several context path related bugs.
- Path steps must be trimmed.
- MatchPath() always returned false.
- nested mode in context is always ignored.
2006-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : without ReportDetails RELAX NG support
supplied too little information on validation error.
2006-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : quick fix for r58557; it caused a big
NVDL validation breakage (nvdl.nvdl does not validate).
Removed unused and insignificant code.
* NvdlCompileContext.cs : removed unused field.
2006-04-03 Atsushi Enomoto <atsushi@ximian.com>
due to the request by Brian Rasumussen to report NVDL error details:
* NvdlFilteredXmlReader.cs : make it as IXmlLineInfo.
* NvdlValidationGenerator.cs :
(NvdlValidationProvider) made validate, schemaType and config as
publicly accessible.
(NvdlValidatorGenerator) added new HandleError() method that can
override error handling.
* NvdlValidator.cs : use it.
* NvdlException.cs : added new type NvdlInstanceValidationException
that is used to "wrap" actual validation errors to provide
NVDL script location information.
* NvdlRelaxngSupport.cs, NvdlXsdSupport.cs :
use those new HandleError() and NvdlInstanceValidationException.
2006-03-23 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : seems like "XmlReaderSettings.ValidationType =
ValidationType.Auto" does not automatically start xsd validation,
so set the property explicitly as ValidationType.Schema.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : oops, XmlSchemaValidationFlags.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : in NET_2_0 mode, use XmlReader.Create()
with validation support. Now MS.NET users can validate NVDL
that uses XSD.
2006-03-03 Atsushi Enomoto <atsushi@ximian.com>
* NvdlSimplified.cs : (SimpleRules) huh, I made silly change to
access null field.
2005-12-23 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs, NvdlReader.cs, NvdlStructures.cs,
NvdlSimplified.cs, NvdlValidator.cs:
Reflected the latest changes in NVDL Final Draft:
http://www.jtc1sc34.org/repository/0694.pdf
- wildcard -> wildCard
- renamed from "PlaceHolder" to "Placeholder"
- trigger/@name of NCName -> trigger/@nameList of list of NCName
2005-09-30 Atsushi Enomoto <atsushi@ximian.com>
* NvdlConfig.cs : changed mime type due to the suggestion from Makoto
Murata.
2005-09-30 Atsushi Enomoto <atsushi@ximian.com>
* NvdlXsdSupport.cs : related fix to r51030; XmlSchema.Read() now does
not consume EndElement.
2005-09-25 Atsushi Enomoto <atsushi@ximian.com>
* NvdlValidationProvider.cs : GetSchemaXmlStream() should take NVDL
script's base URI into account to compute the actual schema URI.
* NvdlRelaxngSupport.cs : ditto.
2005-09-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlCompileContext.cs : make this internal.
* NvdlStructures.cs : surpress default constructor.
Make debug stuff internal.
2005-04-11 Atsushi Enomoto <atsushi@ximian.com>
* NvdlRelaxngSupport.cs : added PlanAtt validation support.
2005-04-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlValidator.cs : fixed warning.
2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs, NvdlStructures.cs, NvdlSimplified.cs :
"PlaceHolderNamespace" is not proper name (for "virtualElement").
2005-03-07 Atsushi Enomoto <atsushi@ximian.com>
* 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.
* NvdlCompileContext.cs, NvdlConfig.cs, NvdlSimplified.cs,
NvdlValidatingReader.cs : Simplified objects are now all internal.
* NvdlValidator.cs : don't output debug.
2005-03-06 Atsushi Enomoto <atsushi@ximian.com>
* NvdlFilteredXmlReader.cs : New file. Supports createPlaceHolder()
and attBubble[I].
* NvdlValidator.cs : support for attachPlaceHolder.
* NvdlSimplified.cs,
NvdlStructures.cs,
NvdlBuiltInValidationProvider.cs : renamed namespace const.
* NvdlValidationProvider.cs : removed extraneous debug.
2005-03-01 Atsushi Enomoto <atsushi@ximian.com>
* NvdlStructures.cs,
NvdlSimplified.cs,
NvdlReader.cs,
NvdlValidatingReader.cs,
NvdlConfig.cs,
NvdlValidationProvider.cs,
NvdlBuiltInValidationProvider.cs,
NvdlRelaxngSupport.cs,
NvdlXsdSupport.cs,
NvdlException.cs,
NvdlValidator.cs,
NvdlCompileContext.cs : initial checkin.

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlBuiltInValidationProvider : NvdlValidationProvider
{
public NvdlBuiltInValidationProvider ()
{
}
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
reader.MoveToContent ();
if (reader.NodeType != XmlNodeType.Element ||
reader.NamespaceURI != Nvdl.BuiltInValidationNamespace)
return null;
return new NvdlBuiltInValidatorGenerator (reader.LocalName == "allow");
}
}
internal class NvdlBuiltInValidatorGenerator : NvdlValidatorGenerator
{
bool allow;
public NvdlBuiltInValidatorGenerator (bool allow)
{
this.allow = allow;
}
public override XmlReader CreateValidator (XmlReader reader, XmlResolver resolver)
{
return new NvdlBuiltInValidationReader (reader, allow);
}
public override bool AddOption (string name, string arg)
{
return false;
}
}
internal class NvdlBuiltInValidationReader : XmlDefaultReader
{
bool allow;
public NvdlBuiltInValidationReader (XmlReader reader, bool allow)
: base (reader)
{
this.allow = allow;
}
public override bool Read ()
{
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 true;
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
internal class NvdlCompileContext
{
NvdlRules rules;
NvdlConfig config;
XmlResolver resolver;
Hashtable compiledModes = new Hashtable ();
Hashtable modeContexts = new Hashtable ();
Hashtable cancelledRules = new Hashtable ();
Hashtable ruleContexts = new Hashtable ();
public NvdlCompileContext (NvdlRules rules, NvdlConfig config, XmlResolver resolver)
{
this.rules = rules;
this.config = config;
this.resolver = resolver;
}
public NvdlRules Rules {
get { return rules; }
}
public NvdlConfig Config {
get { return config; }
}
internal XmlResolver XmlResolver {
get { return resolver; }
}
internal void AddCompiledMode (string name, SimpleMode m)
{
compiledModes.Add (m.Name, m);
}
internal void AddCompiledMode (NvdlModeUsage u, SimpleMode m)
{
compiledModes.Add (u, m);
}
internal void AddCompiledMode (NvdlContext c, SimpleMode m)
{
compiledModes.Add (c, m);
}
internal SimpleMode GetCompiledMode (string name)
{
return compiledModes [name] as SimpleMode;
}
internal SimpleMode GetCompiledMode (NvdlModeUsage u)
{
return compiledModes [u] as SimpleMode;
}
internal SimpleMode GetCompiledMode (NvdlContext c)
{
return compiledModes [c] as SimpleMode;
}
internal ICollection GetCompiledModes ()
{
return compiledModes.Values;
}
internal NvdlModeCompileContext GetModeContext (SimpleMode m)
{
return modeContexts [m] as NvdlModeCompileContext;
}
internal void AddModeContext (SimpleMode m,
NvdlModeCompileContext mctx)
{
modeContexts.Add (m, mctx);
}
internal NvdlRule GetRuleContext (SimpleRule r)
{
return ruleContexts [r] as NvdlRule;
}
internal void AddRuleContext (SimpleRule r, NvdlRule rctx)
{
ruleContexts.Add (r, rctx);
}
public Hashtable CancelledRules {
get { return cancelledRules; }
}
}
internal class NvdlModeCompileContext
{
ArrayList included;
public NvdlModeCompileContext (NvdlModeBase mode)
{
included = new ArrayList ();
}
public ArrayList Included {
get { return included; }
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlConfig
{
XmlResolver resolver = new XmlUrlResolver ();
ArrayList providers = new ArrayList ();
public NvdlConfig ()
{
providers.Add (new NvdlBuiltInValidationProvider ());
}
public void AddProvider (NvdlValidationProvider provider)
{
providers.Add (provider);
}
internal XmlResolver XmlResolverInternal {
get { return resolver; }
}
public XmlResolver XmlResolver {
set { resolver = value; }
}
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);
}
}
}

View File

@@ -0,0 +1,92 @@
using System;
using System.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlException : Exception
{
public NvdlException (string message)
: base (message)
{
}
public NvdlException (string message, Exception inner)
: base (message ,inner)
{
}
internal static string FormatMessage (string message,
IXmlLineInfo lineInfo)
{
NvdlElementBase source = lineInfo as NvdlElementBase;
XmlReader reader = lineInfo as XmlReader;
if (source != null && source.HasLineInfo ())
return String.Format ("{0}. {1} ({2},{3})",
message, source.SourceUri,
source.LineNumber, source.LinePosition);
else if (lineInfo != null && lineInfo.HasLineInfo ())
return String.Format ("{0}. {3}({1},{2})",
message,
lineInfo.LineNumber,
lineInfo.LinePosition,
reader != null ? reader.BaseURI + ' ' : String.Empty);
else
return message;
}
}
public class NvdlCompileException : NvdlException
{
public NvdlCompileException (string message,
IXmlLineInfo source)
: this (message, null, source)
{
}
public NvdlCompileException (string message, Exception inner,
IXmlLineInfo source)
: base (FormatMessage (message, source), inner)
{
}
}
public class NvdlValidationException : NvdlException
{
public NvdlValidationException (string message,
IXmlLineInfo source)
: this (message, null, source)
{
}
public NvdlValidationException (string message, Exception inner,
IXmlLineInfo source)
: base (FormatMessage (message, source), inner)
{
}
}
public class NvdlInstanceValidationException : NvdlException
{
public NvdlInstanceValidationException (string message,
NvdlValidatorGenerator generator,
string nvdlLocation)
: this (message, null, generator, nvdlLocation)
{
}
public NvdlInstanceValidationException (string message, Exception inner,
NvdlValidatorGenerator generator,
string nvdlLocation)
: base (FormatMessageWithDefinition (message, nvdlLocation), inner)
{
}
// assuming that wrapped exception message usually
// contains the actual instance location info.
static string FormatMessageWithDefinition (string message, string nvdlLocation)
{
return String.Format ("{0}. Related NVDL script: {1}", message, nvdlLocation);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using Commons.Xml.Relaxng;
using Commons.Xml.Relaxng.Rnc;
namespace Commons.Xml.Nvdl
{
public class NvdlRelaxngValidatorProvider : NvdlValidationProvider
{
public const string RncMimeType = "application/vnd.oasis-open.relax-ng.rnc";
public override NvdlValidatorGenerator CreateGenerator (
NvdlValidate validate, string schemaType, NvdlConfig config)
{
if (schemaType == RncMimeType)
return CreateRncGenerator (validate, config);
return base.CreateGenerator (validate, schemaType, 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);
}
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
if (reader.NamespaceURI != RelaxngGrammar.NamespaceURI)
return null;
return new NvdlRelaxngValidatorGenerator (RelaxngPattern.Read (reader), config);
}
}
internal class NvdlRelaxngValidatorGenerator : NvdlValidatorGenerator
{
RelaxngPattern pattern;
public NvdlRelaxngValidatorGenerator (RelaxngPattern p,
NvdlConfig config)
{
// FIXME: use XmlResolver
pattern = p;
}
public override XmlReader CreateValidator (XmlReader reader,
XmlResolver resolver)
{
// XmlResolver is never used.
RelaxngValidatingReader rvr =
new RelaxngValidatingReader (
reader, pattern);
rvr.ReportDetails = true;
return rvr;
}
public override XmlReader CreateAttributeValidator (
XmlReader reader,
XmlResolver resolver)
{
// XmlResolver is never used.
RelaxngValidatingReader rvr =
new RelaxngValidatingReader (
reader, pattern);
rvr.ReportDetails = true;
return rvr;
}
public override bool AddOption (string name, string arg)
{
return false;
}
public override bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
{
if (ex is RelaxngException)
throw new NvdlInstanceValidationException (String.Format ("RELAX NG validation error occured as a part of NVDL validation: " + ex.Message), ex, this, nvdlLocation);
return false;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Threading;
using System.Xml;
using Commons.Xml;
namespace Commons.Xml.Nvdl
{
public class NvdlValidatingReader : XmlDefaultReader
{
NvdlDispatcher dispatcher;
public NvdlValidatingReader (XmlReader reader, NvdlRules rules)
: this (reader, rules, new XmlUrlResolver ())
{
}
public NvdlValidatingReader (XmlReader reader, NvdlRules rules, XmlResolver resolver)
: this (reader, rules, resolver, Nvdl.DefaultConfig)
{
}
public NvdlValidatingReader (XmlReader reader, NvdlRules rules,
XmlResolver resolver, NvdlConfig config)
: base (reader)
{
dispatcher = new NvdlDispatcher (new SimpleRules (
new NvdlCompileContext (
rules, config, resolver)), this);
}
internal NvdlValidatingReader (XmlReader reader, SimpleRules rules)
: base (reader)
{
dispatcher = new NvdlDispatcher (rules, this);
}
public event NvdlMessageEventHandler ActionStarted;
internal void OnMessage (ListDictionary messages)
{
if (messages == null)
return;
string message = messages [Thread.CurrentThread.CurrentCulture.Name] as string;
if (message == null)
message = messages [String.Empty] as string;
if (message == null)
return;
if (ActionStarted != null)
ActionStarted (this, new NvdlMessageEventArgs (message));
}
// validation.
public override bool Read ()
{
if (!Reader.Read ())
return false;
switch (Reader.NodeType) {
case XmlNodeType.Element:
dispatcher.StartElement ();
break;
case XmlNodeType.EndElement:
dispatcher.EndElement ();
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
case XmlNodeType.SignificantWhitespace:
dispatcher.Text ();
break;
case XmlNodeType.Whitespace:
dispatcher.Whitespace ();
break;
}
return true;
}
}
}

View File

@@ -0,0 +1,121 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
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;
// 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);
}
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;
}
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;
}
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;
}
}
public abstract class NvdlValidatorGenerator
{
// creates individual validator with schema
// (which should be provided in derived constructor).
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;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Xml.Schema;
namespace Commons.Xml.Nvdl
{
public class NvdlXsdValidatorProvider : NvdlValidationProvider
{
public override NvdlValidatorGenerator CreateGenerator (
XmlReader reader, NvdlConfig config)
{
if (reader.NamespaceURI != XmlSchema.Namespace)
return null;
ArrayList al = new ArrayList ();
while (!reader.EOF) {
if (reader.NodeType != XmlNodeType.Element) {
reader.Read ();
continue;
}
reader.MoveToContent ();
XmlSchema xs = XmlSchema.Read (reader, null);
xs.Compile (null, config.XmlResolverInternal);
al.Add (xs);
reader.Read ();
}
return new NvdlXsdValidatorGenerator (al.ToArray (typeof (XmlSchema)) as XmlSchema []);
}
}
internal class NvdlXsdValidatorGenerator : NvdlValidatorGenerator
{
XmlSchema [] schemas;
public NvdlXsdValidatorGenerator (XmlSchema [] schemas)
{
this.schemas = schemas;
}
public override XmlReader CreateValidator (XmlReader reader,
XmlResolver resolver)
{
#if NET_2_0
XmlReaderSettings s = new XmlReaderSettings ();
s.ValidationType = ValidationType.Schema;
// do not allow inline schema and schemaLocation.
s.ValidationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
s.XmlResolver = resolver;
foreach (XmlSchema schema in schemas)
s.Schemas.Add (schema);
return XmlReader.Create (reader, s);
#else
XmlValidatingReader xvr =
new XmlValidatingReader (reader);
xvr.XmlResolver = resolver;
foreach (XmlSchema schema in schemas)
xvr.Schemas.Add (schema);
return xvr;
#endif
}
public override bool AddOption (string name, string arg)
{
return false;
}
public override bool HandleError (Exception ex, XmlReader reader, string nvdlLocation)
{
if (ex is XmlSchemaException)
throw new NvdlInstanceValidationException (String.Format ("XML schema validation error occured as a part of NVDL validation."), ex, this, nvdlLocation);
return false;
}
}
}

View File

@@ -0,0 +1,245 @@
2009-02-23 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : added "Anything" which is used in error recovery
support.
2007-12-14 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : For ContainsText() (for interleave text/text
constraint check), element pattern should return false.
Fixed bug #347945.
2007-04-18 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : inside elements, reset oneOrMore[Group] flags in
CheckConstraints().
2006-02-02 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : After profiling in depth, finally I found the
source of the worst perf. problem in the code - return x for
(choice x x).
It now validates 5MB of OpenDocument specification content.xml,
which only Jing could do.
2006-01-16 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs : fixed warnings.
2006-01-16 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : RdpOneOrMore.EmptyTextDeriv() should be "override".
RdpList.EmptyTextDeriv() (which was also virtual incorrectly) was
removed since the code was in wrong assumption.
* Util.cs : debug string now contains data and dataExcept info.
2006-01-15 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : lazy evaluate Group branches. If left hand is
notAllowed, the returned value is always NotAllowed, no need to
compute another branch.
2006-01-13 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs, RdpPatterns.cs : introduced "IsContextDependent"
optimization; when a pattern is (namespace) context independent
(almost all cases except for QName validation), new TextDeriv()
overload that takes MemoizationStore memoizes TextDeriv results.
2006-01-12 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs :
Introduced EmptyTextDeriv() so that the results could be memoized.
2006-01-10 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs :
- Added StartAttDeriv(), EndAttDeriv() and IsTextValueDependent.
(See corresponding changes in RelaxngValidatingReader.cs).
- Added a bunch of derivative method overloads to receive
MemoizationStore and memoize results efficiently.
2006-01-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs :
- Fixed RdpPattern.TextDeriv() and MixedTextDeriv() to not allow
whitespaces incorrectly.
- Fixed MixedTextDeriv() to not require string argument.
- Erased commented code.
- in listDerivInternal(), skip empty strings.
- ValueMatch() should allow whitespaces if the pattern is nullable
(as defined in derivative).
- Replaced MakeChoice()/MakeGroup()/MakeInterleave()/MakeAfter()
in TextOnlyDeriv() and MixedTextDeriv(). They should not be
constructions but should be functions (thus, member methods).
- Fixed Nullable in RdpData and RdpValue to conform to the
derivative algorithm (it incorrectly extended to return false
for RELAX NG predefined datatypes).
2006-01-04 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs :
- Implemented textOnlyDeriv and mixedTextDeriv of "memoization".
Details are described in the "derivative" algorithm:
http://www.thaiopensource.com/relaxng/derivative.html#Memoization
- Added MakeChoiceLeaf() to implement "choice-leaves":
http://www.thaiopensource.com/relaxng/derivative.html#Avoiding_exponential_blowup
- To intern effectively, reorder choice and interleave contents by
hash code.
- Avoid extra pattern creation with related to empty and notAllowed
as one hand of binary branches.
2006-01-03 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : reduced RdpFlip instantiation. Share patternPool
only when it does not exist.
2006-01-03 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs, RdpPatterns.cs : optimization. Removed extraneous
delegate instantiation. Avoid using enum for HashTable keys.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs RdpObjects.cs RdpContentType.cs RdpNameClasses.cs
RdpPatterns.cs :
... and svn:eol-style as well, since there is exactly no one else
who develops this assembly and messes no one else.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs RdpObjects.cs RdpContentType.cs RdpNameClasses.cs
RdpPatterns.cs :
Ugh, seems like svn server shows different diffs than that of
client. Anyways here I fixed all mixed line endings.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : in ValueMatch() it should not strip whitespaces
which could be validated. This fixes test #256/2.i.xml.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : oneOrMore ancestor check for anyName/nsName in
section 7.3 was missing. This fixes test #357, #358 and #359.
* RdpNameClass.cs : added HasInfiniteName property to RdpNameClass.
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs, RdpUtil.cs : reimplemented name class analysis to
not create extraneous QName instances. This also fixes some weird
bugs (test #362 and #363).
2005-12-27 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : Checking interleave restriction in section 7.4 with
PatternType was not insufficient. Now I use ContainsText(). It fixes
testcase #371.
2005-12-20 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : cache ContentType and save speed.
2005-09-20 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : Added name class analysis support. The algorithm is at
http://www.thaiopensource.com/relaxng/nameclass.html .
* RdpPattern.cs :
- added CheckNameOverlap() for group and interleave to do name class
analysis (spec 7.3 and 7.4).
- Removed CheckAttributeDuplicates(). Now name class analysis is
implemented in CheckNameOverlap().
- Added additional bool parameter to GetLabels() to collect
RdpNameClass instances instead of XmlQualifiedName instances.
2005-07-31 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : GetLabels() for RdpGroup should check attributes
when the left branch is not nullable (it works like an interleave).
Implemented spec 7.3 attribute check (though not enabled for now).
2005-04-11 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : tiny debug string fix.
2005-03-01 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : In "textDeriv(group p1 p2) s", "nullable p1" is
incorrectly computed as "nullable p".
2005-02-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpObjects.cs : provide error type name. removed commented code block.
2005-02-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : MakeOneOrMore() did not always set up internal table.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* Util.cs : trivial debug string fix.
* RdpPattern.cs : trivial formatting fix.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : The last attribute stuff broke usual validation wrt
global attributes.
2004-12-06 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : fixed setupTable(). Avoid boxing.
2004-12-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : RdpAttribute now omits value check when the argument
value is null. It is useful to get labels.
2004-12-05 Atsushi Enomoto <atsushi@ximian.com>
* RdpPattern.cs : added GetLabels().
2004-06-25 Atsushi Enomoto <atsushi@ximian.com>
* RdpContentType.cs, RdpNameClass.cs, RdpObjects.cs, RdpPatterns.cs,
Util.cs : added novell license term.
2004-06-21 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Fixed ExpandRef() that caused incorrect nest error.
2004-06-17 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Quick workaround for infinite loop happening in
some kind of recursive expansion.
2004-03-12 Atsushi Enomoto <atsushi@ximian.com>
* RdpPatterns.cs : Fixed TextDeriv() to allow whitespace text nodes
except for Data and Value (though they are overridden).
2004-02-25 Atsushi Enomoto <atsushi@ximian.com>
* Added RdpContextType.cs.
* RdpNameClasses.cs,
RdpObjects.cs,
RdpPatterns.cs,
Util.cs : radical design change (too many things to write up).
2003-05-19 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* RdpPattern.cs : Some method name capitalization.
Fixed RdpInterleave.StartTagOpenDeriv() which is logically incorrect.
2003-05-05 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* RdpPattern.cs : added RdpAttribute.expandRef(). UnresolvedRef had
remained in attribute patterns.
2003-04-29 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* Started.
* added ChangeLog, RdpNameClasses.cs, RdpObjects.cs, RdpPatterns.cs
and Util.cs.

View File

@@ -0,0 +1,42 @@
//
// RdpContentType.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// See RELAX NG spec 7.2
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace Commons.Xml.Relaxng.Derivative
{
public enum RdpContentType {
Invalid = 0,
Empty = 1,
Complex = 2,
Simple = 4
}
}

View File

@@ -0,0 +1,237 @@
//
// Commons.Xml.Relaxng.Derivative.RdpNameClasses.cs
//
// Author:
// Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// 2003 Atsushi Enomoto "No rights reserved."
//
// Copyright (c) 2004 Novell Inc.
// All rights reserved
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Xml;
namespace Commons.Xml.Relaxng.Derivative
{
public enum RdpNameClassType
{
None = 0,
AnyName = 1,
AnyNameExcept = 2,
NsName = 3,
NsNameExcept = 4,
Name = 5,
NameClassChoice = 6
}
public abstract class RdpNameClass
{
public abstract bool HasInfiniteName { get; }
public abstract RdpNameClassType NameClassType { get; }
public abstract bool Contains (string name, string ns);
}
public class RdpAnyName : RdpNameClass
{
static RdpAnyName instance;
static RdpAnyName ()
{
instance = new RdpAnyName ();
}
public static RdpAnyName Instance {
get { return instance; }
}
private RdpAnyName () {}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.AnyName; }
}
public override bool Contains (string name, string ns)
{
return true;
}
}
public class RdpAnyNameExcept : RdpNameClass
{
RdpNameClass except;
public RdpAnyNameExcept (RdpNameClass except)
{
this.except = except;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.AnyNameExcept; }
}
public RdpNameClass ExceptNameClass {
get { return except; }
}
public override bool Contains (string name, string ns)
{
return (except == null) || !except.Contains (name, ns);
}
}
public class RdpNsName : RdpNameClass
{
string ns;
public RdpNsName (string ns)
{
this.ns = ns;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NsName; }
}
public string NamespaceURI {
get { return ns; }
}
public override bool Contains (string name, string ns)
{
return NamespaceURI == ns;
}
}
public class RdpNsNameExcept : RdpNsName
{
string ns;
RdpNameClass except;
public RdpNsNameExcept (string ns, RdpNameClass except)
: base (ns)
{
this.ns = ns;
this.except = except;
}
public override bool HasInfiniteName {
get { return true; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NsNameExcept; }
}
public RdpNameClass ExceptNameClass {
get { return except; }
}
public override bool Contains (string name, string ns)
{
return this.ns == ns &&
(except == null || !except.Contains (name, ns));
}
}
public class RdpName : RdpNameClass
{
string local;
string ns;
public RdpName (string local, string ns)
{
this.ns = ns;
this.local = local;
}
public override bool HasInfiniteName {
get { return false; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.Name; }
}
public string NamespaceURI {
get { return ns; }
}
public string LocalName {
get { return local; }
}
public override bool Contains (string name, string ns)
{
return this.ns == ns && this.local == name;
}
}
public class RdpNameClassChoice : RdpNameClass
{
RdpNameClass l;
RdpNameClass r;
public RdpNameClassChoice (RdpNameClass l, RdpNameClass r)
{
this.l = l;
this.r = r;
}
public override bool HasInfiniteName {
get { return l.HasInfiniteName || r.HasInfiniteName; }
}
public override RdpNameClassType NameClassType {
get { return RdpNameClassType.NameClassChoice; }
}
public RdpNameClass LValue {
get { return l; }
}
public RdpNameClass RValue {
get { return r; }
}
public override bool Contains (string name, string ns)
{
return l.Contains (name, ns) || r.Contains (name, ns);
}
}
}

Some files were not shown because too many files have changed in this diff Show More