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