1 martin 1.33 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.34 //
|
3 martin 1.33 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.34 //
|
10 martin 1.33 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.34 //
|
17 martin 1.33 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.34 //
|
20 martin 1.33 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.34 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.33 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.34 //
|
28 martin 1.33 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.11 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_XmlParser_h
33 #define Pegasus_XmlParser_h
34
35 #include <Pegasus/Common/Config.h>
|
36 kumpf 1.17 #include <Pegasus/Common/ArrayInternal.h>
|
37 kumpf 1.16 #include <Pegasus/Common/InternalException.h>
|
38 mike 1.11 #include <Pegasus/Common/Stack.h>
|
39 kumpf 1.15 #include <Pegasus/Common/Linkage.h>
|
40 mike 1.23 #include <Pegasus/Common/Buffer.h>
|
41 mike 1.11
42 PEGASUS_NAMESPACE_BEGIN
43
44 class PEGASUS_COMMON_LINKAGE XmlException : public Exception
45 {
46 public:
47
48 enum Code
49 {
|
50 kumpf 1.28 BAD_START_TAG = 1,
51 BAD_END_TAG,
52 BAD_ATTRIBUTE_NAME,
53 EXPECTED_EQUAL_SIGN,
54 BAD_ATTRIBUTE_VALUE,
55 MINUS_MINUS_IN_COMMENT,
56 UNTERMINATED_COMMENT,
57 UNTERMINATED_CDATA,
58 UNTERMINATED_DOCTYPE,
59 MALFORMED_REFERENCE,
60 EXPECTED_COMMENT_OR_CDATA,
61 START_END_MISMATCH,
62 UNCLOSED_TAGS,
63 MULTIPLE_ROOTS,
64 VALIDATION_ERROR,
|
65 kumpf 1.31 SEMANTIC_ERROR,
66 UNDECLARED_NAMESPACE
|
67 mike 1.11 };
68
|
69 chuck 1.18
|
70 mike 1.11 XmlException(
|
71 kumpf 1.28 Code code,
72 Uint32 lineNumber,
73 const String& message = String());
74
75
|
76 chuck 1.18 XmlException(
|
77 kumpf 1.28 Code code,
78 Uint32 lineNumber,
79 MessageLoaderParms& msgParms);
|
80 chuck 1.18
|
81 mike 1.11
82 XmlException::Code getCode() const { return _code; }
83
84 private:
85
86 Code _code;
87 };
88
89 class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
90 {
91 public:
92
93 XmlValidationError(Uint32 lineNumber, const String& message);
|
94 kumpf 1.28 XmlValidationError(Uint32 lineNumber, MessageLoaderParms& msgParms);
|
95 mike 1.11 };
96
97 class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
98 {
99 public:
100
101 XmlSemanticError(Uint32 lineNumber, const String& message);
|
102 kumpf 1.28 XmlSemanticError(Uint32 lineNumber, MessageLoaderParms& msgParms);
|
103 mike 1.11 };
104
|
105 kumpf 1.31 struct XmlNamespace
106 {
107 const char* localName;
108 const char* extendedName;
109 int type;
110 Uint32 scopeLevel;
111 };
112
|
113 mike 1.11 struct XmlAttribute
114 {
|
115 kumpf 1.31 int nsType;
|
116 mike 1.11 const char* name;
|
117 kumpf 1.31 const char* localName;
|
118 mike 1.11 const char* value;
119 };
120
121 struct PEGASUS_COMMON_LINKAGE XmlEntry
122 {
|
123 kumpf 1.31 enum XmlEntryType
|
124 mike 1.11 {
|
125 kumpf 1.28 XML_DECLARATION,
126 START_TAG,
127 EMPTY_TAG,
128 END_TAG,
129 COMMENT,
130 CDATA,
131 DOCTYPE,
132 CONTENT
|
133 mike 1.11 };
134
|
135 kumpf 1.31 XmlEntryType type;
|
136 mike 1.11 const char* text;
|
137 kumpf 1.31 int nsType; // Only applies to START_TAG, EMPTY_TAG, and END_TAG
138 const char* localName; // Only applies to START_TAG, EMPTY_TAG, and END_TAG
|
139 venkat.puvvada 1.36 Uint32 textLen; // Only applies to CDATA and CONTENT
140
|
141 kumpf 1.31 Array<XmlAttribute> attributes;
|
142 mike 1.11
143 void print() const;
144
145 const XmlAttribute* findAttribute(const char* name) const;
146
|
147 kumpf 1.32 const XmlAttribute* findAttribute(int attrNsType, const char* name) const;
|
148 kumpf 1.31
|
149 mike 1.11 Boolean getAttributeValue(const char* name, Uint32& value) const;
150
151 Boolean getAttributeValue(const char* name, Real32& value) const;
152
153 Boolean getAttributeValue(const char* name, const char*& value) const;
154
155 Boolean getAttributeValue(const char* name, String& value) const;
156 };
157
158 inline int operator==(const XmlEntry&, const XmlEntry&)
159 {
160 return 0;
161 }
162
163 class PEGASUS_COMMON_LINKAGE XmlParser
164 {
165 public:
166
167 // Warning: this constructor modifies the text.
168
|
169 mike 1.37 /** If hideEmptyTags if true, next() hides empty tags from the caller.
170 Instead, next() returns a fake start tag. The subsequent next() call
171 returns a fake end tag. This relieves the caller from having to do
172 special processing of empty tags, which can be tricky and error-prone.
173 */
174 XmlParser(char* text, XmlNamespace* ns = 0, Boolean hideEmptyTags = false);
|
175 mike 1.11
|
176 kumpf 1.35 /** Comments are returned with entry if includeComment is true else
|
177 venkat.puvvada 1.29 XmlParser ignores comments. Default is false.
178 */
179 Boolean next(XmlEntry& entry, Boolean includeComment = false);
|
180 mike 1.11
181 void putBack(XmlEntry& entry);
182
183 ~XmlParser();
184
185 Uint32 getStackSize() const { return _stack.size(); }
186
187 Uint32 getLine() const { return _line; }
188
|
189 kumpf 1.31 XmlNamespace* getNamespace(int nsType);
190
|
191 mike 1.37 void setHideEmptyTags(bool flag) { _hideEmptyTags = flag; }
192
|
193 thilo.boehm 1.38 bool getHideEmptyTags() const { return _hideEmptyTags; }
|
194 mike 1.37
|
195 mike 1.11 private:
196
|
197 mike 1.37 Boolean _next(XmlEntry& entry, Boolean includeComment = false);
198
|
199 kumpf 1.31 Boolean _getElementName(char*& p, const char*& localName);
|
200 mike 1.11
|
201 kumpf 1.31 Boolean _getOpenElementName(
202 char*& p,
203 const char*& localName,
204 Boolean& openCloseElement);
|
205 mike 1.11
|
206 kumpf 1.31 void _getAttributeNameAndEqual(char*& p, const char*& localName);
|
207 mike 1.11
208 void _getComment(char*& p);
209
210 void _getCData(char*& p);
211
212 void _getDocType(char*& p);
213
214 void _getElement(char*& p, XmlEntry& entry);
215
|
216 kumpf 1.31 int _getNamespaceType(const char* tag);
217
218 int _getSupportedNamespaceType(const char* extendedName);
219
|
220 mike 1.11 Uint32 _line;
221 char* _current;
222 char _restoreChar;
223 Stack<char*> _stack;
224 Boolean _foundRoot;
225 Stack<XmlEntry> _putBackStack;
|
226 kumpf 1.31
227 XmlNamespace* _supportedNamespaces;
228 Stack<XmlNamespace> _nameSpaces;
229 int _currentUnsupportedNSType;
|
230 mike 1.37 Boolean _hideEmptyTags;
|
231 mike 1.11 };
232
233 PEGASUS_COMMON_LINKAGE void XmlAppendCString(
|
234 kumpf 1.28 Buffer& out,
|
235 mike 1.11 const char* str);
236
237 PEGASUS_NAMESPACE_END
238
239 #endif /* Pegasus_XmlParser_h */
|