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

  1 martin 1.33 //%LICENSE////////////////////////////////////////////////////////////////
  2             // 
  3             // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9             // 
 10             // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16             // 
 17             // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19             // 
 20             // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21             // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 22 martin 1.33 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 mike   1.11 // 
 28 martin 1.33 //////////////////////////////////////////////////////////////////////////
 29 mike   1.11 //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #ifndef Pegasus_XmlParser_h
 33             #define Pegasus_XmlParser_h
 34             
 35             #include <Pegasus/Common/Config.h>
 36 kumpf  1.17 #include <Pegasus/Common/ArrayInternal.h>
 37 kumpf  1.16 #include <Pegasus/Common/InternalException.h>
 38 mike   1.11 #include <Pegasus/Common/Stack.h>
 39 kumpf  1.15 #include <Pegasus/Common/Linkage.h>
 40 mike   1.23 #include <Pegasus/Common/Buffer.h>
 41 mike   1.11 
 42             PEGASUS_NAMESPACE_BEGIN
 43             
 44             class PEGASUS_COMMON_LINKAGE XmlException : public Exception
 45             {
 46             public:
 47             
 48                 enum Code
 49                 {
 50 kumpf  1.28         BAD_START_TAG = 1,
 51                     BAD_END_TAG,
 52                     BAD_ATTRIBUTE_NAME,
 53                     EXPECTED_EQUAL_SIGN,
 54                     BAD_ATTRIBUTE_VALUE,
 55                     MINUS_MINUS_IN_COMMENT,
 56                     UNTERMINATED_COMMENT,
 57                     UNTERMINATED_CDATA,
 58                     UNTERMINATED_DOCTYPE,
 59                     MALFORMED_REFERENCE,
 60                     EXPECTED_COMMENT_OR_CDATA,
 61                     START_END_MISMATCH,
 62                     UNCLOSED_TAGS,
 63                     MULTIPLE_ROOTS,
 64                     VALIDATION_ERROR,
 65 kumpf  1.31         SEMANTIC_ERROR,
 66                     UNDECLARED_NAMESPACE
 67 mike   1.11     };
 68             
 69 chuck  1.18 
 70 mike   1.11     XmlException(
 71 kumpf  1.28         Code code,
 72                     Uint32 lineNumber,
 73                     const String& message = String());
 74             
 75             
 76 chuck  1.18     XmlException(
 77 kumpf  1.28         Code code,
 78                     Uint32 lineNumber,
 79                     MessageLoaderParms& msgParms);
 80 chuck  1.18 
 81 mike   1.11 
 82                 XmlException::Code getCode() const { return _code; }
 83             
 84             private:
 85             
 86                 Code _code;
 87             };
 88             
 89             class PEGASUS_COMMON_LINKAGE XmlValidationError : public XmlException
 90             {
 91             public:
 92             
 93                 XmlValidationError(Uint32 lineNumber, const String& message);
 94 kumpf  1.28     XmlValidationError(Uint32 lineNumber, MessageLoaderParms& msgParms);
 95 mike   1.11 };
 96             
 97             class PEGASUS_COMMON_LINKAGE XmlSemanticError : public XmlException
 98             {
 99             public:
100             
101                 XmlSemanticError(Uint32 lineNumber, const String& message);
102 kumpf  1.28     XmlSemanticError(Uint32 lineNumber, MessageLoaderParms& msgParms);
103 mike   1.11 };
104             
105 kumpf  1.31 struct XmlNamespace
106             {
107                 const char* localName;
108                 const char* extendedName;
109                 int type;
110                 Uint32 scopeLevel;
111             };
112             
113 mike   1.11 struct XmlAttribute
114             {
115 kumpf  1.31     int nsType;
116 mike   1.11     const char* name;
117 kumpf  1.31     const char* localName;
118 mike   1.11     const char* value;
119             };
120             
121             struct PEGASUS_COMMON_LINKAGE XmlEntry
122             {
123 kumpf  1.31     enum XmlEntryType
124 mike   1.11     {
125 kumpf  1.28         XML_DECLARATION,
126                     START_TAG,
127                     EMPTY_TAG,
128                     END_TAG,
129                     COMMENT,
130                     CDATA,
131                     DOCTYPE,
132                     CONTENT
133 mike   1.11     };
134             
135 kumpf  1.31     XmlEntryType type;
136 mike   1.11     const char* text;
137 kumpf  1.31     int nsType;            // Only applies to START_TAG, EMPTY_TAG, and END_TAG
138                 const char* localName; // Only applies to START_TAG, EMPTY_TAG, and END_TAG
139                 Array<XmlAttribute> attributes;
140 mike   1.11 
141                 void print() const;
142             
143                 const XmlAttribute* findAttribute(const char* name) const;
144             
145 kumpf  1.32     const XmlAttribute* findAttribute(int attrNsType, const char* name) const;
146 kumpf  1.31 
147 mike   1.11     Boolean getAttributeValue(const char* name, Uint32& value) const;
148             
149                 Boolean getAttributeValue(const char* name, Real32& value) const;
150             
151                 Boolean getAttributeValue(const char* name, const char*& value) const;
152             
153                 Boolean getAttributeValue(const char* name, String& value) const;
154             };
155             
156             inline int operator==(const XmlEntry&, const XmlEntry&)
157             {
158                 return 0;
159             }
160             
161             class PEGASUS_COMMON_LINKAGE XmlParser
162             {
163             public:
164             
165                 // Warning: this constructor modifies the text.
166             
167 kumpf  1.31     XmlParser(char* text, XmlNamespace* ns = 0);
168 mike   1.11 
169 venkat.puvvada 1.29     /** Comments are returned with entry if includeComment is true else 
170                             XmlParser ignores comments. Default is false.
171                         */
172                         Boolean next(XmlEntry& entry, Boolean includeComment = false);
173 mike           1.11 
174                         void putBack(XmlEntry& entry);
175                     
176                         ~XmlParser();
177                     
178                         Uint32 getStackSize() const { return _stack.size(); }
179                     
180                         Uint32 getLine() const { return _line; }
181                     
182 kumpf          1.31     XmlNamespace* getNamespace(int nsType);
183                     
184 mike           1.11 private:
185                     
186 kumpf          1.31     Boolean _getElementName(char*& p, const char*& localName);
187 mike           1.11 
188 kumpf          1.31     Boolean _getOpenElementName(
189                             char*& p,
190                             const char*& localName,
191                             Boolean& openCloseElement);
192 mike           1.11 
193 kumpf          1.31     void _getAttributeNameAndEqual(char*& p, const char*& localName);
194 mike           1.11 
195                         void _getComment(char*& p);
196                     
197                         void _getCData(char*& p);
198                     
199                         void _getDocType(char*& p);
200                     
201                         void _getElement(char*& p, XmlEntry& entry);
202                     
203 kumpf          1.31     int _getNamespaceType(const char* tag);
204                     
205                         int _getSupportedNamespaceType(const char* extendedName);
206                     
207 mike           1.11     Uint32 _line;
208                         char* _current;
209                         char _restoreChar;
210                         Stack<char*> _stack;
211                         Boolean _foundRoot;
212                         Stack<XmlEntry> _putBackStack;
213 kumpf          1.31 
214                         XmlNamespace* _supportedNamespaces;
215                         Stack<XmlNamespace> _nameSpaces;
216                         int _currentUnsupportedNSType;
217 mike           1.11 };
218                     
219                     PEGASUS_COMMON_LINKAGE void XmlAppendCString(
220 kumpf          1.28     Buffer& out,
221 mike           1.11     const char* str);
222                     
223                     PEGASUS_NAMESPACE_END
224                     
225                     #endif /* Pegasus_XmlParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2