1 mike 1.1 //BEGIN_LICENSE
2 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
20 //END_LICENSE
21 //BEGIN_HISTORY
22 mike 1.1 //
23 // Author:
24 //
25 // $Log$
26 //
27 //END_HISTORY
28
29 ////////////////////////////////////////////////////////////////////////////////
30 //
31 // XmlParser.h
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34
35 #ifndef Pegasus_XmlParser_h
36 #define Pegasus_XmlParser_h
37
38 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/Array.h>
40 #include <Pegasus/Common/Exception.h>
41 #include <Pegasus/Common/Stack.h>
42
43 mike 1.1 PEGASUS_NAMESPACE_BEGIN
44
45 class PEGASUS_COMMON_LINKAGE XmlException : public Exception
46 {
47 public:
48
49 enum Code
50 {
51 BAD_START_TAG = 1,
52 BAD_END_TAG,
53 BAD_ATTRIBUTE_NAME,
54 EXPECTED_EQUAL_SIGN,
55 BAD_ATTRIBUTE_VALUE,
56 MINUS_MINUS_IN_COMMENT,
57 UNTERMINATED_COMMENT,
58 UNTERMINATED_CDATA,
59 UNTERMINATED_DOCTYPE,
60 TOO_MANY_ATTRIBUTES,
61 MALFORMED_REFERENCE,
62 EXPECTED_COMMENT_OR_CDATA,
63 START_END_MISMATCH,
64 mike 1.1 UNCLOSED_TAGS,
65 MULTIPLE_ROOTS,
66 VALIDATION_ERROR,
67 SEMANTIC_ERROR
68 };
69
70 XmlException(
71 Code code,
72 Uint32 lineNumber,
73 const String& message = String());
74
75 XmlException::Code getCode() const { return _code; }
76
77 private:
78
79 Code _code;
80 };
81
82 class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
83 {
84 public:
85 mike 1.1
86 XmlValidationError(Uint32 lineNumber, const String& message);
87 };
88
89 class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
90 {
91 public:
92
93 XmlSemanticError(Uint32 lineNumber, const String& message);
94 };
95
96 struct XmlAttribute
97 {
98 const char* name;
99 const char* value;
100 };
101
102 struct PEGASUS_COMMON_LINKAGE XmlEntry
103 {
104 enum Type
105 {
106 mike 1.1 XML_DECLARATION,
107 START_TAG,
108 EMPTY_TAG,
109 END_TAG,
110 COMMENT,
111 CDATA,
112 DOCTYPE,
113 CONTENT
114 };
115
116 enum { MAX_ATTRIBUTES = 10 };
117
118 Type type;
119 const char* text;
120 XmlAttribute attributes[MAX_ATTRIBUTES];
121 Uint32 attributeCount;
122
123 void print() const;
124
125 const XmlAttribute* findAttribute(const char* name) const;
126
127 mike 1.1 Boolean getAttributeValue(const char* name, Uint32& value) const;
128
129 Boolean getAttributeValue(const char* name, Real32& value) const;
130
131 Boolean getAttributeValue(const char* name, const char*& value) const;
132
133 Boolean getAttributeValue(const char* name, String& value) const;
134 };
135
136 class PEGASUS_COMMON_LINKAGE XmlParser
137 {
138 public:
139
140 // Warning: this constructor modifies the text.
141
142 XmlParser(char* text);
143
144 Boolean next(XmlEntry& entry);
145
146 void putBack(XmlEntry& entry);
147
148 mike 1.1 ~XmlParser();
149
150 Uint32 getStackSize() const { return _stack.getSize(); }
151
152 Uint32 getLine() const { return _line; }
153
154 private:
155
156 void _skipWhitespace(char*& p);
157
158 Boolean _getElementName(char*& p);
159
160 Boolean _getOpenElementName(char*& p, Boolean& openCloseElement);
161
162 void _getAttributeNameAndEqual(char*& p);
163
164 void _getAttributeValue(char*& p);
165
166 void _getComment(char*& p);
167
168 void _getCData(char*& p);
169 mike 1.1
170 void _getDocType(char*& p);
171
172 void _getContent(char*& p);
173
174 void _substituteReferences(char* text);
175
176 void _getElement(char*& p, XmlEntry& entry);
177
178 Uint32 _line;
179 char* _text;
180 char* _current;
181 char _restoreChar;
182 Stack<char*> _stack;
183 Boolean _foundRoot;
184 Stack<XmlEntry> _putBackStack;
185 };
186
187 inline void XmlAppendCString(Array<Sint8>& out, const char* str)
188 {
189 out.append(str, strlen(str));
190 mike 1.1 }
191
192 PEGASUS_COMMON_LINKAGE void XmlAppendString(
193 Array<Sint8>& out,
194 const String& str);
195
196 PEGASUS_NAMESPACE_END
197
198 #endif /* Pegasus_XmlParser_h */
|