Copied remotely
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocumentType.cs
1 //\r
2 // System.Xml.XmlDocumentType.cs\r
3 //\r
4 // Author: Duncan Mak (duncan@ximian.com)\r
5 //         Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)\r
6 //\r
7 // (C) Ximian, Inc.\r
8 //\r
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 using System;\r
31 using System.IO;\r
32 using System.Collections;\r
33 using Mono.Xml;\r
34 \r
35 #if NET_2_0\r
36 using XmlTextReaderImpl = Mono.Xml2.XmlTextReader;\r
37 #else\r
38 using XmlTextReaderImpl = System.Xml.XmlTextReader;\r
39 #endif\r
40 \r
41 namespace System.Xml\r
42 {\r
43         public class XmlDocumentType  : XmlLinkedNode\r
44         {\r
45                 // Fields\r
46                 internal XmlNamedNodeMap entities;\r
47                 internal XmlNamedNodeMap notations;\r
48                 DTDObjectModel dtd;\r
49 \r
50                 // Constructor\r
51                 protected internal XmlDocumentType (string name, string publicId,\r
52                                                     string systemId, string internalSubset,\r
53                                                     XmlDocument doc)\r
54                         : base (doc)\r
55                 {\r
56                         XmlTextReaderImpl xtr = new XmlTextReaderImpl (BaseURI, new StringReader (""), doc.NameTable);\r
57                         xtr.XmlResolver = doc.Resolver;\r
58                         xtr.GenerateDTDObjectModel (name, publicId, systemId, internalSubset);\r
59                         this.dtd = xtr.DTD;\r
60 \r
61                         ImportFromDTD ();\r
62                 }\r
63 \r
64                 internal XmlDocumentType (DTDObjectModel dtd, XmlDocument doc)\r
65                         : base (doc)\r
66                 {\r
67                         this.dtd = dtd;\r
68                         ImportFromDTD ();\r
69                 }\r
70 \r
71                 private void ImportFromDTD ()\r
72                 {\r
73                         entities = new XmlNamedNodeMap (this);\r
74                         notations = new XmlNamedNodeMap (this);\r
75 \r
76                         foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) {
77                                 XmlNode n = new XmlEntity (decl.Name, decl.NotationName,
78                                         decl.PublicId, decl.SystemId, OwnerDocument);
79                                 entities.SetNamedItem (n);
80                         }
81                         foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) {
82                                 XmlNode n = new XmlNotation (decl.LocalName, decl.Prefix,
83                                         decl.PublicId, decl.SystemId, OwnerDocument);
84                                 notations.SetNamedItem (n);
85                         }
86                 }\r
87 \r
88                 // Properties\r
89                 internal DTDObjectModel DTD {\r
90                         get { return dtd; }\r
91                 }\r
92 \r
93                 public XmlNamedNodeMap Entities\r
94                 {\r
95                         get { return entities; }\r
96                 }\r
97                         \r
98                 public string InternalSubset\r
99                 {\r
100                         get { return dtd.InternalSubset; }\r
101                 }\r
102 \r
103                 public override bool IsReadOnly\r
104                 {\r
105                         get { return true; } // always return true\r
106                 }\r
107 \r
108                 public override string LocalName\r
109                 {\r
110                         get { return dtd.Name; }\r
111                 }\r
112 \r
113                 public override string Name\r
114                 {\r
115                         get { return dtd.Name; }\r
116                 }\r
117 \r
118                 public override XmlNodeType NodeType\r
119                 {\r
120                         get { return XmlNodeType.DocumentType; }\r
121                 }\r
122 \r
123                 public XmlNamedNodeMap Notations\r
124                 {\r
125                         get { return notations; }\r
126                 }\r
127 \r
128                 public string PublicId\r
129                 {\r
130                         get { return dtd.PublicId; }\r
131                 }\r
132 \r
133                 public string SystemId\r
134                 {\r
135                         get { return dtd.SystemId; }\r
136                 }\r
137 \r
138                 // Methods\r
139                 public override XmlNode CloneNode (bool deep)\r
140                 {\r
141                         // deep is ignored\r
142                         return new XmlDocumentType (dtd, OwnerDocument);\r
143                 }\r
144                 \r
145                 public override void WriteContentTo (XmlWriter w)\r
146                 {\r
147                         // No effect\r
148                 }\r
149 \r
150                 public override void WriteTo (XmlWriter w)\r
151                 {\r
152                         w.WriteDocType (Name, PublicId, SystemId, InternalSubset);\r
153                 }\r
154         }\r
155 }\r