Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
6.2 KiB

  1. #pragma once
  2. /************************************************************************
  3. Copyright (c) 2001 Microsoft Corporation
  4. File Name: CSite.h -- Definition of CSite.cpp
  5. Abstract: Site objects that manages partner site settings through XML and DB.
  6. Site interface to manage SiteXXX.xml.
  7. Revision History:
  8. 2001/1/24 lifenwu Created.
  9. ***************************************************************************/
  10. #include "PSANexus.h" //sd_uncommented
  11. #include "atlcoll.h"
  12. #include "atltime.h"
  13. //
  14. // XML Item Node type
  15. //
  16. typedef enum siteItemNodeType
  17. {
  18. stnt_Device = 1,
  19. stnt_Item,
  20. stnt_ExtItem,
  21. stnt_CBScriptVar,
  22. stnt_Invalid
  23. } SITE_ITEM_NODE_TYPE;
  24. //
  25. // Each XML node owns a set of attributes
  26. //
  27. class CSiteAttribute
  28. {
  29. public:
  30. virtual ~CSiteAttribute();
  31. //
  32. // Random Access to an attribute
  33. //
  34. BOOL AttributeGet(CString szName, CString *pszValue);
  35. BOOL AttributeGet(POSITION pos, CString *pszName, CString *pszValue)
  36. {
  37. if (pos == NULL) return FALSE;
  38. m_mapFields.GetAt(pos, *pszName, pszValue);
  39. return TRUE;
  40. }
  41. //
  42. // enumeration through
  43. //
  44. POSITION AttributeGetStartPosition()
  45. {
  46. return m_mapFields.GetStartPosition();
  47. }
  48. BOOL AttributeGetNext(POSITION& pos, CString *pszName, CString *pszValue)
  49. {
  50. CString *csValue;
  51. if (pos == NULL) return FALSE;
  52. m_mapFields.GetNextAssoc(pos, *pszName, csValue);
  53. *pszValue = *csValue;
  54. return TRUE;
  55. }
  56. ULONG AttributeGetCount()
  57. {
  58. return m_mapFields.GetCount();
  59. }
  60. //
  61. // Add/Update/Delete operation
  62. //
  63. BOOL AttributeAdd(CString szName, CString szValue);
  64. BOOL AttributeUpdate(CString szName, CString szValue);
  65. BOOL AttributeDelete(CString szName);
  66. //
  67. // Initialization routines
  68. //
  69. HRESULT InitAttributes(IXMLDOMNode *pNode);
  70. protected:
  71. typedef CAtlMap<CString, CString *, CStringElementTraits<CString> > ATTRIBUTE_MAP;
  72. ATTRIBUTE_MAP m_mapFields;
  73. private:
  74. };
  75. //
  76. // CSite Item represents a leaf XML node,
  77. // such <Item>Birthdate</Item> or <ExtItem> or <CBScriptVar>
  78. //
  79. class CSiteItem : public CSiteAttribute
  80. {
  81. public:
  82. ~CSiteItem() { };
  83. //
  84. // Get/Set Item value and its type
  85. //
  86. LPCTSTR GetItem() { return m_szItem; }
  87. void SetItem(LPCTSTR szItem) { m_szItem = szItem; }
  88. SITE_ITEM_NODE_TYPE GetType() { return m_enumType; }
  89. void SetType(SITE_ITEM_NODE_TYPE t) { m_enumType = t; }
  90. //
  91. // Initialization routines
  92. // $$Todo$$ Add DB init
  93. //
  94. HRESULT InitFromXML(IXMLDOMNode *pNode);
  95. protected:
  96. CString m_szItem;
  97. SITE_ITEM_NODE_TYPE m_enumType;
  98. };
  99. //
  100. // Represents an XML containder node such as <Section>, <Device>, <Locale>
  101. // Internally, a CAtlArray maintains the container.
  102. // The ordering of the elements are implicitly stored in the array
  103. //
  104. template<class T>
  105. class CSiteContainer : public CSiteAttribute
  106. {
  107. public:
  108. ~CSiteContainer()
  109. {
  110. // Deep clean up array
  111. for (ULONG ulIndex = 0; ulIndex < m_array.GetCount(); ulIndex++)
  112. {
  113. T * pT = m_array[ulIndex];
  114. if (pT != NULL)
  115. {
  116. delete pT;
  117. pT = 0; //sd_added
  118. }
  119. }
  120. m_array.RemoveAll();
  121. }
  122. //
  123. // Access to container array
  124. //
  125. T *GetItem(unsigned long ulItemIdx) { return m_array[ulItemIdx]; }
  126. size_t AddItem(T *t) { return m_array.Add(t); }
  127. ULONG GetCount() { return m_array.GetCount(); }
  128. //
  129. // Initializations
  130. //
  131. HRESULT InitFromXML(IXMLDOMNode *pNode)
  132. {
  133. HRESULT hr = E_FAIL;
  134. CComPtr<IXMLDOMNode> pItem = NULL;
  135. CComPtr<IXMLDOMNodeList> pList = NULL;
  136. long i, lNumChildren;
  137. CComBSTR bstr;
  138. CComVariant var;
  139. hr = InitAttributes(pNode);
  140. hr = pNode->get_childNodes(&pList);
  141. if (FAILED(hr))
  142. {
  143. goto exit;
  144. }
  145. hr = pList->get_length(&lNumChildren);
  146. for (i=0; i < lNumChildren; i++)
  147. {
  148. pItem = NULL;
  149. hr = pList->get_item(i, &pItem);
  150. T *pT = new T;
  151. if (pT == NULL)
  152. {
  153. hr = E_OUTOFMEMORY;
  154. goto exit;
  155. }
  156. hr = pT->InitFromXML(pItem);
  157. if (FAILED(hr))
  158. {
  159. if (pT != NULL) delete pT;
  160. }
  161. else
  162. {
  163. AddItem(pT);
  164. }
  165. }
  166. hr = S_OK;
  167. exit:
  168. return hr;
  169. }
  170. protected:
  171. typedef CAtlArray<T *> SITEITEM_ARRAY;
  172. SITEITEM_ARRAY m_array;
  173. };
  174. //
  175. // Container objects class
  176. //
  177. typedef CSiteContainer<CSiteItem> CSiteSection;
  178. typedef CSiteContainer<CSiteItem> CSiteLocale;
  179. //
  180. // Device has been referred as Style (mainly indicates HTML, WML, CDML, Wizard, etc
  181. //
  182. class CSiteDevice : public CSiteContainer<CSiteSection>
  183. {
  184. public:
  185. CSiteDevice() { }
  186. CSiteDevice(CString szDeviceName) { m_szName = szDeviceName; }
  187. void SetDeviceName(CString sz) { m_szName = sz; }
  188. // Persist as XML blob in DB
  189. //
  190. HRESULT Pesist(LONG lSiteID);
  191. HRESULT InitFromDB(LONG lSiteID);
  192. HRESULT InitFromStream(ISequentialStream *pStream);
  193. private:
  194. CString m_szName;
  195. COleDateTime m_dtSRFChangedTime;
  196. };
  197. //
  198. // Main entry object to a partner site settings data
  199. //
  200. //sd_added, 08/March/2001, use this type to pass the site info to be stored in DB
  201. //to CSite obj.
  202. typedef CPSANexusFlexRegInsert::tagInputParameters SITEMETRICS_STRUCT;
  203. class CSite : public CSiteAttribute
  204. {
  205. public:
  206. CSite() { m_lSiteID = -1;};
  207. CSite(LONG lSiteID) { m_lSiteID = lSiteID; }
  208. ~CSite() { };
  209. // Initialize from DB, Read Only, to be used during Runtime
  210. HRESULT InitSiteAttributes();
  211. HRESULT InitSiteDevices(int iTargetType);
  212. HRESULT InitDevice(CString szwStyle, int iTargetType);
  213. // Initialize from XML -- an XML for a site customization ; used by preprocessing
  214. HRESULT Init(IXMLDOMDocument *pXMLDoc);
  215. HRESULT InitFromDB(int iTargetType);
  216. // Persist to DB through XML only
  217. // never persist from object memory
  218. HRESULT Persist(SITEMETRICS_STRUCT *pSiteMetrics);
  219. HRESULT GetDateTime(COleDateTime *pDateTime);
  220. CSiteContainer<CSiteDevice>* GetDeviceContainer() { return &m_Devices; }
  221. CSiteContainer<CSiteLocale>* GetLocaleContainer() { return &m_Locales; }
  222. LONG GetSiteID() { return m_lSiteID; }
  223. void SetSiteID(LONG l) { m_lSiteID = l; }
  224. CSiteDevice * GetDevice(CString cszDevice);
  225. private:
  226. typedef CAtlMap< CString, LONG, CStringElementTraits<CString> > SITEDEVICE_MAP;
  227. CSiteContainer<CSiteDevice> m_Devices;
  228. SITEDEVICE_MAP m_DeviceMap;
  229. CSiteContainer<CSiteLocale> m_Locales;
  230. LONG m_lSiteID;
  231. COleDateTime m_oledtDateUpdated;
  232. };
  233. class CSitesAll : public CSiteContainer<CSite>
  234. {
  235. public:
  236. protected:
  237. private:
  238. };