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