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

  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            //%/////////////////////////////////////////////////////////////////////////////
 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.23 #include <Pegasus/Common/Buffer.h>
 43 mike  1.11 
 44            PEGASUS_NAMESPACE_BEGIN
 45            
 46            class PEGASUS_COMMON_LINKAGE XmlException : public Exception
 47            {
 48            public:
 49            
 50                enum Code
 51                {
 52 kumpf 1.28         BAD_START_TAG = 1,
 53                    BAD_END_TAG,
 54                    BAD_ATTRIBUTE_NAME,
 55                    EXPECTED_EQUAL_SIGN,
 56                    BAD_ATTRIBUTE_VALUE,
 57                    MINUS_MINUS_IN_COMMENT,
 58                    UNTERMINATED_COMMENT,
 59                    UNTERMINATED_CDATA,
 60                    UNTERMINATED_DOCTYPE,
 61                    MALFORMED_REFERENCE,
 62                    EXPECTED_COMMENT_OR_CDATA,
 63                    START_END_MISMATCH,
 64                    UNCLOSED_TAGS,
 65                    MULTIPLE_ROOTS,
 66                    VALIDATION_ERROR,
 67 kumpf 1.31         SEMANTIC_ERROR,
 68                    UNDECLARED_NAMESPACE
 69 mike  1.11     };
 70            
 71 chuck 1.18 
 72 mike  1.11     XmlException(
 73 kumpf 1.28         Code code,
 74                    Uint32 lineNumber,
 75                    const String& message = String());
 76            
 77            
 78 chuck 1.18     XmlException(
 79 kumpf 1.28         Code code,
 80                    Uint32 lineNumber,
 81                    MessageLoaderParms& msgParms);
 82 chuck 1.18 
 83 mike  1.11 
 84                XmlException::Code getCode() const { return _code; }
 85            
 86            private:
 87            
 88                Code _code;
 89            };
 90            
 91            class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
 92            {
 93            public:
 94            
 95                XmlValidationError(Uint32 lineNumber, const String& message);
 96 kumpf 1.28     XmlValidationError(Uint32 lineNumber, MessageLoaderParms& msgParms);
 97 mike  1.11 };
 98            
 99            class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
100            {
101            public:
102            
103                XmlSemanticError(Uint32 lineNumber, const String& message);
104 kumpf 1.28     XmlSemanticError(Uint32 lineNumber, MessageLoaderParms& msgParms);
105 mike  1.11 };
106            
107 kumpf 1.31 struct XmlNamespace
108            {
109                const char* localName;
110                const char* extendedName;
111                int type;
112                Uint32 scopeLevel;
113            };
114            
115 mike  1.11 struct XmlAttribute
116            {
117 kumpf 1.31     int nsType;
118 mike  1.11     const char* name;
119 kumpf 1.31     const char* localName;
120 mike  1.11     const char* value;
121            };
122            
123            struct PEGASUS_COMMON_LINKAGE XmlEntry
124            {
125 kumpf 1.31     enum XmlEntryType
126 mike  1.11     {
127 kumpf 1.28         XML_DECLARATION,
128                    START_TAG,
129                    EMPTY_TAG,
130                    END_TAG,
131                    COMMENT,
132                    CDATA,
133                    DOCTYPE,
134                    CONTENT
135 mike  1.11     };
136            
137 kumpf 1.31     XmlEntryType type;
138 mike  1.11     const char* text;
139 kumpf 1.31     int nsType;            // Only applies to START_TAG, EMPTY_TAG, and END_TAG
140                const char* localName; // Only applies to START_TAG, EMPTY_TAG, and END_TAG
141                Array<XmlAttribute> attributes;
142 mike  1.11 
143                void print() const;
144            
145                const XmlAttribute* findAttribute(const char* name) const;
146            
147 kumpf 1.31     const XmlAttribute* findAttribute(int nsType, const char* name) const;
148            
149 mike  1.11     Boolean getAttributeValue(const char* name, Uint32& value) const;
150            
151                Boolean getAttributeValue(const char* name, Real32& value) const;
152            
153                Boolean getAttributeValue(const char* name, const char*& value) const;
154            
155                Boolean getAttributeValue(const char* name, String& value) const;
156            };
157            
158            inline int operator==(const XmlEntry&, const XmlEntry&)
159            {
160                return 0;
161            }
162            
163            class PEGASUS_COMMON_LINKAGE XmlParser
164            {
165            public:
166            
167                // Warning: this constructor modifies the text.
168            
169 kumpf 1.31     XmlParser(char* text, XmlNamespace* ns = 0);
170 mike  1.11 
171 venkat.puvvada 1.29     /** Comments are returned with entry if includeComment is true else 
172                             XmlParser ignores comments. Default is false.
173                         */
174                         Boolean next(XmlEntry& entry, Boolean includeComment = false);
175 mike           1.11 
176                         void putBack(XmlEntry& entry);
177                     
178                         ~XmlParser();
179                     
180                         Uint32 getStackSize() const { return _stack.size(); }
181                     
182                         Uint32 getLine() const { return _line; }
183                     
184 kumpf          1.31     XmlNamespace* getNamespace(int nsType);
185                     
186 mike           1.11 private:
187                     
188 kumpf          1.31     Boolean _getElementName(char*& p, const char*& localName);
189 mike           1.11 
190 kumpf          1.31     Boolean _getOpenElementName(
191                             char*& p,
192                             const char*& localName,
193                             Boolean& openCloseElement);
194 mike           1.11 
195 kumpf          1.31     void _getAttributeNameAndEqual(char*& p, const char*& localName);
196 mike           1.11 
197                         void _getComment(char*& p);
198                     
199                         void _getCData(char*& p);
200                     
201                         void _getDocType(char*& p);
202                     
203                         void _getElement(char*& p, XmlEntry& entry);
204                     
205 kumpf          1.31     int _getNamespaceType(const char* tag);
206                     
207                         int _getSupportedNamespaceType(const char* extendedName);
208                     
209 mike           1.11     Uint32 _line;
210                         char* _current;
211                         char _restoreChar;
212                         Stack<char*> _stack;
213                         Boolean _foundRoot;
214                         Stack<XmlEntry> _putBackStack;
215 kumpf          1.31 
216                         XmlNamespace* _supportedNamespaces;
217                         Stack<XmlNamespace> _nameSpaces;
218                         int _currentUnsupportedNSType;
219 mike           1.11 };
220                     
221                     PEGASUS_COMMON_LINKAGE void XmlAppendCString(
222 kumpf          1.28     Buffer& out,
223 mike           1.11     const char* str);
224                     
225                     PEGASUS_NAMESPACE_END
226                     
227                     #endif /* Pegasus_XmlParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2