diff --git a/CS2JLibrary/NetFramework/schemas/ClassRepTemplate.xsd b/CS2JLibrary/NetFramework/schemas/ClassRepTemplate.xsd new file mode 100755 index 0000000..f717d36 --- /dev/null +++ b/CS2JLibrary/NetFramework/schemas/ClassRepTemplate.xsd @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs index e0ba76d..6ca29da 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JMain.cs @@ -123,11 +123,11 @@ namespace Twiglet.CS2J.Translator .Add ("cheatdir=", dir => cfg.CheatDir = dir) .Add ("netdir=", dirs => addDirectories(cfg.NetRoot, dirs)) .Add ("exnetdir=", dirs => addDirectories(cfg.ExNetRoot, dirs)) + .Add ("netschemadir=", dirs => addDirectories(cfg.NetSchemaDir, dirs)) .Add ("appdir=", dirs => addDirectories(cfg.AppRoot, dirs)) .Add ("exappdir=", dirs => addDirectories(cfg.ExAppRoot, dirs)) .Add ("csdir=", dirs => addDirectories(csDir, dirs)) .Add ("excsdir=", dirs => addDirectories(cfg.Exclude, dirs)) - .Add ("keyfile=", v => cfg.KeyFile = v) .Add ("translator-keep-parens=", v => cfg.TranslatorKeepParens = Boolean.Parse(v)) .Add ("translator-timestamp-files=", v => cfg.TranslatorAddTimeStamp = Boolean.Parse(v)) .Add ("translator-blanket-throw=", v => cfg.TranslatorBlanketThrow = Boolean.Parse(v)) @@ -164,6 +164,17 @@ namespace Twiglet.CS2J.Translator RsaKey.FromXmlString(rsaPubXml); // Load .Net templates + // Do we have schemas for the templates? + if (cfg.NetSchemaDir.Count == 0) + { + // By default look for schemas in net dirs + cfg.NetSchemaDir = new List(cfg.NetRoot); + } + + // Comment out for now. I don't see how to wrie an xsd file that will allow elements to appear in any order + // foreach (string schemadir in cfg.NetSchemaDir) + // doFile(schemadir, ".xsd", addNetSchema, null); + foreach (string r in cfg.NetRoot) doFile(r, ".xml", addNetTranslation, cfg.ExNetRoot); @@ -247,7 +258,7 @@ namespace Twiglet.CS2J.Translator { string canonicalPath = Path.GetFullPath(root); // If this is a directory, walk each file/dir in that directory - if (!excludes.Contains(canonicalPath)) + if (excludes == null || !excludes.Contains(canonicalPath)) { if (Directory.Exists(canonicalPath)) { @@ -351,6 +362,20 @@ namespace Twiglet.CS2J.Translator return signedXml.CheckSignature(Key); } + // Here's where we do the real work... + public static void addNetSchema(string fullName) + { + try + { + TypeRepTemplate.TemplateReaderSettings.Schemas.Add("urn:www.twigletsoftware.com:schemas:txtemplate:1:0", fullName); + Console.WriteLine(fullName); + } + catch (Exception e) + { + throw; + } + } + // Here's where we do the real work... public static void addNetTranslation(string fullName) { diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JSettings.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JSettings.cs index aa59c96..e31436c 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JSettings.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JMain/CS2JSettings.cs @@ -25,6 +25,7 @@ namespace Twiglet.CS2J.Translator public string CheatDir { get; set; } public IList NetRoot { get; set; } public IList ExNetRoot { get; set; } + public IList NetSchemaDir { get; set; } public IList AppRoot { get; set; } public IList ExAppRoot { get; set; } public IList Exclude { get; set; } @@ -102,6 +103,7 @@ namespace Twiglet.CS2J.Translator CheatDir = ""; NetRoot = new List(); ExNetRoot = new List(); + NetSchemaDir = new List(); AppRoot = new List(); ExAppRoot = new List(); Exclude = new List(); diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs index 0a587d9..a5c23ea 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs @@ -9,6 +9,7 @@ using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Xml; +using System.Xml.Schema; using System.Xml.Serialization; using Twiglet.CS2J.Translator.Utils; @@ -2229,12 +2230,44 @@ namespace Twiglet.CS2J.Translator.TypeRep #region deserialization + private static XmlReaderSettings _templateReaderSettings = null; + + /// + /// Reader Settings used when reading translation templates. Validate against schemas + /// + public static XmlReaderSettings TemplateReaderSettings + { + get + { + if (_templateReaderSettings == null) + { + _templateReaderSettings = new XmlReaderSettings(); + _templateReaderSettings.ValidationType = ValidationType.Schema; + _templateReaderSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; + _templateReaderSettings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); + } + return _templateReaderSettings; + } + } + + // Display any warnings or errors while validating translation templates. + private static void ValidationCallBack(object sender, ValidationEventArgs args) + { + if (args.Severity == XmlSeverityType.Warning) + Console.WriteLine("\tWarning: Matching schema not found. No validation occurred." + args.Message); + else + Console.WriteLine("\tValidation error: " + args.Message); + } + private static object Deserialize (Stream fs, System.Type t) { object o = null; - + + // Create the XmlReader object. + XmlReader reader = XmlReader.Create(fs, TemplateReaderSettings); + XmlSerializer serializer = new XmlSerializer (t, Constants.TranslationTemplateNamespace); - o = serializer.Deserialize (fs); + o = serializer.Deserialize (reader); return o; }