PropertyList.hpp
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. /****************License************************************************
  2.  * Vocalocity OpenVXI
  3.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  18.  * registered trademarks of Vocalocity, Inc. 
  19.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  20.  * by Vocalocity.
  21.  ***********************************************************************/
  22. #include "VXIvalue.h"                  // for VXIMap
  23. #include <map>
  24. #include <vector>
  25. #include "CommonExceptions.hpp"
  26. class VXMLElement;
  27. class SimpleLogger;
  28. enum PropertyLevel {
  29.   DEFAULTS_PROP = 0,
  30.   SESSION_PROP  = 1,
  31.   APP_PROP      = 2,
  32.   DOC_PROP      = 3,
  33.   DIALOG_PROP   = 4,
  34.   FIELD_PROP    = 5,
  35.   LAST_PROP     = 6        // this one should always be last in the list
  36. };
  37. class PropertyList {
  38. public:
  39.   static const VXIchar * const BaseURI;
  40.   static const VXIchar * const Language;
  41.   static const VXIchar * const AbsoluteURI;
  42.   static const VXIchar * const SourceEncoding;
  43.   const VXIchar* GetProperty(const VXIchar * key,
  44.                              PropertyLevel L = LAST_PROP) const;
  45.   // Returns property value if a match was found.  Otherwise returns NULL.
  46.   bool SetProperty(const VXIchar * key, const VXIchar * value,
  47.                    PropertyLevel L);
  48.   void SetProperties(const VXMLElement & doc, PropertyLevel level,
  49.                      const VXIMapHolder &);
  50.   // Sets all properties indicated by <property> at this level.
  51. public:
  52.   enum CacheAttrType {
  53.     Audio,
  54.     Document,
  55.     Grammar,
  56.     Object,
  57.     Script,
  58.     Data
  59.   };
  60.   void GetFetchobjCacheAttrs(const VXMLElement & elem,
  61.                              CacheAttrType,
  62.                              VXIMapHolder & fetchobj) const;
  63. public:
  64.   bool GetFetchobjSubmitAttributes(const VXMLElement & elem,
  65.                                    VXIMapHolder & submitData,
  66.                                    VXIMapHolder & fetchobj) const;
  67.   bool GetFetchobjBase(VXIMapHolder & fetchobj) const;
  68.   bool GetFetchobjSubmitType(const VXMLElement & elem,
  69.                              VXIMapHolder & fetchobj) const;
  70.   bool GetFetchobjURIs(const VXMLElement & elem, VXIMapHolder & fetchobj,
  71.                        vxistring & uri, vxistring & fragment) const;
  72.   bool PushProperties(const VXMLElement & elem);
  73.   // Returns: true if any properties were found.
  74.   void PopProperties();
  75.   void PopPropertyLevel(PropertyLevel l);
  76.   void GetProperties(VXIMapHolder &) const;
  77.   PropertyList& operator=(const PropertyList &);
  78.   PropertyList(const PropertyList &);
  79.   PropertyList(const SimpleLogger & l);
  80.   ~PropertyList() { properties.clear(); }
  81. public:
  82.   static bool ConvertTimeToMilliseconds(const SimpleLogger &,
  83.                                         const vxistring & time,
  84.                                         VXIint& result);
  85.   // This function converts an incoming string into an appropriate number of
  86.   // milliseconds.  The format of the string is pretty rigid - some number of
  87.   // digits (0...9) followed by {"s", "ms"} for seconds or milliseconds
  88.   // respectively.  White space or decimals are both illegal.  The result will
  89.   // always contain the 'best guess' even if an error is returned.  Should no
  90.   // units be provided, seconds is assumed and an error is returned.
  91.   //
  92.   // Returns: true  - the time was well formed and result contains number of ms
  93.   //          false - the time was illegal, result contains the best guess
  94.   static bool ConvertValueToFraction(const SimpleLogger &,
  95.                                      const vxistring & value,
  96.                                      VXIflt32& result);
  97.   // This function converts an incoming string into a floating point number
  98.   // in the interval [0, 1].
  99.   //
  100.   // Returns: true  - the number was well formed and in the interval
  101.   //          false - the value was illegal, result contains the best guess
  102. private:
  103.   typedef std::map<vxistring, vxistring> STRINGMAP;
  104.   typedef std::vector<STRINGMAP> PROPERTIES;
  105.   PROPERTIES properties;
  106.   const SimpleLogger & log;
  107. };
  108. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  109.                           VXIint value)
  110. {
  111.   if (m.GetValue() == NULL) return;
  112.   VXIInteger * val = VXIIntegerCreate(value);
  113.   if (val == NULL) throw VXIException::OutOfMemory();
  114.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  115.                     reinterpret_cast<VXIValue *>(val));
  116. }
  117. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  118.                           const VXIchar * value)
  119. {
  120.   if ((m.GetValue() == NULL) || (value == NULL)) return;
  121.   VXIString * val = VXIStringCreate(value);
  122.   if (val == NULL) throw VXIException::OutOfMemory();
  123.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  124.                     reinterpret_cast<VXIValue *>(val));
  125. }
  126. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  127.                           const vxistring & value)
  128. {
  129.   if (m.GetValue() == NULL) return;
  130.   VXIString * val = VXIStringCreate(value.c_str());
  131.   if (val == NULL) throw VXIException::OutOfMemory();
  132.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  133.                     reinterpret_cast<VXIValue *>(val));
  134. }
  135. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  136.                           VXIflt32 value)
  137. {
  138.   if (m.GetValue() == NULL) return;
  139.   VXIFloat * val = VXIFloatCreate(value);
  140.   if (val == NULL) throw VXIException::OutOfMemory();
  141.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  142.                     reinterpret_cast<VXIValue *>(val));
  143. }
  144. #if (VXI_CURRENT_VERSION >= 0x00030000)
  145. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  146.                           VXIflt64 value)
  147. {
  148.   if (m.GetValue() == NULL) return;
  149.   VXIDouble * val = VXIDoubleCreate(value);
  150.   if (val == NULL) throw VXIException::OutOfMemory();
  151.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  152.                     reinterpret_cast<VXIValue *>(val));
  153. }
  154. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  155.                           VXIulong value)
  156. {
  157.   if (m.GetValue() == NULL) return;
  158.   VXIULong * val = VXIULongCreate(value);
  159.   if (val == NULL) throw VXIException::OutOfMemory();
  160.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  161.                     reinterpret_cast<VXIValue *>(val));
  162. }
  163. #endif
  164. inline void AddParamValue(VXIMapHolder & m, const vxistring & name,
  165.                           bool value)
  166. {
  167.   if (m.GetValue() == NULL) return;
  168.   VXIBoolean * val = VXIBooleanCreate((value ? TRUE : FALSE));
  169.   if (val == NULL) throw VXIException::OutOfMemory();
  170.   VXIMapSetProperty(m.GetValue(), name.c_str(),
  171.                     reinterpret_cast<VXIValue *>(val));
  172. }