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

Diff for /pegasus/src/Pegasus/Common/XmlWriter.cpp between version 1.1 and 1.17

version 1.1, 2001/01/14 19:53:36 version 1.17, 2001/06/11 23:11:26
Line 1 
Line 1 
 //BEGIN_LICENSE  //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
 // //
Line 17 
Line 17 
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
 // //
 //END_LICENSE  //==============================================================================
 //BEGIN_HISTORY  
 // //
 // Author:  // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // $Log$  // Modified By:
 // Revision 1.1  2001/01/14 19:53:36  mike  
 // Initial revision  
 // //
 //  //%/////////////////////////////////////////////////////////////////////////////
 //END_HISTORY  
  
 #include <cstdlib> #include <cstdlib>
 #include <cstdio> #include <cstdio>
 #include "ClassDecl.h"  #include "CIMClass.h"
 #include "QualifierDecl.h"  #include "CIMInstance.h"
   #include "CIMQualifierDecl.h"
 #include "XmlWriter.h" #include "XmlWriter.h"
 #include "XmlParser.h" #include "XmlParser.h"
  
Line 143 
Line 140 
         out << "<NAMESPACE NAME=\"" << p << "\"/>\n";         out << "<NAMESPACE NAME=\"" << p << "\"/>\n";
     }     }
  
       delete [] tmp;
   
     out << "</LOCALNAMESPACEPATH>\n";     out << "</LOCALNAMESPACEPATH>\n";
 } }
  
 static inline void AppendSpecialChar(std::ostream& os, char c)  static inline void AppendSpecialChar(PEGASUS_STD(ostream)& os, char c)
 { {
     switch (c)     switch (c)
     {     {
Line 175 
Line 174 
     }     }
 } }
  
 static inline void AppendSpecial(std::ostream& os, const char* str)  static inline void AppendSpecial(PEGASUS_STD(ostream)& os, const char* str)
 { {
     while (*str)     while (*str)
         AppendSpecialChar(os, *str++);         AppendSpecialChar(os, *str++);
Line 215 
Line 214 
  
     out << "M-POST /cimom HTTP/1.1\r\n";     out << "M-POST /cimom HTTP/1.1\r\n";
     out << "HOST: " << host << "\r\n";     out << "HOST: " << host << "\r\n";
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";      out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << content.getSize() << "\r\n";      out << "Content-Length: " << content.size() << "\r\n";
     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
     out << nn <<"\r\n";     out << nn <<"\r\n";
     out << nn << "-CIMOperation: " << cimOperation << "\r\n";     out << nn << "-CIMOperation: " << cimOperation << "\r\n";
Line 242 
Line 241 
     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
  
     out << "HTTP/1.1 200 OK\r\n";     out << "HTTP/1.1 200 OK\r\n";
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";      out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << content.getSize() << "\r\n";      out << "Content-Length: " << content.size() << "\r\n";
     out << "Ext:\r\n";     out << "Ext:\r\n";
     out << "Cache-Control: no-cache\r\n";     out << "Cache-Control: no-cache\r\n";
     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
Line 265 
Line 264 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Array<Sint8> XmlWriter::formatMessageElement( Array<Sint8> XmlWriter::formatMessageElement(
     Uint32 messageId,      const String& messageId,
     const Array<Sint8>& body)     const Array<Sint8>& body)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 399 
Line 398 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Array<Sint8> XmlWriter::formatErrorElement( Array<Sint8> XmlWriter::formatErrorElement(
     CimException::Code code,      CIMException::Code code,
     const char* description)     const char* description)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 476 
Line 475 
 Array<Sint8>& XmlWriter::appendClassParameter( Array<Sint8>& XmlWriter::appendClassParameter(
     Array<Sint8>& out,     Array<Sint8>& out,
     const char* parameterName,     const char* parameterName,
     const ConstClassDecl& classDecl)      const CIMConstClass& cimClass)
 { {
     Array<Sint8> tmp;     Array<Sint8> tmp;
     classDecl.toXml(tmp);      cimClass.toXml(tmp);
     return formatIParamValueElement(out, parameterName, tmp);     return formatIParamValueElement(out, parameterName, tmp);
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
   // appendInstanceNameParameter()
   //
   //------------------------------------------------------------------------------
   
   Array<Sint8>& XmlWriter::appendInstanceNameParameter(
       Array<Sint8>& out,
       const char* parameterName,
       const CIMReference& instanceName)
   {
       Array<Sint8> tmp;
       instanceName.instanceNameToXml(tmp);
       return formatIParamValueElement(out, parameterName, tmp);
   }
   
   //------------------------------------------------------------------------------
   //
   // appendInstanceParameter()
   //
   //------------------------------------------------------------------------------
   
   Array<Sint8>& XmlWriter::appendInstanceParameter(
       Array<Sint8>& out,
       const char* parameterName,
       const CIMConstInstance& instance)
   {
       Array<Sint8> tmp;
       instance.toXml(tmp);
       return formatIParamValueElement(out, parameterName, tmp);
   }
   
   //----------------------------------------------------------
   //
   //  appendPropertyNameParameter()
   //
   //     </IPARAMVALUE>
   //     <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
   //
   //     USE: Create parameter for getProperty operation
   //==========================================================
   Array<Sint8>& XmlWriter::appendPropertyNameParameter(
       Array<Sint8>& out,
       const String& propertyName)
   {
       Array<Sint8> tmp;
       tmp << "<VALUE>" << propertyName << "</VALUE>\n";
       return formatIParamValueElement(out,"PropertyName", tmp);}
   
   //------------------------------------------------------------------------------
   //
 // appendClassParameter() // appendClassParameter()
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 492 
Line 540 
 Array<Sint8>& XmlWriter::appendQualifierDeclarationParameter( Array<Sint8>& XmlWriter::appendQualifierDeclarationParameter(
     Array<Sint8>& out,     Array<Sint8>& out,
     const char* parameterName,     const char* parameterName,
     const ConstQualifierDecl& qualifierDecl)      const CIMConstQualifierDecl& qualifierDecl)
 { {
     Array<Sint8> tmp;     Array<Sint8> tmp;
     qualifierDecl.toXml(tmp);     qualifierDecl.toXml(tmp);
Line 514 
Line 562 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
   // appendInstanceNameElement()
   //
   //------------------------------------------------------------------------------
   
   Array<Sint8>& XmlWriter::appendInstanceNameElement(
       Array<Sint8>& out,
       const CIMReference& instanceName)
   {
       instanceName.instanceNameToXml(out);
       return out;
   }
   
   //------------------------------------------------------------------------------
   //
 // _printAttributes() // _printAttributes()
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 static void _printAttributes( static void _printAttributes(
     std::ostream& os,      PEGASUS_STD(ostream)& os,
     const XmlAttribute* attributes,     const XmlAttribute* attributes,
     Uint32 attributeCount)     Uint32 attributeCount)
 { {
Line 542 
Line 604 
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 static void _indent(std::ostream& os, Uint32 level, Uint32 indentChars)  static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)
 { {
     Uint32 n = level * indentChars;     Uint32 n = level * indentChars;
  
Line 557 
Line 619 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 void XmlWriter::indentedPrint( void XmlWriter::indentedPrint(
     std::ostream& os,      PEGASUS_STD(ostream)& os,
     const char* text,     const char* text,
     Uint32 indentChars)     Uint32 indentChars)
 { {
Line 573 
Line 635 
         {         {
             case XmlEntry::XML_DECLARATION:             case XmlEntry::XML_DECLARATION:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
  
                 os << "<?" << entry.text << " ";                 os << "<?" << entry.text << " ";
                 _printAttributes(os, entry.attributes, entry.attributeCount);                 _printAttributes(os, entry.attributes, entry.attributeCount);
Line 583 
Line 645 
  
             case XmlEntry::START_TAG:             case XmlEntry::START_TAG:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
  
                 os << "<" << entry.text;                 os << "<" << entry.text;
  
Line 598 
Line 660 
  
             case XmlEntry::EMPTY_TAG:             case XmlEntry::EMPTY_TAG:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
  
                 os << "<" << entry.text << " ";                 os << "<" << entry.text << " ";
                 _printAttributes(os, entry.attributes, entry.attributeCount);                 _printAttributes(os, entry.attributes, entry.attributeCount);
Line 611 
Line 673 
                 if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)                 if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
                     stack.pop();                     stack.pop();
  
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
  
                 os << "</" << entry.text << ">";                 os << "</" << entry.text << ">";
                 break;                 break;
Line 620 
Line 682 
             case XmlEntry::COMMENT:             case XmlEntry::COMMENT:
             {             {
  
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
                 os << "<!--";                 os << "<!--";
                 AppendSpecial(os, entry.text);                 AppendSpecial(os, entry.text);
                 os << "-->";                 os << "-->";
Line 629 
Line 691 
  
             case XmlEntry::CONTENT:             case XmlEntry::CONTENT:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
                 AppendSpecial(os, entry.text);                 AppendSpecial(os, entry.text);
                 break;                 break;
             }             }
  
             case XmlEntry::CDATA:             case XmlEntry::CDATA:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
                 os << "<![CDATA[...]]>";                 os << "<![CDATA[...]]>";
                 break;                 break;
             }             }
  
             case XmlEntry::DOCTYPE:             case XmlEntry::DOCTYPE:
             {             {
                 _indent(os, stack.getSize(), indentChars);                  _indent(os, stack.size(), indentChars);
                 os << "<!DOCTYPE...>";                 os << "<!DOCTYPE...>";
                 break;                 break;
             }             }
         }         }
  
         os << std::endl;          os << PEGASUS_STD(endl);
     }     }
  
     delete [] tmp;     delete [] tmp;
Line 661 
Line 723 
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Uint32 XmlWriter::getNextMessageId()  String XmlWriter::getNextMessageId()
 { {
     // ATTN: make thread-safe:     // ATTN: make thread-safe:
     static Uint32 messageId = 1000;     static Uint32 messageId = 1000;
Line 671 
Line 733 
     if (messageId < 1000)     if (messageId < 1000)
         messageId = 1001;         messageId = 1001;
  
     return messageId;      char buffer[16];
       sprintf(buffer, "%d", messageId);
       return buffer;
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 702 
Line 766 
  
 Array<Sint8> XmlWriter::formatSimpleRspMessage( Array<Sint8> XmlWriter::formatSimpleRspMessage(
     const char* iMethodName,     const char* iMethodName,
       const String& messageId,
     const Array<Sint8>& body)     const Array<Sint8>& body)
 { {
     return XmlWriter::formatMethodResponseHeader(     return XmlWriter::formatMethodResponseHeader(
         XmlWriter::formatMessageElement(         XmlWriter::formatMessageElement(
             XmlWriter::getNextMessageId(),              messageId,
             XmlWriter::formatSimpleRspElement(             XmlWriter::formatSimpleRspElement(
                 XmlWriter::formatIMethodResponseElement(                 XmlWriter::formatIMethodResponseElement(
                     iMethodName,                     iMethodName,
                     XmlWriter::formatIReturnValueElement(body)))));                     XmlWriter::formatIReturnValueElement(body)))));
 } }
  
   Array<Sint8>& operator<<(Array<Sint8>& out, const char* x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, char x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, Char16 x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, const String& x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, const Indentor& x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, const Array<Sint8>& x)
   {
       out.appendArray(x);
       return out;
   }
   
   Array<Sint8>& operator<<(Array<Sint8>& out, Uint32 x)
   {
       XmlWriter::append(out, x);
       return out;
   }
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1  
changed lines
  Added in v.1.17

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2