(file) Return to XmlParser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.8 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a copy
  6           // of this software and associated documentation files (the "Software"), to 
  7           // deal in the Software without restriction, including without limitation the 
  8           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9           // sell copies of the Software, and to permit persons to whom the Software is
 10           // furnished to do so, subject to the following conditions:
 11           // 
 12           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20           //
 21           //==============================================================================
 22 mike  1.8 //
 23           // Author: Mike Brasher (mbrasher@bmc.com)
 24           //
 25           // Modified By:
 26           //
 27           //%/////////////////////////////////////////////////////////////////////////////
 28           
 29           #ifndef Pegasus_XmlParser_h
 30           #define Pegasus_XmlParser_h
 31           
 32           #include <Pegasus/Common/Config.h>
 33           #include <Pegasus/Common/Array.h>
 34           #include <Pegasus/Common/Exception.h>
 35           #include <Pegasus/Common/Stack.h>
 36           
 37           PEGASUS_NAMESPACE_BEGIN
 38           
 39           class PEGASUS_COMMON_LINKAGE XmlException : public Exception
 40           {
 41           public:
 42           
 43 mike  1.8     enum Code
 44               {
 45           	BAD_START_TAG = 1,
 46           	BAD_END_TAG,
 47           	BAD_ATTRIBUTE_NAME,
 48           	EXPECTED_EQUAL_SIGN,
 49           	BAD_ATTRIBUTE_VALUE,
 50           	MINUS_MINUS_IN_COMMENT,
 51           	UNTERMINATED_COMMENT,
 52           	UNTERMINATED_CDATA,
 53           	UNTERMINATED_DOCTYPE,
 54           	TOO_MANY_ATTRIBUTES,
 55           	MALFORMED_REFERENCE,
 56           	EXPECTED_COMMENT_OR_CDATA,
 57           	START_END_MISMATCH,
 58           	UNCLOSED_TAGS,
 59           	MULTIPLE_ROOTS,
 60           	VALIDATION_ERROR,
 61           	SEMANTIC_ERROR
 62               };
 63           
 64 mike  1.8     XmlException(
 65           	Code code, 
 66           	Uint32 lineNumber,
 67           	const String& message = String());
 68           
 69               XmlException::Code getCode() const { return _code; }
 70           
 71           private:
 72           
 73               Code _code;
 74           };
 75           
 76           class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
 77           {
 78           public:
 79           
 80               XmlValidationError(Uint32 lineNumber, const String& message);
 81           };
 82           
 83           class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
 84           {
 85 mike  1.8 public:
 86           
 87               XmlSemanticError(Uint32 lineNumber, const String& message);
 88           };
 89           
 90           struct XmlAttribute
 91           {
 92               const char* name;
 93               const char* value;
 94           };
 95           
 96           struct PEGASUS_COMMON_LINKAGE XmlEntry
 97           {
 98               enum CIMType
 99               {
100           	XML_DECLARATION,
101           	START_TAG, 
102           	EMPTY_TAG, 
103           	END_TAG, 
104           	COMMENT,
105           	CDATA,
106 mike  1.8 	DOCTYPE,
107           	CONTENT
108               };
109           
110               enum { MAX_ATTRIBUTES = 10 };
111           
112               CIMType type;
113               const char* text;
114               XmlAttribute attributes[MAX_ATTRIBUTES];
115               Uint32 attributeCount;
116           
117               void print() const;
118           
119               const XmlAttribute* findAttribute(const char* name) const;
120           
121               Boolean getAttributeValue(const char* name, Uint32& value) const;
122           
123               Boolean getAttributeValue(const char* name, Real32& value) const;
124           
125               Boolean getAttributeValue(const char* name, const char*& value) const;
126           
127 mike  1.8     Boolean getAttributeValue(const char* name, String& value) const;
128           };
129           
130           PEGASUS_MEMORY_FUNCTIONS(XmlEntry)
131           
132           inline int operator==(const XmlEntry&, const XmlEntry&)
133           {
134               return 0;
135           }
136           
137           #define PEGASUS_ARRAY_T XmlEntry
138           # include "ArrayInter.h"
139           #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 mike  1.8 
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           
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 mike  1.8     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               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 mike  1.8 };
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 */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2