internal void CheckIncludeRecursion(string href) { if (this.includedUris [href] != null) { // FIXME: fill line info throw new RelaxngException("Include recursion found. href: " + href); } if (parentGrammar != null) { parentGrammar.CheckIncludeRecursion(href); } }
internal override RdpPattern Compile (RelaxngGrammar grammar) { grammar.CheckIncludeRecursion (Href); grammar.IncludedUris.Add (Href, Href); if (grammar.Resolver == null) throw new RelaxngException (this, "To compile 'include' element, XmlResolver is required."); Uri uri = grammar.Resolver.ResolveUri (BaseUri != String.Empty ? new Uri (BaseUri) : null, Href); RelaxngPattern p = ReadExternalResource (grammar, uri, ns); p.DataProvider = grammar.Provider; RdpPattern ret = p.Compile (grammar); grammar.IncludedUris.Remove (Href); return ret; }
// compile into div internal RelaxngDiv Compile(RelaxngGrammar grammar) { grammar.CheckIncludeRecursion(Href); grammar.IncludedUris.Add(Href); if (grammar.Resolver == null) { throw new RelaxngException(this, "To compile 'include' element, XmlResolver is required."); } Uri baseUri = null; try { if (BaseUri != null && BaseUri != String.Empty) { baseUri = new Uri(BaseUri); } #if PORTABLE } catch { throw; } #else } catch (UriFormatException) {
// compile into div internal RelaxngDiv Compile (RelaxngGrammar grammar) { grammar.CheckIncludeRecursion (Href); grammar.IncludedUris.Add (Href, Href); if (grammar.Resolver == null) throw new RelaxngException (this, "To compile 'include' element, XmlResolver is required."); Uri baseUri = null; try { if (BaseUri != null && BaseUri != String.Empty) baseUri = new Uri (BaseUri); } catch (UriFormatException) { if (File.Exists (BaseUri)) baseUri = new Uri (Path.GetFullPath (BaseUri)); } Uri uri = grammar.Resolver.ResolveUri (baseUri, Href); RelaxngGrammar g = ReadExternalResource (grammar, uri, (ns != null && ns.Length != 0) || !grammar.IsSourceCompactSyntax ? ns : grammar.DefaultNamespace) as RelaxngGrammar; if (g == null) throw new RelaxngException (this, "Included syntax must start with \"grammar\" element."); g.DataProvider = grammar.Provider; g.IsSourceCompactSyntax = grammar.IsSourceCompactSyntax; // process recursive inclusions. foreach (RelaxngInclude inc in g.Includes) g.Divs.Add (inc.Compile (grammar)); // process this own div children. // each div subelements are also compiled. foreach (RelaxngDiv cdiv in divs) cdiv.Compile (g); foreach (RelaxngDiv cdiv in g.Divs) cdiv.Compile (g); // replace redifinitions into div. // starts. if (this.Starts.Count > 0 && g.Starts.Count == 0) throw new RelaxngException (this, "When the included grammar does not contain start components, this include component must not contain start components."); RelaxngGrammarContentList appliedStarts = (this.starts.Count > 0) ? this.starts : g.Starts; RelaxngDiv div = new RelaxngDiv (); div.BaseUri = this.BaseUri; div.LinePosition = this.LinePosition; div.LineNumber = this.LineNumber; foreach (RelaxngStart start in appliedStarts) div.Starts.Add (start); // defines. Hashtable overrides = new Hashtable (); Hashtable originalDefs = new Hashtable (); foreach (RelaxngDefine def in defines) { overrides.Add (def.Name, def.Name); div.Defines.Add (def); } foreach (RelaxngDefine def in g.Defines) { originalDefs [def.Name] = def.Name; if (!overrides.ContainsKey (def.Name)) { div.Defines.Add (def); } // else discard. } foreach (string name in overrides.Values) if (!originalDefs.ContainsKey (name)) throw new RelaxngException (this, "The include component must not contain define components whose name does not appear in the included grammar component."); grammar.IncludedUris.Remove (Href); return div; }
internal override RdpPattern Compile (RelaxngGrammar grammar) { grammar.CheckIncludeRecursion (Href); grammar.IncludedUris.Add (Href, Href); if (grammar.Resolver == null) throw new RelaxngException (this, "To compile 'include' element, XmlResolver is required."); Uri uri = grammar.Resolver.ResolveUri (BaseUri != String.Empty ? new Uri (BaseUri) : null, Href); RelaxngPattern p = ReadExternalResource (grammar, uri, ns); p.DataProvider = grammar.Provider; RdpPattern ret = p.Compile (grammar); grammar.IncludedUris.Remove (Href); return ret; }
// compile into div internal RelaxngDiv Compile(RelaxngGrammar grammar) { grammar.CheckIncludeRecursion(Href); grammar.IncludedUris.Add(Href, Href); if (grammar.Resolver == null) { throw new RelaxngException(this, "To compile 'include' element, XmlResolver is required."); } Uri baseUri = null; try { if (BaseUri != null && BaseUri != String.Empty) { baseUri = new Uri(BaseUri); } } catch (UriFormatException) { if (File.Exists(BaseUri)) { baseUri = new Uri(Path.GetFullPath(BaseUri)); } } Uri uri = grammar.Resolver.ResolveUri(baseUri, Href); RelaxngGrammar g = ReadExternalResource(grammar, uri, (ns != null && ns.Length != 0) || !grammar.IsSourceCompactSyntax ? ns : grammar.DefaultNamespace) as RelaxngGrammar; if (g == null) { throw new RelaxngException(this, "Included syntax must start with \"grammar\" element."); } g.DataProvider = grammar.Provider; g.IsSourceCompactSyntax = grammar.IsSourceCompactSyntax; // process recursive inclusions. foreach (RelaxngInclude inc in g.Includes) { g.Divs.Add(inc.Compile(grammar)); } // process this own div children. // each div subelements are also compiled. foreach (RelaxngDiv cdiv in divs) { cdiv.Compile(g); } foreach (RelaxngDiv cdiv in g.Divs) { cdiv.Compile(g); } // replace redifinitions into div. // starts. if (this.Starts.Count > 0 && g.Starts.Count == 0) { throw new RelaxngException(this, "When the included grammar does not contain start components, this include component must not contain start components."); } RelaxngGrammarContentList appliedStarts = (this.starts.Count > 0) ? this.starts : g.Starts; RelaxngDiv div = new RelaxngDiv(); div.BaseUri = this.BaseUri; div.LinePosition = this.LinePosition; div.LineNumber = this.LineNumber; foreach (RelaxngStart start in appliedStarts) { div.Starts.Add(start); } // defines. Hashtable overrides = new Hashtable(); Hashtable originalDefs = new Hashtable(); foreach (RelaxngDefine def in defines) { overrides.Add(def.Name, def.Name); div.Defines.Add(def); } foreach (RelaxngDefine def in g.Defines) { originalDefs [def.Name] = def.Name; if (!overrides.ContainsKey(def.Name)) { div.Defines.Add(def); } // else discard. } foreach (string name in overrides.Values) { if (!originalDefs.ContainsKey(name)) { throw new RelaxngException(this, "The include component must not contain define components whose name does not appear in the included grammar component."); } } grammar.IncludedUris.Remove(Href); return(div); }