(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.42 and 1.43.2.3

version 1.42, 2007/07/30 06:50:57 version 1.43.2.3, 2008/03/12 01:54:51
Line 328 
Line 328 
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 XmlParser::XmlParser(char* text)  XmlParser::XmlParser(char* text, XmlNamespace* ns)
     : _line(1),     : _line(1),
       _current(text),       _current(text),
       _restoreChar('\0'),       _restoreChar('\0'),
       _foundRoot(false)        _foundRoot(false),
         _scopeLevel(0),
         _supportedNamespaces(ns)
 { {
 } }
  
Line 347 
Line 349 
     }     }
 } }
  
   #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 383 
Line 389 
  
     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 501 
Line 511 
     }     }
 } }
  
 Boolean XmlParser::next(XmlEntry& entry, Boolean includeComment)  Boolean XmlParser::next(
       XmlEntry& entry,
       Boolean includeComment)
 { {
       entry.attributes.clear();
   
     if (!_putBackStack.isEmpty())     if (!_putBackStack.isEmpty())
     {     {
         entry = _putBackStack.top();         entry = _putBackStack.top();
Line 591 
Line 605 
         }         }
     }while (!includeComment && entry.type == XmlEntry::COMMENT);     }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];
                   // ATTN WSMAN: Also check for default declarations?  E.g.,
                   // if (strcmp(attr.name, "xmlns") == 0) ... ns.localName = "";
                   if (strncmp(attr.name, "xmlns:", 6) == 0)
                   {
                       XmlNamespace ns;
                       // ATTN WSMAN: Need to ensure the localName is not empty?
                       ns.localName = attr.name + 6;
                       ns.extendedName = attr.value;
                       ns.scopeLevel = _scopeLevel;
                       ns.type = getSupportedNamespaceType(ns.extendedName);
   
                       // Make sure we know how to deal with entries from
                       // this namespace
                       if (ns.type != -1)
                       {
                           _nameSpaces.push(ns);
                       }
                       else
                       {
                           // ATTN WSMAN: throw an exception
                       }
                   }
               }
           }
   
           // The tag must be namespace qualified with a known namespace
           if ((entry.nsType = _getNamespaceType(entry.text)) == -1)
           {
               // ATTN WSMAN: throw an exception
               // ATTN WSMAN: If namespaces are supported, does that
               // mean they are required?
           }
   
           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();
               }
   
               // ATTN WSMAN: This could happen if the XML is not well formed,
               // so it probably is not correct to assert this.
               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
       if (pos == NULL)
       {
           return -1;
       }
   
       // Search the namespace stack from the top
       for (int i = _nameSpaces.size() - 1; i >=0; i--)
       {
           if (!strncmp(_nameSpaces[i].localName, tag, pos - tag))
           {
               return _nameSpaces[i].type;
           }
       }
       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)
 { {
     _putBackStack.push(entry);     _putBackStack.push(entry);
Line 770 
Line 903 
  
 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 918 
Line 1049 
  
         _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 953 
Line 1081 
  
     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 964 
Line 1092 
 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.42  
changed lines
  Added in v.1.43.2.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2