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