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

Diff for /pegasus/src/Pegasus/Common/XmlParser.cpp between version 1.37 and 1.43.2.4

version 1.37, 2006/01/11 20:49:25 version 1.43.2.4, 2008/03/12 23:40:26
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 27 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By: David Dillard, VERITAS Software Corp.  
 //                  (david.dillard@veritas.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 104 
Line 101 
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #define PEGASUS_ARRAY_T XmlEntry  
 # include "ArrayImpl.h"  
 #undef PEGASUS_ARRAY_T  
   
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // //
 // Static helper functions // Static helper functions
Line 186 
Line 179 
     "One or more tags are still open",     "One or more tags are still open",
     "More than one root element was encountered",     "More than one root element was encountered",
     "Validation error",     "Validation error",
     "Semantic error"      "Semantic error",
       "Malformed namespace declaration",
       "Namespace not supported",
       "Namespace not declared"
 }; };
  
 static const char* _xmlKeys[] = static const char* _xmlKeys[] =
Line 207 
Line 203 
     "Common.XmlParser.UNCLOSED_TAGS",     "Common.XmlParser.UNCLOSED_TAGS",
     "Common.XmlParser.MULTIPLE_ROOTS",     "Common.XmlParser.MULTIPLE_ROOTS",
     "Common.XmlParser.VALIDATION_ERROR",     "Common.XmlParser.VALIDATION_ERROR",
     "Common.XmlParser.SEMANTIC_ERROR"      "Common.XmlParser.SEMANTIC_ERROR",
       "Common.XmlParser.MALFORMED_NAMESPACE_DECL",
       "Common.XmlParser.UNSUPPORTED_NAMESPACE",
       "Common.XmlParser.UNDECLARED_NAMESPACE"
 }; };
  
 // l10n replace _formMessage (comment out the old one)  
 /*  
 static String _formMessage(Uint32 code, Uint32 line, const String& message)  
 {  
     String result = _xmlMessages[Uint32(code) - 1];  
   
     char buffer[32];  
     sprintf(buffer, "%d", line);  
     result.append(": on line ");  
     result.append(buffer);  
  
     if (message.size())  static MessageLoaderParms _formMessage(
     {      Uint32 code,
         result.append(": ");      Uint32 line,
         result.append(message);      const String& message)
     }  
   
     return result;  
 }  
 */  
   
 static MessageLoaderParms _formMessage(Uint32 code, Uint32 line, const String& message)  
 { {
     String dftMsg = _xmlMessages[Uint32(code) - 1];     String dftMsg = _xmlMessages[Uint32(code) - 1];
     String key = _xmlKeys[Uint32(code) - 1];     String key = _xmlKeys[Uint32(code) - 1];
Line 293 
Line 275 
     const String& message)     const String& message)
     : XmlException(XmlException::VALIDATION_ERROR, lineNumber, message)     : XmlException(XmlException::VALIDATION_ERROR, lineNumber, message)
 { {
   
 } }
  
  
Line 302 
Line 283 
     MessageLoaderParms& msgParms)     MessageLoaderParms& msgParms)
     : XmlException(XmlException::VALIDATION_ERROR, lineNumber, msgParms)     : XmlException(XmlException::VALIDATION_ERROR, lineNumber, msgParms)
 { {
   
 } }
  
  
Line 317 
Line 297 
     const String& message)     const String& message)
     : XmlException(XmlException::SEMANTIC_ERROR, lineNumber, message)     : XmlException(XmlException::SEMANTIC_ERROR, lineNumber, message)
 { {
   
 } }
  
  
Line 326 
Line 305 
     MessageLoaderParms& msgParms)     MessageLoaderParms& msgParms)
     : XmlException(XmlException::SEMANTIC_ERROR, lineNumber, msgParms)     : XmlException(XmlException::SEMANTIC_ERROR, lineNumber, msgParms)
 { {
   
 } }
  
  
Line 336 
Line 314 
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 XmlParser::XmlParser(char* text) : _line(1), _text(text), _current(text),  XmlParser::XmlParser(char* text, XmlNamespace* ns)
     _restoreChar('\0'), _foundRoot(false)      : _line(1),
         _current(text),
         _restoreChar('\0'),
         _foundRoot(false),
         _scopeLevel(0),
         _supportedNamespaces(ns)
 { {
   
 } }
  
 inline void _skipWhitespace(Uint32& line, char*& p) inline void _skipWhitespace(Uint32& line, char*& p)
Line 353 
Line 335 
     }     }
 } }
  
   #if defined(PEGASUS_PLATFORM_WIN64_IA64_MSVC) || \
       defined(PEGASUS_PLATFORM_WIN64_X86_64_MSVC)
   #pragma optimize( "", off )
   #endif
 static int _getEntityRef(char*& p) static int _getEntityRef(char*& p)
 { {
     if ((p[0] == 'g') && (p[1] == 't') && (p[2] == ';'))     if ((p[0] == 'g') && (p[1] == 't') && (p[2] == ';'))
Line 389 
Line 375 
  
     return -1;     return -1;
 } }
   #if defined(PEGASUS_PLATFORM_WIN64_IA64_MSVC) || \
       defined(PEGASUS_PLATFORM_WIN64_X86_64_MSVC)
   #pragma optimize( "", on )
   #endif
  
 static inline int _getCharRef(char*& p, bool hex) static inline int _getCharRef(char*& p, bool hex)
 { {
Line 507 
Line 497 
     }     }
 } }
  
 Boolean XmlParser::next(XmlEntry& entry)  Boolean XmlParser::next(
       XmlEntry& entry,
       Boolean includeComment)
 { {
       entry.attributes.clear();
   
     if (!_putBackStack.isEmpty())     if (!_putBackStack.isEmpty())
     {     {
         entry = _putBackStack.top();         entry = _putBackStack.top();
Line 529 
Line 523 
         _restoreChar = '\0';         _restoreChar = '\0';
     }     }
  
       // Loop until we are done with comments if includeComment is false.
       do
       {
     // Skip over any whitespace:     // Skip over any whitespace:
   
     _skipWhitespace(_line, _current);     _skipWhitespace(_line, _current);
  
     if (!*_current)     if (!*_current)
Line 572 
Line 568 
  
             _stack.pop();             _stack.pop();
         }         }
   
         return true;  
     }     }
     else     else
     {     {
Line 594 
Line 588 
  
         if (nullTerminator)         if (nullTerminator)
             *nullTerminator = '\0';             *nullTerminator = '\0';
           }
       } while (!includeComment && entry.type == XmlEntry::COMMENT);
   
       if (_supportedNamespaces &&
           (entry.type == XmlEntry::START_TAG ||
            entry.type == XmlEntry::EMPTY_TAG ||
            entry.type == XmlEntry::END_TAG))
       {
           // Process attributes and enter namespaces into the table
           if (entry.type == XmlEntry::START_TAG ||
               entry.type == XmlEntry::EMPTY_TAG)
           {
               _scopeLevel++;
               for (unsigned int i = 0; i < entry.attributes.size(); i++)
               {
                   XmlAttribute& attr = entry.attributes[i];
                   if (strncmp(attr.name, "xmlns", 5) == 0)
                   {
                       XmlNamespace ns;
                       if (attr.name[5] == ':')
                       {
                           ns.localName = attr.name + 6;
   
                           // Check if we have malformed XML of the form:
                           // "xmlns:=URI". In this case attr.name will be set
                           // to "xmlns:" and ns.localName will point to '\0'
                           if (ns.localName[0] == '\0')
                           {
                               throw XmlException(
                                   XmlException::MALFORMED_NAMESPACE_DECL,
                                   _line);
                           }
                       }
                       else
                       {
                           // Default name space has no local name
                           ns.localName = 0;
                       }
                       ns.extendedName = attr.value;
                       ns.scopeLevel = _scopeLevel;
                       ns.type = getSupportedNamespaceType(ns.extendedName);
   
                       // Even unsupported namespaces get pushed onto the stack.
                       // We will throw an exception of there is an attempt to
                       // reference an unsupported namespace later.
                       _nameSpaces.push(ns);
                   }
                   else
                   {
                       // Attribute names may also be namespace qualified.
                       attr.nsType = _getNamespaceType(attr.name);
                   }
               }
           }
   
           // Get the namespace type for this tag.
           entry.nsType = _getNamespaceType(entry.text);
   
           if (entry.type == XmlEntry::END_TAG ||
               entry.type == XmlEntry::EMPTY_TAG)
           {
               // Remove any namespaces of the current scope level from
               // the scope stack.
               while (!_nameSpaces.isEmpty() &&
                      _scopeLevel <= _nameSpaces.top().scopeLevel)
               {
                   _nameSpaces.pop();
               }
   
               PEGASUS_ASSERT(_scopeLevel > 0);
               _scopeLevel--;
           }
       }
       else
       {
           entry.nsType = -1;
       }
  
         return true;         return true;
     }     }
   
   // Get the namespace type of the given tag
   int XmlParser::_getNamespaceType(const char* tag)
   {
       const char* pos = strchr(tag, ':');
   
       // If ":" is not found, the tag is not namespace qualified and we
       // need to look for the default name space.
   
       // Search the namespace stack from the top
       for (int i = _nameSpaces.size() - 1; i >=0; i--)
       {
           // If ":" is found, look for the name space with the matching
           // local name...
           if ((pos && _nameSpaces[i].localName &&
                !strncmp(_nameSpaces[i].localName, tag, pos - tag)) ||
               // ... otherwise look for the default name space. It's the
               // one with localName set to NULL
               (!pos && !_nameSpaces[i].localName))
           {
               // If it's a reference to an unsupported namespace,
               // throw an exception
               if (_nameSpaces[i].type == -1)
               {
                   throw XmlException(XmlException::UNSUPPORTED_NAMESPACE, _line);
               }
               return _nameSpaces[i].type;
           }
       }
   
       // If the tag is namespace qualified, but the name space has not been
       // declared, it's malformed XML and we must throw an exception
       if (pos)
       {
           throw XmlException(XmlException::UNDECLARED_NAMESPACE, _line);
       }
   
       // Otherwise it's OK not to have a name space.
       return -1;
   }
   
   // Gived the extended namespace name, find it in the table of supported
   // namespaces and return its type.
   int XmlParser::getSupportedNamespaceType(const char* extendedName)
   {
       for (int i = 0;
            _supportedNamespaces[i].localName != 0;
            i++)
       {
           PEGASUS_ASSERT(_supportedNamespaces[i].type == i);
           if (!strcmp(_supportedNamespaces[i].extendedName, extendedName))
           {
               return _supportedNamespaces[i].type;
           }
       }
       return -1;
   }
   
   XmlNamespace* XmlParser::getNamespace(int nsType)
   {
       for (int i = _nameSpaces.size() - 1; i >=0; i--)
       {
           if (_nameSpaces[i].type == nsType)
           {
               return &_nameSpaces[i];
           }
       }
       return 0;
 } }
  
 void XmlParser::putBack(XmlEntry& entry) void XmlParser::putBack(XmlEntry& entry)
Line 775 
Line 914 
  
 void XmlParser::_getElement(char*& p, XmlEntry& entry) void XmlParser::_getElement(char*& p, XmlEntry& entry)
 { {
     entry.attributeCount = 0;  
   
     //--------------------------------------------------------------------------     //--------------------------------------------------------------------------
     // Get the element name (expect one of these: '?', '!', [A-Za-z_])     // Get the element name (expect one of these: '?', '!', [A-Za-z_])
     //--------------------------------------------------------------------------     //--------------------------------------------------------------------------
Line 878 
Line 1015 
         }         }
  
         XmlAttribute attr;         XmlAttribute attr;
           attr.nsType = -1;
         attr.name = p;         attr.name = p;
         _getAttributeNameAndEqual(p);         _getAttributeNameAndEqual(p);
  
Line 923 
Line 1061 
  
         _skipWhitespace(_line, p);         _skipWhitespace(_line, p);
  
         if (entry.attributeCount == XmlEntry::MAX_ATTRIBUTES)          entry.attributes.append(attr);
             throw XmlException(XmlException::TOO_MANY_ATTRIBUTES, _line);  
   
         entry.attributes[entry.attributeCount++] = attr;  
     }     }
 } }
  
Line 958 
Line 1093 
  
     PEGASUS_STD(cout) << '\n';     PEGASUS_STD(cout) << '\n';
  
     for (Uint32 i = 0; i < attributeCount; i++)      for (Uint32 i = 0; i < attributes.size(); i++)
     {     {
         PEGASUS_STD(cout) << "    " << attributes[i].name << "=\"";         PEGASUS_STD(cout) << "    " << attributes[i].name << "=\"";
         _printValue(attributes[i].value);         _printValue(attributes[i].value);
Line 969 
Line 1104 
 const XmlAttribute* XmlEntry::findAttribute( const XmlAttribute* XmlEntry::findAttribute(
     const char* name) const     const char* name) const
 { {
     for (Uint32 i = 0; i < attributeCount; i++)      for (Uint32 i = 0; i < attributes.size(); i++)
     {     {
         if (strcmp(attributes[i].name, name) == 0)         if (strcmp(attributes[i].name, name) == 0)
             return &attributes[i];             return &attributes[i];


Legend:
Removed from v.1.37  
changed lines
  Added in v.1.43.2.4

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2