(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / System.Xml / XmlParserContext.cs
blob62a3cf5da29d72bd063057b1c8fd2b9b697ea215
1 //
2 // System.Xml.XmlParserContext
3 //
4 // Author:
5 // Jason Diamond (jason@injektilo.org)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //
8 // (C) 2001, 2002 Jason Diamond http://injektilo.org/
9 // (C) 2003 Atsushi Enomoto
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Text;
34 using Mono.Xml;
36 #if NET_2_0
37 using XmlTextReaderImpl = Mono.Xml2.XmlTextReader;
38 #else
39 using XmlTextReaderImpl = System.Xml.XmlTextReader;
40 #endif
42 namespace System.Xml
44 public class XmlParserContext
46 #region Class
47 class ContextItem
49 public string BaseURI;
50 public string XmlLang;
51 public XmlSpace XmlSpace;
53 #endregion
55 #region Constructors
57 public XmlParserContext (
58 XmlNameTable nt,
59 XmlNamespaceManager nsMgr,
60 string xmlLang,
61 XmlSpace xmlSpace) :
63 this (
64 nt,
65 nsMgr,
66 null,
67 null,
68 null,
69 null,
70 null,
71 xmlLang,
72 xmlSpace,
73 null
78 public XmlParserContext (
79 XmlNameTable nt,
80 XmlNamespaceManager nsMgr,
81 string xmlLang,
82 XmlSpace xmlSpace,
83 Encoding enc) :
85 this (
86 nt,
87 nsMgr,
88 null,
89 null,
90 null,
91 null,
92 null,
93 xmlLang,
94 xmlSpace,
95 enc
100 public XmlParserContext (
101 XmlNameTable nt,
102 XmlNamespaceManager nsMgr,
103 string docTypeName,
104 string pubId,
105 string sysId,
106 string internalSubset,
107 string baseURI,
108 string xmlLang,
109 XmlSpace xmlSpace) :
111 this (
113 nsMgr,
114 docTypeName,
115 pubId,
116 sysId,
117 internalSubset,
118 baseURI,
119 xmlLang,
120 xmlSpace,
121 null
126 public XmlParserContext (
127 XmlNameTable nt,
128 XmlNamespaceManager nsMgr,
129 string docTypeName,
130 string pubId,
131 string sysId,
132 string internalSubset,
133 string baseURI,
134 string xmlLang,
135 XmlSpace xmlSpace,
136 Encoding enc)
137 : this (
139 nsMgr,
140 (docTypeName != null && docTypeName != String.Empty) ?
141 new XmlTextReaderImpl ("", nt).GenerateDTDObjectModel (
142 docTypeName, pubId, sysId, internalSubset) : null,
143 baseURI,
144 xmlLang,
145 xmlSpace,
146 enc)
150 internal XmlParserContext (XmlNameTable nt,
151 XmlNamespaceManager nsMgr,
152 DTDObjectModel dtd,
153 string baseURI,
154 string xmlLang,
155 XmlSpace xmlSpace,
156 Encoding enc)
158 if (nt == null)
159 this.nameTable = nsMgr == null ? new NameTable () : nsMgr.NameTable;
160 else
161 this.nameTable = nt;
163 this.namespaceManager = nsMgr != null ? nsMgr : new XmlNamespaceManager (nameTable);
164 if (dtd != null) {
165 this.docTypeName = dtd.Name;
166 this.publicID = dtd.PublicId;
167 this.systemID = dtd.SystemId;
168 this.internalSubset = dtd.InternalSubset;
169 this.dtd = dtd;
171 this.encoding = enc;
173 this.baseURI = baseURI;
174 this.xmlLang = xmlLang;
175 this.xmlSpace = xmlSpace;
177 contextItems = new ArrayList ();
179 #endregion
181 #region Fields
183 private string baseURI;
184 private string docTypeName;
185 private Encoding encoding;
186 private string internalSubset;
187 private XmlNamespaceManager namespaceManager;
188 private XmlNameTable nameTable;
189 private string publicID;
190 private string systemID;
191 private string xmlLang;
192 private XmlSpace xmlSpace;
193 private ArrayList contextItems;
194 private int contextItemCount;
195 private DTDObjectModel dtd;
197 #endregion
199 #region Properties
201 public string BaseURI {
202 get { return baseURI; }
203 set { baseURI = value; }
206 public string DocTypeName {
207 get { return docTypeName != null ? docTypeName : dtd != null ? dtd.Name : null; }
208 set { docTypeName = value; }
211 internal DTDObjectModel Dtd {
212 get { return dtd; }
213 set { dtd = value; }
216 public Encoding Encoding {
217 get { return encoding; }
218 set { encoding = value; }
221 public string InternalSubset {
222 get { return internalSubset != null ? internalSubset : dtd != null ? dtd.InternalSubset : null; }
223 set { internalSubset = value; }
226 public XmlNamespaceManager NamespaceManager {
227 get { return namespaceManager; }
228 set { namespaceManager = value; }
231 public XmlNameTable NameTable {
232 get { return nameTable; }
233 set { nameTable = value; }
236 public string PublicId {
237 get { return publicID != null ? publicID : dtd != null ? dtd.PublicId : null; }
238 set { publicID = value; }
241 public string SystemId {
242 get { return systemID != null ? systemID : dtd != null ? dtd.SystemId : null; }
243 set { systemID = value; }
246 public string XmlLang {
247 get { return xmlLang; }
248 set { xmlLang = value; }
251 public XmlSpace XmlSpace {
252 get { return xmlSpace; }
253 set { xmlSpace = value; }
256 #endregion
258 #region Methods
259 internal void PushScope ()
261 ContextItem item = null;
262 if (contextItems.Count == contextItemCount) {
263 item = new ContextItem ();
264 contextItems.Add (item);
266 else
267 item = (ContextItem) contextItems [contextItemCount - 1];
268 item.BaseURI = BaseURI;
269 item.XmlLang = XmlLang;
270 item.XmlSpace = XmlSpace;
271 contextItemCount++;
274 internal void PopScope ()
276 contextItemCount--;
277 ContextItem prev = (ContextItem) contextItems [contextItemCount];
278 baseURI = prev.BaseURI;
279 xmlLang = prev.XmlLang;
280 xmlSpace = prev.XmlSpace;
282 #endregion