(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.10 and 1.19

version 1.10, 2001/04/13 18:20:51 version 1.19, 2001/06/16 23:10:05
Line 1 
Line 1 
 //BEGIN_LICENSE  //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // DEALINGS IN THE SOFTWARE.  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //END_LICENSE  //==============================================================================
 //BEGIN_HISTORY  
 // //
 // Author:  // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // $Log$  // Modified By:
 // Revision 1.10  2001/04/13 18:20:51  mike  
 // Ported so Solaris.  
 // Fixed memory leaks.  
 // //
 // Revision 1.9  2001/04/08 01:13:22  mike  //%/////////////////////////////////////////////////////////////////////////////
 // Changed "ConstCIM" to "CIMConst"  
 //  
 // Revision 1.7  2001/02/20 07:25:57  mike  
 // Added basic create-instance in repository and in client.  
 //  
 // Revision 1.6  2001/02/19 01:47:17  mike  
 // Renamed names of the form CIMConst to CIMConst.  
 //  
 // Revision 1.5  2001/02/18 03:56:01  mike  
 // Changed more class names (e.g., ConstClassDecl -> CIMConstClass)  
 //  
 // Revision 1.4  2001/02/16 02:06:07  mike  
 // Renamed many classes and headers.  
 //  
 // Revision 1.3  2001/01/31 08:20:51  mike  
 // Added dispatcher framework.  
 // Added enumerateInstanceNames.  
 //  
 // Revision 1.2  2001/01/29 02:23:44  mike  
 // Added support for GetInstance operation  
 //  
 // Revision 1.1.1.1  2001/01/14 19:53:36  mike  
 // Pegasus import  
 //  
 //  
 //END_HISTORY  
  
 #include <cstdlib> #include <cstdlib>
 #include <cstdio> #include <cstdio>
Line 175 
Line 146 
     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 204 
Line 175 
     }     }
 } }
  
 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 245 
Line 216 
     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-CIMType: 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 272 
Line 243 
  
     out << "HTTP/1.1 200 OK\r\n";     out << "HTTP/1.1 200 OK\r\n";
     out << "Content-CIMType: 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 294 
Line 265 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 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 544 
Line 515 
     return formatIParamValueElement(out, parameterName, 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 594 
Line 582 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 static void _printAttributes( static void _printAttributes(
     std::ostream& os,      PEGASUS_STD(ostream)& os,
     const XmlAttribute* attributes,     const XmlAttribute* attributes,
     Uint32 attributeCount)     Uint32 attributeCount)
 { {
Line 617 
Line 605 
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 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 632 
Line 620 
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 void XmlWriter::indentedPrint( void XmlWriter::indentedPrint(
     std::ostream& os,      PEGASUS_STD(ostream)& os,
     const char* text,     const char* text,
     Uint32 indentChars)     Uint32 indentChars)
 { {
Line 648 
Line 636 
         {         {
             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 658 
Line 646 
  
             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 673 
Line 661 
  
             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 686 
Line 674 
                 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 695 
Line 683 
             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 704 
Line 692 
  
             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 736 
Line 724 
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 Uint32 XmlWriter::getNextMessageId()  String XmlWriter::getNextMessageId()
 { {
     // ATTN: make thread-safe:     // ATTN: make thread-safe:
     static Uint32 messageId = 1000;     static Uint32 messageId = 1000;
Line 746 
Line 734 
     if (messageId < 1000)     if (messageId < 1000)
         messageId = 1001;         messageId = 1001;
  
     return messageId;      char buffer[16];
       sprintf(buffer, "%d", messageId);
       return buffer;
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 777 
Line 767 
  
 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.10  
changed lines
  Added in v.1.19

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2