Merge pull request #319 from pragmatrix/master
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaWhiteSpaceFacet.cs
1 // Author: Dwivedi, Ajay kumar
2 //            Adwiv@Yahoo.com
3
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 using System;
25 using System.Xml;
26
27 namespace System.Xml.Schema
28 {
29         /// <summary>
30         /// Summary description for XmlSchemaWhiteSpaceFacet.
31         /// </summary>
32         public class XmlSchemaWhiteSpaceFacet : XmlSchemaFacet
33         {
34                 const string xmlname = "whiteSpace";
35
36                 public XmlSchemaWhiteSpaceFacet()
37                 {
38                 }
39                         
40                 internal override Facet ThisFacet { 
41                         get { return Facet.whiteSpace;}
42                 }
43         
44                 //      <whiteSpace
45                 //      fixed = boolean : false
46                 //      id = ID
47                 //      value = (collapse | preserve | replace)
48                 //      {any attributes with non-schema namespace . . .}>
49                 //      Content: (annotation?)
50                 //      </whiteSpace>
51                 internal static XmlSchemaWhiteSpaceFacet Read(XmlSchemaReader reader, ValidationEventHandler h)
52                 {
53                         XmlSchemaWhiteSpaceFacet ws = new XmlSchemaWhiteSpaceFacet();
54                         reader.MoveToElement();
55
56                         if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
57                         {
58                                 error(h,"Should not happen :1: XmlSchemaWhiteSpaceFacet.Read, name="+reader.Name,null);
59                                 reader.Skip();
60                                 return null;
61                         }
62
63                         ws.LineNumber = reader.LineNumber;
64                         ws.LinePosition = reader.LinePosition;
65                         ws.SourceUri = reader.BaseURI;
66
67                         while(reader.MoveToNextAttribute())
68                         {
69                                 if(reader.Name == "id")
70                                 {
71                                         ws.Id = reader.Value;
72                                 }
73                                 else if(reader.Name == "fixed")
74                                 {
75                                         Exception innerex;
76                                         ws.IsFixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
77                                         if(innerex != null)
78                                                 error(h, reader.Value + " is not a valid value for fixed attribute",innerex);
79                                 }
80                                 else if(reader.Name == "value")
81                                 {
82                                         ws.Value = reader.Value;
83                                 }
84                                 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
85                                 {
86                                         error(h,reader.Name + " is not a valid attribute for "+xmlname,null);
87                                 }
88                                 else
89                                 {
90                                         XmlSchemaUtil.ReadUnhandledAttribute(reader,ws);
91                                 }
92                         }
93                         
94                         reader.MoveToElement();
95                         if(reader.IsEmptyElement)
96                                 return ws;
97
98                         //  Content: (annotation?)
99                         int level = 1;
100                         while(reader.ReadNextElement())
101                         {
102                                 if(reader.NodeType == XmlNodeType.EndElement)
103                                 {
104                                         if(reader.LocalName != xmlname)
105                                                 error(h,"Should not happen :2: XmlSchemaWhiteSpaceFacet.Read, name="+reader.Name,null);
106                                         break;
107                                 }
108                                 if(level <= 1 && reader.LocalName == "annotation")
109                                 {
110                                         level = 2;      //Only one annotation
111                                         XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
112                                         if(annotation != null)
113                                                 ws.Annotation = annotation;
114                                         continue;
115                                 }
116                                 reader.RaiseInvalidElementError();
117                         }                       
118                         return ws;
119                 }
120
121
122         }
123 }