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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2