Leaked source code of windows server 2003
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.

2823 lines
74 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Updater.cpp
  5. Abstract:
  6. Handles access to the database.
  7. Revision History:
  8. ******************************************************************************/
  9. #include "stdafx.h"
  10. ////////////////////////////////////////////////////////////////////////////////
  11. static const WCHAR s_DB_LOCATION_ENV[] = L"%HELP_LOCATION%";
  12. #define STAT_CREATED( table ) m_stat.m_ent##table.Created()
  13. #define STAT_MODIFIED( table ) m_stat.m_ent##table.Modified()
  14. #define STAT_DELETED( table ) m_stat.m_ent##table.Deleted()
  15. #define STAT_NOOP( table ) m_stat.m_ent##table.NoOp()
  16. ////////////////////////////////////////////////////////////////////////////////
  17. Taxonomy::Updater::WordSetStatus::WordSetStatus()
  18. {
  19. m_updater = NULL; // Updater* m_updater;
  20. m_def = NULL; // const WordSetDef* m_def;
  21. //
  22. // WordSet m_set;
  23. m_fLoaded = false; // bool m_fLoaded;
  24. m_fModified = false; // bool m_fModified;
  25. }
  26. HRESULT Taxonomy::Updater::WordSetStatus::Close()
  27. {
  28. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Close" );
  29. HRESULT hr;
  30. m_updater = NULL;
  31. m_def = NULL;
  32. m_set.clear();
  33. m_fLoaded = false;
  34. m_fModified = false;
  35. hr = S_OK;
  36. __HCP_FUNC_EXIT(hr);
  37. }
  38. HRESULT Taxonomy::Updater::WordSetStatus::Init( /*[in]*/ Updater* updater, /*[in]*/ const WordSetDef* def )
  39. {
  40. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Init" );
  41. HRESULT hr;
  42. __MPC_EXIT_IF_METHOD_FAILS(hr, Close());
  43. m_updater = updater;
  44. m_def = def;
  45. hr = S_OK;
  46. __HCP_FUNC_CLEANUP;
  47. __HCP_FUNC_EXIT(hr);
  48. }
  49. ////////////////////
  50. HRESULT Taxonomy::Updater::WordSetStatus::Load()
  51. {
  52. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Load" );
  53. HRESULT hr;
  54. if(m_fLoaded == false)
  55. {
  56. MPC::wstring strTokenList;
  57. bool fFound;
  58. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater->ReadDBParameter( m_def->szName, strTokenList, &fFound ));
  59. if(m_def->szDefault && strTokenList.size() == 0) strTokenList = m_def->szDefault;
  60. if(m_def->szAlwaysPresent ) strTokenList += m_def->szAlwaysPresent;
  61. if(m_def->fSplitAtDelimiter)
  62. {
  63. std::vector<MPC::wstring> vec;
  64. int iLen;
  65. int i;
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::SplitAtDelimiter( vec, strTokenList.c_str(), L" ,\t\n", false, true ));
  67. iLen = vec.size();
  68. for(i=0; i<iLen; i++)
  69. {
  70. m_set.insert( vec[i] );
  71. }
  72. }
  73. else
  74. {
  75. int iLen;
  76. int i;
  77. iLen = strTokenList.size();
  78. for(i=0; i<iLen; i++)
  79. {
  80. m_set.insert( MPC::wstring( 1, strTokenList[i] ) );
  81. }
  82. }
  83. m_fLoaded = true;
  84. }
  85. hr = S_OK;
  86. __HCP_FUNC_CLEANUP;
  87. __HCP_FUNC_EXIT(hr);
  88. }
  89. HRESULT Taxonomy::Updater::WordSetStatus::Save()
  90. {
  91. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Save" );
  92. HRESULT hr;
  93. if(m_fModified)
  94. {
  95. MPC::wstring strTokenList;
  96. std::vector<MPC::wstring> vec;
  97. WordIter it;
  98. int i;
  99. vec.resize( m_set.size() );
  100. for(i=0, it = m_set.begin(); it != m_set.end(); it++, i++)
  101. {
  102. vec[i] = *it;
  103. }
  104. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::JoinWithDelimiter( vec, strTokenList, m_def->fSplitAtDelimiter ? L"," : L"" ));
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, m_updater->WriteDBParameter( m_def->szName, strTokenList.c_str() ));
  106. m_fModified = false;
  107. }
  108. hr = S_OK;
  109. __HCP_FUNC_CLEANUP;
  110. __HCP_FUNC_EXIT(hr);
  111. }
  112. HRESULT Taxonomy::Updater::WordSetStatus::Add( /*[in]*/ LPCWSTR szValue )
  113. {
  114. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Add" );
  115. HRESULT hr;
  116. __MPC_EXIT_IF_METHOD_FAILS(hr, Load());
  117. m_set.insert( szValue ); m_fModified = true;
  118. hr = S_OK;
  119. __HCP_FUNC_CLEANUP;
  120. __HCP_FUNC_EXIT(hr);
  121. }
  122. HRESULT Taxonomy::Updater::WordSetStatus::Remove( /*[in]*/ LPCWSTR szValue )
  123. {
  124. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WordSetStatus::Remove" );
  125. HRESULT hr;
  126. WordIter it;
  127. __MPC_EXIT_IF_METHOD_FAILS(hr, Load());
  128. it = m_set.find( szValue );
  129. if(it != m_set.end())
  130. {
  131. m_set.erase( it ); m_fModified = true;
  132. }
  133. hr = S_OK;
  134. __HCP_FUNC_CLEANUP;
  135. __HCP_FUNC_EXIT(hr);
  136. }
  137. ////////////////////////////////////////////////////////////////////////////////
  138. static const Taxonomy::Updater::WordSetDef s_SetDef[] =
  139. {
  140. { L"SET_STOPSIGNS" , false, L",?" , NULL }, // UPDATER_SET_STOPSIGNS
  141. { L"SET_STOPSIGNS_ATENDOFWORD", false, NULL , NULL }, // UPDATER_SET_STOPSIGNS_ATENDOFWORD
  142. { L"SET_STOPWORDS" , true , NULL , NULL }, // UPDATER_SET_STOPWORDS
  143. { L"SET_OPERATOR_NOT" , true , L"NOT", L",!" }, // UPDATER_SET_OPERATOR_NOT
  144. { L"SET_OPERATOR_AND" , true , L"AND", L",&,+" }, // UPDATER_SET_OPERATOR_AND
  145. { L"SET_OPERATOR_OR" , true , L"OR" , L",||" } // UPDATER_SET_OPERATOR_OR
  146. };
  147. Taxonomy::Updater::Updater()
  148. {
  149. // Settings m_ts;
  150. m_db = NULL; // JetBlue::Database* m_db;
  151. m_cache = NULL; // Cache* m_cache;
  152. m_fUseCache = false; // bool m_fUseCache;
  153. //
  154. m_rsDBParameters = NULL; // RS_DBParameters* m_rsDBParameters;
  155. m_rsContentOwners = NULL; // RS_ContentOwners* m_rsContentOwners;
  156. m_rsSynSets = NULL; // RS_SynSets* m_rsSynSets;
  157. m_rsHelpImage = NULL; // RS_HelpImage* m_rsHelpImage;
  158. m_rsIndexFiles = NULL; // RS_IndexFiles* m_rsIndexFiles;
  159. m_rsFullTextSearch = NULL; // RS_FullTextSearch* m_rsFullTextSearch;
  160. m_rsScope = NULL; // RS_Scope* m_rsScope;
  161. m_rsTaxonomy = NULL; // RS_Taxonomy* m_rsTaxonomy;
  162. m_rsTopics = NULL; // RS_Topics* m_rsTopics;
  163. m_rsSynonyms = NULL; // RS_Synonyms* m_rsSynonyms;
  164. m_rsKeywords = NULL; // RS_Keywords* m_rsKeywords;
  165. m_rsMatches = NULL; // RS_Matches* m_rsMatches;
  166. //
  167. m_ID_owner = -1; // long m_ID_owner;
  168. m_fOEM = false; // bool m_fOEM;
  169. //
  170. // WordSetStatus m_sets[UPDATER_SET_OPERATOR_MAX];
  171. // JetBlue::Id2Node m_nodes;
  172. // JetBlue::Node2Id m_nodes_reverse;
  173. //
  174. // Updater_Stat m_stat;
  175. }
  176. Taxonomy::Updater::~Updater()
  177. {
  178. (void)Close();
  179. }
  180. ////////////////////////////////////////////////////////////////////////////////
  181. HRESULT Taxonomy::Updater::FlushWordSets()
  182. {
  183. __HCP_FUNC_ENTRY( "Taxonomy::Updater::FlushWordSets" );
  184. HRESULT hr;
  185. int i;
  186. for(i=UPDATER_SET_STOPSIGNS; i<UPDATER_SET_OPERATOR_MAX; i++)
  187. {
  188. __MPC_EXIT_IF_METHOD_FAILS(hr, m_sets[i].Save());
  189. }
  190. hr = S_OK;
  191. __HCP_FUNC_CLEANUP;
  192. __HCP_FUNC_EXIT(hr);
  193. }
  194. HRESULT Taxonomy::Updater::Close()
  195. {
  196. __HCP_FUNC_ENTRY( "Taxonomy::Updater::Close" );
  197. HRESULT hr;
  198. int i;
  199. for(i=UPDATER_SET_STOPSIGNS; i<UPDATER_SET_OPERATOR_MAX; i++)
  200. {
  201. __MPC_EXIT_IF_METHOD_FAILS(hr, m_sets[i].Close());
  202. }
  203. NodeCache_Clear();
  204. hr = S_OK;
  205. __HCP_FUNC_CLEANUP;
  206. if(m_rsDBParameters ) { delete m_rsDBParameters ; m_rsDBParameters = NULL; }
  207. if(m_rsContentOwners ) { delete m_rsContentOwners ; m_rsContentOwners = NULL; }
  208. if(m_rsSynSets ) { delete m_rsSynSets ; m_rsSynSets = NULL; }
  209. if(m_rsHelpImage ) { delete m_rsHelpImage ; m_rsHelpImage = NULL; }
  210. if(m_rsIndexFiles ) { delete m_rsIndexFiles ; m_rsIndexFiles = NULL; }
  211. if(m_rsFullTextSearch) { delete m_rsFullTextSearch; m_rsFullTextSearch = NULL; }
  212. if(m_rsScope ) { delete m_rsScope ; m_rsScope = NULL; }
  213. if(m_rsTaxonomy ) { delete m_rsTaxonomy ; m_rsTaxonomy = NULL; }
  214. if(m_rsTopics ) { delete m_rsTopics ; m_rsTopics = NULL; }
  215. if(m_rsSynonyms ) { delete m_rsSynonyms ; m_rsSynonyms = NULL; }
  216. if(m_rsKeywords ) { delete m_rsKeywords ; m_rsKeywords = NULL; }
  217. if(m_rsMatches ) { delete m_rsMatches ; m_rsMatches = NULL; }
  218. m_db = NULL;
  219. m_cache = NULL;
  220. m_fUseCache = false;
  221. m_ID_owner = -1;
  222. m_fOEM = false;
  223. __HCP_FUNC_EXIT(hr);
  224. }
  225. HRESULT Taxonomy::Updater::Init( /*[in]*/ const Settings& ts, /*[in]*/ JetBlue::Database* db, /*[in]*/ Cache* cache )
  226. {
  227. __HCP_FUNC_ENTRY( "Taxonomy::Updater::Init" );
  228. HRESULT hr;
  229. int i;
  230. __MPC_EXIT_IF_METHOD_FAILS(hr, Close());
  231. m_ts = ts;
  232. m_db = db;
  233. m_cache = cache;
  234. m_fUseCache = (cache != NULL);
  235. m_strDBLocation = L"";
  236. for(i=UPDATER_SET_STOPSIGNS; i<UPDATER_SET_OPERATOR_MAX; i++)
  237. {
  238. __MPC_EXIT_IF_METHOD_FAILS(hr, m_sets[i].Init( this, &s_SetDef[i] ));
  239. }
  240. hr = S_OK;
  241. __HCP_FUNC_CLEANUP;
  242. __HCP_FUNC_EXIT(hr);
  243. }
  244. HRESULT Taxonomy::Updater::GetWordSet( /*[in] */ Updater_Set id ,
  245. /*[out]*/ WordSet* *pVal )
  246. {
  247. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetWordSet" );
  248. HRESULT hr;
  249. if(pVal) *pVal = NULL;
  250. __MPC_PARAMCHECK_BEGIN(hr)
  251. __MPC_PARAMCHECK_NOTNULL(m_db);
  252. __MPC_PARAMCHECK_END();
  253. __MPC_EXIT_IF_METHOD_FAILS(hr, m_sets[id].Load());
  254. if(pVal) *pVal = &m_sets[id].m_set;
  255. hr = S_OK;
  256. __HCP_FUNC_CLEANUP;
  257. __HCP_FUNC_EXIT(hr);
  258. }
  259. HRESULT Taxonomy::Updater::GetDBParameters( /*[out]*/ RS_DBParameters* *pVal )
  260. {
  261. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetDBParameters" );
  262. HRESULT hr;
  263. if(pVal) *pVal = NULL;
  264. __MPC_PARAMCHECK_BEGIN(hr)
  265. __MPC_PARAMCHECK_NOTNULL(m_db);
  266. __MPC_PARAMCHECK_END();
  267. if(m_rsDBParameters == NULL)
  268. {
  269. JetBlue::Table* tbl;
  270. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "DBParameters", tbl ));
  271. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsDBParameters, new RS_DBParameters( tbl ));
  272. }
  273. if(pVal) *pVal = m_rsDBParameters;
  274. hr = S_OK;
  275. __HCP_FUNC_CLEANUP;
  276. __HCP_FUNC_EXIT(hr);
  277. }
  278. HRESULT Taxonomy::Updater::GetContentOwners( /*[out]*/ RS_ContentOwners* *pVal )
  279. {
  280. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetContentOwners" );
  281. HRESULT hr;
  282. if(pVal) *pVal = NULL;
  283. __MPC_PARAMCHECK_BEGIN(hr)
  284. __MPC_PARAMCHECK_NOTNULL(m_db);
  285. __MPC_PARAMCHECK_END();
  286. if(m_rsContentOwners == NULL)
  287. {
  288. JetBlue::Table* tbl;
  289. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "ContentOwners", tbl ));
  290. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsContentOwners, new RS_ContentOwners( tbl ));
  291. }
  292. if(pVal) *pVal = m_rsContentOwners;
  293. hr = S_OK;
  294. __HCP_FUNC_CLEANUP;
  295. __HCP_FUNC_EXIT(hr);
  296. }
  297. HRESULT Taxonomy::Updater::GetSynSets( /*[out]*/ RS_SynSets* *pVal )
  298. {
  299. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetSynSets" );
  300. HRESULT hr;
  301. if(pVal) *pVal = NULL;
  302. __MPC_PARAMCHECK_BEGIN(hr)
  303. __MPC_PARAMCHECK_NOTNULL(m_db);
  304. __MPC_PARAMCHECK_END();
  305. if(m_rsSynSets == NULL)
  306. {
  307. JetBlue::Table* tbl;
  308. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "SynSets", tbl ));
  309. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsSynSets, new RS_SynSets( tbl ));
  310. }
  311. if(pVal) *pVal = m_rsSynSets;
  312. hr = S_OK;
  313. __HCP_FUNC_CLEANUP;
  314. __HCP_FUNC_EXIT(hr);
  315. }
  316. HRESULT Taxonomy::Updater::GetHelpImage( /*[out]*/ RS_HelpImage* *pVal )
  317. {
  318. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetHelpImage" );
  319. HRESULT hr;
  320. if(pVal) *pVal = NULL;
  321. __MPC_PARAMCHECK_BEGIN(hr)
  322. __MPC_PARAMCHECK_NOTNULL(m_db);
  323. __MPC_PARAMCHECK_END();
  324. if(m_rsHelpImage == NULL)
  325. {
  326. JetBlue::Table* tbl;
  327. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "HelpImage", tbl ));
  328. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsHelpImage, new RS_HelpImage( tbl ));
  329. }
  330. if(pVal) *pVal = m_rsHelpImage;
  331. hr = S_OK;
  332. __HCP_FUNC_CLEANUP;
  333. __HCP_FUNC_EXIT(hr);
  334. }
  335. HRESULT Taxonomy::Updater::GetIndexFiles( /*[out]*/ RS_IndexFiles* *pVal )
  336. {
  337. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetIndexFiles" );
  338. HRESULT hr;
  339. if(pVal) *pVal = NULL;
  340. __MPC_PARAMCHECK_BEGIN(hr)
  341. __MPC_PARAMCHECK_NOTNULL(m_db);
  342. __MPC_PARAMCHECK_END();
  343. if(m_rsIndexFiles == NULL)
  344. {
  345. JetBlue::Table* tbl;
  346. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "IndexFiles", tbl ));
  347. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsIndexFiles, new RS_IndexFiles( tbl ));
  348. }
  349. if(pVal) *pVal = m_rsIndexFiles;
  350. hr = S_OK;
  351. __HCP_FUNC_CLEANUP;
  352. __HCP_FUNC_EXIT(hr);
  353. }
  354. HRESULT Taxonomy::Updater::GetFullTextSearch( /*[out]*/ RS_FullTextSearch* *pVal )
  355. {
  356. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetFullTextSearch" );
  357. HRESULT hr;
  358. if(pVal) *pVal = NULL;
  359. __MPC_PARAMCHECK_BEGIN(hr)
  360. __MPC_PARAMCHECK_NOTNULL(m_db);
  361. __MPC_PARAMCHECK_END();
  362. if(m_rsFullTextSearch == NULL)
  363. {
  364. JetBlue::Table* tbl;
  365. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "FullTextSearch", tbl ));
  366. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsFullTextSearch, new RS_FullTextSearch( tbl ));
  367. }
  368. if(pVal) *pVal = m_rsFullTextSearch;
  369. hr = S_OK;
  370. __HCP_FUNC_CLEANUP;
  371. __HCP_FUNC_EXIT(hr);
  372. }
  373. HRESULT Taxonomy::Updater::GetScope( /*[out]*/ RS_Scope* *pVal )
  374. {
  375. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetScope" );
  376. HRESULT hr;
  377. if(pVal) *pVal = NULL;
  378. __MPC_PARAMCHECK_BEGIN(hr)
  379. __MPC_PARAMCHECK_NOTNULL(m_db);
  380. __MPC_PARAMCHECK_END();
  381. if(m_rsScope == NULL)
  382. {
  383. JetBlue::Table* tbl;
  384. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Scope", tbl ));
  385. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsScope, new RS_Scope( tbl ));
  386. }
  387. if(pVal) *pVal = m_rsScope;
  388. hr = S_OK;
  389. __HCP_FUNC_CLEANUP;
  390. __HCP_FUNC_EXIT(hr);
  391. }
  392. HRESULT Taxonomy::Updater::GetTaxonomy( /*[out]*/ RS_Taxonomy* *pVal )
  393. {
  394. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetTaxonomy" );
  395. HRESULT hr;
  396. if(pVal) *pVal = NULL;
  397. __MPC_PARAMCHECK_BEGIN(hr)
  398. __MPC_PARAMCHECK_NOTNULL(m_db);
  399. __MPC_PARAMCHECK_END();
  400. if(m_rsTaxonomy == NULL)
  401. {
  402. JetBlue::Table* tbl;
  403. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Taxonomy", tbl ));
  404. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsTaxonomy, new RS_Taxonomy( tbl ));
  405. }
  406. if(pVal) *pVal = m_rsTaxonomy;
  407. hr = S_OK;
  408. __HCP_FUNC_CLEANUP;
  409. __HCP_FUNC_EXIT(hr);
  410. }
  411. HRESULT Taxonomy::Updater::GetTopics( /*[out]*/ RS_Topics* *pVal )
  412. {
  413. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetTopics" );
  414. HRESULT hr;
  415. if(pVal) *pVal = NULL;
  416. __MPC_PARAMCHECK_BEGIN(hr)
  417. __MPC_PARAMCHECK_NOTNULL(m_db);
  418. __MPC_PARAMCHECK_END();
  419. if(m_rsTopics == NULL)
  420. {
  421. JetBlue::Table* tbl;
  422. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Topics", tbl ));
  423. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsTopics, new RS_Topics( tbl ));
  424. }
  425. if(pVal) *pVal = m_rsTopics;
  426. hr = S_OK;
  427. __HCP_FUNC_CLEANUP;
  428. __HCP_FUNC_EXIT(hr);
  429. }
  430. HRESULT Taxonomy::Updater::GetSynonyms( /*[out]*/ RS_Synonyms* *pVal )
  431. {
  432. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetSynonyms" );
  433. HRESULT hr;
  434. if(pVal) *pVal = NULL;
  435. __MPC_PARAMCHECK_BEGIN(hr)
  436. __MPC_PARAMCHECK_NOTNULL(m_db);
  437. __MPC_PARAMCHECK_END();
  438. if(m_rsSynonyms == NULL)
  439. {
  440. JetBlue::Table* tbl;
  441. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Synonyms", tbl ));
  442. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsSynonyms, new RS_Synonyms( tbl ));
  443. }
  444. if(pVal) *pVal = m_rsSynonyms;
  445. hr = S_OK;
  446. __HCP_FUNC_CLEANUP;
  447. __HCP_FUNC_EXIT(hr);
  448. }
  449. HRESULT Taxonomy::Updater::GetKeywords( /*[out]*/ RS_Keywords* *pVal )
  450. {
  451. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetKeywords" );
  452. HRESULT hr;
  453. if(pVal) *pVal = NULL;
  454. __MPC_PARAMCHECK_BEGIN(hr)
  455. __MPC_PARAMCHECK_NOTNULL(m_db);
  456. __MPC_PARAMCHECK_END();
  457. if(m_rsKeywords == NULL)
  458. {
  459. JetBlue::Table* tbl;
  460. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Keywords", tbl ));
  461. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsKeywords, new RS_Keywords( tbl ));
  462. }
  463. if(pVal) *pVal = m_rsKeywords;
  464. hr = S_OK;
  465. __HCP_FUNC_CLEANUP;
  466. __HCP_FUNC_EXIT(hr);
  467. }
  468. HRESULT Taxonomy::Updater::GetMatches( /*[out]*/ RS_Matches* *pVal )
  469. {
  470. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetMatches" );
  471. HRESULT hr;
  472. if(pVal) *pVal = NULL;
  473. __MPC_PARAMCHECK_BEGIN(hr)
  474. __MPC_PARAMCHECK_NOTNULL(m_db);
  475. __MPC_PARAMCHECK_END();
  476. if(m_rsMatches == NULL)
  477. {
  478. JetBlue::Table* tbl;
  479. __MPC_EXIT_IF_METHOD_FAILS(hr, m_db->GetTable( "Matches", tbl ));
  480. __MPC_EXIT_IF_ALLOC_FAILS(hr, m_rsMatches, new RS_Matches( tbl ));
  481. }
  482. if(pVal) *pVal = m_rsMatches;
  483. hr = S_OK;
  484. __HCP_FUNC_CLEANUP;
  485. __HCP_FUNC_EXIT(hr);
  486. }
  487. ////////////////////////////////////////////////////////////////////////////////
  488. ////////////////////////////////////////////////////////////////////////////////
  489. HRESULT Taxonomy::Updater::DeleteAllTopicsUnderANode( /*[in]*/ RS_Topics* rs ,
  490. /*[in]*/ long ID_node ,
  491. /*[in]*/ bool fCheck )
  492. {
  493. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteAllTopicsUnderANode" );
  494. HRESULT hr;
  495. bool fFound;
  496. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_TopicsUnderNode( ID_node, &fFound ));
  497. while(fFound && rs->m_ID_node == ID_node)
  498. {
  499. if(rs->m_ID_owner != m_ID_owner)
  500. {
  501. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  502. }
  503. if(fCheck == false)
  504. {
  505. __MPC_EXIT_IF_METHOD_FAILS(hr, GetMatches());
  506. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllMatchesPointingToTopic( m_rsMatches, rs->m_ID_topic ));
  507. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Delete()); STAT_DELETED( Topics );
  508. }
  509. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Move( 0, JET_MoveNext, &fFound ));
  510. }
  511. hr = S_OK;
  512. __HCP_FUNC_CLEANUP;
  513. __HCP_FUNC_EXIT(hr);
  514. }
  515. HRESULT Taxonomy::Updater::DeleteAllSubNodes( /*[in]*/ RS_Taxonomy* rs ,
  516. /*[in]*/ long ID_node ,
  517. /*[in]*/ bool fCheck )
  518. {
  519. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteAllSubNodes" );
  520. HRESULT hr;
  521. bool fFound;
  522. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllTopicsUnderANode( m_rsTopics, ID_node, fCheck ));
  523. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_Children( ID_node, &fFound ));
  524. while(fFound)
  525. {
  526. if(rs->m_ID_owner != m_ID_owner)
  527. {
  528. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  529. }
  530. {
  531. RS_Taxonomy subrs( *rs );
  532. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllSubNodes( &subrs, rs->m_ID_node, fCheck ));
  533. }
  534. if(fCheck == false)
  535. {
  536. //
  537. // Keep the node cache in sync.
  538. //
  539. NodeCache_Remove( rs->m_ID_node );
  540. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Delete()); STAT_DELETED( Taxonomy );
  541. }
  542. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Move( 0, JET_MoveNext, &fFound ));
  543. }
  544. hr = S_OK;
  545. __HCP_FUNC_CLEANUP;
  546. __HCP_FUNC_EXIT(hr);
  547. }
  548. HRESULT Taxonomy::Updater::DeleteAllMatchesPointingToTopic( /*[in]*/ RS_Matches* rs ,
  549. /*[in]*/ long ID_topic )
  550. {
  551. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteAllMatchesPointingToTopic" );
  552. HRESULT hr;
  553. bool fFound;
  554. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Seek_ByTopic( ID_topic, &fFound ));
  555. while(fFound)
  556. {
  557. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Delete()); STAT_DELETED( Matches );
  558. __MPC_EXIT_IF_METHOD_FAILS(hr, rs->Move( 0, JET_MoveNext, &fFound ));
  559. }
  560. hr = S_OK;
  561. __HCP_FUNC_CLEANUP;
  562. __HCP_FUNC_EXIT(hr);
  563. }
  564. ////////////////////////////////////////////////////////////////////////////////
  565. ////////////////////////////////////////////////////////////////////////////////
  566. HRESULT Taxonomy::Updater::ReadDBParameter( /*[in] */ LPCWSTR szName ,
  567. /*[out]*/ MPC::wstring& strValue ,
  568. /*[out]*/ bool *pfFound )
  569. {
  570. __HCP_FUNC_ENTRY( "Taxonomy::Updater::ReadDBParameter" );
  571. HRESULT hr;
  572. bool fFound;
  573. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDBParameters());
  574. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsDBParameters->Seek_ByName( szName, &fFound ));
  575. if(fFound)
  576. {
  577. strValue = m_rsDBParameters->m_strValue;
  578. }
  579. if(pfFound)
  580. {
  581. *pfFound = fFound;
  582. }
  583. else if(fFound == false)
  584. {
  585. __MPC_SET_ERROR_AND_EXIT(hr, JetBlue::JetERRToHRESULT(JET_errRecordNotFound));
  586. }
  587. hr = S_OK;
  588. __HCP_FUNC_CLEANUP;
  589. __HCP_FUNC_EXIT(hr);
  590. }
  591. HRESULT Taxonomy::Updater::ReadDBParameter( /*[in] */ LPCWSTR szName ,
  592. /*[out]*/ long& lValue ,
  593. /*[out]*/ bool *pfFound )
  594. {
  595. __HCP_FUNC_ENTRY( "Taxonomy::Updater::ReadDBParameter" );
  596. HRESULT hr;
  597. MPC::wstring strValue;
  598. __MPC_EXIT_IF_METHOD_FAILS(hr, ReadDBParameter( szName, strValue, pfFound ));
  599. lValue = _wtol( strValue.c_str() );
  600. hr = S_OK;
  601. __HCP_FUNC_CLEANUP;
  602. __HCP_FUNC_EXIT(hr);
  603. }
  604. HRESULT Taxonomy::Updater::WriteDBParameter( /*[in]*/ LPCWSTR szName ,
  605. /*[in]*/ LPCWSTR szValue )
  606. {
  607. __HCP_FUNC_ENTRY( "Taxonomy::Updater::WriteDBParameter" );
  608. HRESULT hr;
  609. bool fFound;
  610. __MPC_EXIT_IF_METHOD_FAILS(hr, GetDBParameters());
  611. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsDBParameters->Seek_ByName( szName, &fFound ));
  612. JET_SET_FIELD_TRISTATE(m_rsDBParameters,m_strValue,m_fValid__Value,szValue,STRINGISPRESENT(szValue));
  613. if(fFound)
  614. {
  615. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsDBParameters->Update());
  616. }
  617. else
  618. {
  619. m_rsDBParameters->m_strName = szName;
  620. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsDBParameters->Insert());
  621. }
  622. hr = S_OK;
  623. __HCP_FUNC_CLEANUP;
  624. __HCP_FUNC_EXIT(hr);
  625. }
  626. HRESULT Taxonomy::Updater::WriteDBParameter( /*[in]*/ LPCWSTR szName ,
  627. /*[in]*/ long lValue )
  628. {
  629. WCHAR rgValue[64]; swprintf( rgValue, L"%ld", lValue );
  630. return WriteDBParameter( szName, rgValue );
  631. }
  632. HRESULT Taxonomy::Updater::AddWordToSet( /*[in]*/ Updater_Set id ,
  633. /*[in]*/ LPCWSTR szValue )
  634. {
  635. return m_sets[id].Add( szValue );
  636. }
  637. HRESULT Taxonomy::Updater::RemoveWordFromSet( /*[in]*/ Updater_Set id, /*[in]*/ LPCWSTR szValue )
  638. {
  639. return m_sets[id].Remove( szValue );
  640. }
  641. const MPC::wstring& Taxonomy::Updater::GetHelpLocation()
  642. {
  643. if(m_strDBLocation.size() == 0)
  644. {
  645. if(Taxonomy::InstalledInstanceStore::s_GLOBAL)
  646. {
  647. Taxonomy::LockingHandle handle;
  648. Taxonomy::InstalledInstanceIter it;
  649. bool fFound;
  650. if(SUCCEEDED(Taxonomy::InstalledInstanceStore::s_GLOBAL->GrabControl( handle )) &&
  651. SUCCEEDED(Taxonomy::InstalledInstanceStore::s_GLOBAL->SKU_Find ( m_ts, fFound, it )) && fFound)
  652. {
  653. m_strDBLocation = it->m_inst.m_strHelpFiles;
  654. }
  655. }
  656. if(m_strDBLocation.size() == 0)
  657. {
  658. m_strDBLocation = HC_HELPSVC_HELPFILES_DEFAULT;
  659. }
  660. }
  661. return m_strDBLocation;
  662. }
  663. HRESULT Taxonomy::Updater::ExpandURL( /*[in/out]*/ MPC::wstring& strURL )
  664. {
  665. __HCP_FUNC_ENTRY( "Taxonomy::Updater::ExpandURL" );
  666. HRESULT hr;
  667. LPCWSTR szEnd;
  668. GetHelpLocation();
  669. szEnd = strURL.c_str();
  670. while((szEnd = wcschr( szEnd, '%' )))
  671. {
  672. if(!_wcsnicmp( szEnd, s_DB_LOCATION_ENV, MAXSTRLEN( s_DB_LOCATION_ENV ) ))
  673. {
  674. MPC::wstring::size_type pos = szEnd - strURL.c_str();
  675. strURL.replace( pos, MAXSTRLEN( s_DB_LOCATION_ENV ), m_strDBLocation );
  676. break;
  677. }
  678. szEnd++;
  679. }
  680. hr = MPC::SubstituteEnvVariables( strURL );
  681. __HCP_FUNC_EXIT(hr);
  682. }
  683. HRESULT Taxonomy::Updater::CollapseURL( /*[in/out]*/ MPC::wstring& strURL )
  684. {
  685. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CollapseURL" );
  686. HRESULT hr;
  687. MPC::wstring strBASE;
  688. CComBSTR bstrBASE;
  689. CComBSTR bstrURL;
  690. LPCWSTR szEnd;
  691. GetHelpLocation(); (void)MPC::SubstituteEnvVariables( strBASE = m_strDBLocation );
  692. bstrBASE = strBASE.c_str(); ::CharUpperW( bstrBASE );
  693. bstrURL = strURL .c_str(); ::CharUpperW( bstrURL );
  694. if(szEnd = wcsstr( bstrURL, bstrBASE ))
  695. {
  696. MPC::wstring::size_type pos = szEnd - bstrURL;
  697. strURL.replace( pos, bstrBASE.Length(), s_DB_LOCATION_ENV );
  698. }
  699. hr = S_OK;
  700. __HCP_FUNC_EXIT(hr);
  701. }
  702. HRESULT Taxonomy::Updater::ListAllTheHelpFiles( /*[out]*/ MPC::WStringList& lstFiles )
  703. {
  704. __HCP_FUNC_ENTRY( "Taxonomy::Updater::ListAllTheHelpFiles" );
  705. HRESULT hr;
  706. WordSet setFiles;
  707. WordIter it;
  708. bool fFound;
  709. //
  710. // Get all the files from the HelpImage list.
  711. //
  712. if(SUCCEEDED(GetHelpImage()))
  713. {
  714. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Move( 0, JET_MoveFirst, &fFound ));
  715. while(fFound)
  716. {
  717. if(m_rsHelpImage->m_strFile.empty() == false) setFiles.insert( m_rsHelpImage->m_strFile );
  718. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Move( 0, JET_MoveNext, &fFound ));
  719. }
  720. }
  721. //
  722. // Get all the CHM and CHQ from the FullTextSearch list.
  723. //
  724. if(SUCCEEDED(GetFullTextSearch()))
  725. {
  726. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Move( 0, JET_MoveFirst, &fFound ));
  727. while(fFound)
  728. {
  729. if(m_rsFullTextSearch->m_strCHM.empty() == false) setFiles.insert( m_rsFullTextSearch->m_strCHM );
  730. if(m_rsFullTextSearch->m_strCHQ.empty() == false) setFiles.insert( m_rsFullTextSearch->m_strCHQ );
  731. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Move( 0, JET_MoveNext, &fFound ));
  732. }
  733. }
  734. //
  735. // Get all the CHM from the IndexFiles list.
  736. //
  737. if(SUCCEEDED(GetIndexFiles()))
  738. {
  739. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Move( 0, JET_MoveFirst, &fFound ));
  740. while(fFound)
  741. {
  742. if(m_rsIndexFiles->m_strStorage.empty() == false) setFiles.insert( m_rsIndexFiles->m_strStorage );
  743. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Move( 0, JET_MoveNext, &fFound ));
  744. }
  745. }
  746. //
  747. // From a set to a list to a VARIANT.
  748. //
  749. for(it = setFiles.begin(); it != setFiles.end(); it++)
  750. {
  751. lstFiles.push_back( *it );
  752. }
  753. hr = S_OK;
  754. __HCP_FUNC_CLEANUP;
  755. __HCP_FUNC_EXIT(hr);
  756. }
  757. HRESULT Taxonomy::Updater::GetIndexInfo( /*[out]*/ MPC::wstring& strLocation, /*[out]*/ MPC::wstring& strDisplayName, /*[in]*/ LPCWSTR szScope )
  758. {
  759. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GetIndexInfo" );
  760. HRESULT hr;
  761. long ID_Scope = -1;
  762. long lOwner;
  763. if(szScope)
  764. {
  765. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateScope( ID_Scope, lOwner, szScope ));
  766. }
  767. __MPC_EXIT_IF_METHOD_FAILS(hr, m_ts.IndexFile( strLocation, ID_Scope ));
  768. strDisplayName = m_rsScope->m_strName;
  769. hr = S_OK;
  770. __HCP_FUNC_CLEANUP;
  771. __HCP_FUNC_EXIT(hr);
  772. }
  773. ////////////////////////////////////////////////////////////////////////////////
  774. ////////////////////////////////////////////////////////////////////////////////
  775. HRESULT Taxonomy::Updater::DeleteOwner()
  776. {
  777. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteOwner" );
  778. HRESULT hr;
  779. bool fFound;
  780. __MPC_EXIT_IF_METHOD_FAILS(hr, GetContentOwners());
  781. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Move( 0, JET_MoveFirst, &fFound ));
  782. while(fFound)
  783. {
  784. if(m_rsContentOwners->m_ID_owner == m_ID_owner)
  785. {
  786. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Delete()); STAT_DELETED( ContentOwners );
  787. m_ID_owner = -1;
  788. break;
  789. }
  790. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Move( 0, JET_MoveNext, &fFound ));
  791. }
  792. hr = S_OK;
  793. __HCP_FUNC_CLEANUP;
  794. __HCP_FUNC_EXIT(hr);
  795. }
  796. HRESULT Taxonomy::Updater::LocateOwner( /*[in] */ LPCWSTR szDN )
  797. {
  798. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateOwner" );
  799. HRESULT hr;
  800. bool fFound;
  801. m_ID_owner = -1;
  802. __MPC_EXIT_IF_METHOD_FAILS(hr, GetContentOwners());
  803. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Seek_ByVendorID( szDN, &fFound ));
  804. if(fFound)
  805. {
  806. m_ID_owner = m_rsContentOwners->m_ID_owner;
  807. m_fOEM = m_rsContentOwners->m_fIsOEM;
  808. }
  809. hr = S_OK;
  810. __HCP_FUNC_CLEANUP;
  811. __HCP_FUNC_EXIT(hr);
  812. }
  813. HRESULT Taxonomy::Updater::CreateOwner( /*[out]*/ long& ID_owner,
  814. /*[in] */ LPCWSTR szDN ,
  815. /*[in] */ bool fIsOEM )
  816. {
  817. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateOwner" );
  818. HRESULT hr;
  819. bool fFound;
  820. ID_owner = -1;
  821. __MPC_EXIT_IF_METHOD_FAILS(hr, GetContentOwners());
  822. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Seek_ByVendorID( szDN, &fFound ));
  823. m_rsContentOwners->m_fIsOEM = fIsOEM;
  824. if(fFound == true)
  825. {
  826. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Update()); STAT_MODIFIED( ContentOwners );
  827. }
  828. else
  829. {
  830. m_rsContentOwners->m_strDN = szDN;
  831. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsContentOwners->Insert()); STAT_CREATED( ContentOwners );
  832. }
  833. ID_owner = m_rsContentOwners->m_ID_owner;
  834. hr = S_OK;
  835. __HCP_FUNC_CLEANUP;
  836. __HCP_FUNC_EXIT(hr);
  837. }
  838. ////////////////////////////////////////////////////////////////////////////////
  839. ////////////////////////////////////////////////////////////////////////////////
  840. HRESULT Taxonomy::Updater::DeleteSynSet( /*[in]*/ LPCWSTR szName )
  841. {
  842. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteSynSet" );
  843. HRESULT hr;
  844. bool fFound;
  845. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynSets());
  846. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynSets->Seek_ByPair( szName, m_ID_owner, &fFound ));
  847. if(fFound)
  848. {
  849. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynSets->Delete()); STAT_DELETED( SynSets );
  850. }
  851. else
  852. {
  853. STAT_NOOP( SynSets );
  854. }
  855. hr = S_OK;
  856. __HCP_FUNC_CLEANUP;
  857. __HCP_FUNC_EXIT(hr);
  858. }
  859. HRESULT Taxonomy::Updater::LocateSynSet( /*[out]*/ long& ID_synset ,
  860. /*[in] */ LPCWSTR szName )
  861. {
  862. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateSynSet" );
  863. HRESULT hr;
  864. bool fFound;
  865. ID_synset = -1;
  866. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynSets());
  867. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynSets->Seek_ByPair( szName, m_ID_owner, &fFound ));
  868. if(fFound)
  869. {
  870. ID_synset = m_rsSynSets->m_ID_synset;
  871. }
  872. hr = S_OK;
  873. __HCP_FUNC_CLEANUP;
  874. __HCP_FUNC_EXIT(hr);
  875. }
  876. HRESULT Taxonomy::Updater::CreateSynSet( /*[out]*/ long& ID_synset ,
  877. /*[in ]*/ LPCWSTR szName )
  878. {
  879. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateSynSet" );
  880. HRESULT hr;
  881. bool fFound;
  882. ID_synset = -1;
  883. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynSets());
  884. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynSets->Seek_ByPair( szName, m_ID_owner, &fFound ));
  885. if(!fFound)
  886. {
  887. m_rsSynSets->m_strName = szName;
  888. m_rsSynSets->m_ID_owner = m_ID_owner;
  889. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynSets->Insert()); STAT_CREATED( SynSets );
  890. }
  891. else
  892. {
  893. STAT_NOOP( SynSets );
  894. }
  895. ID_synset = m_rsSynSets->m_ID_synset;
  896. hr = S_OK;
  897. __HCP_FUNC_CLEANUP;
  898. __HCP_FUNC_EXIT(hr);
  899. }
  900. ////////////////////////////////////////
  901. HRESULT Taxonomy::Updater::DeleteSynonym( /*[in]*/ long ID_synset ,
  902. /*[in]*/ LPCWSTR szName )
  903. {
  904. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteSynonym" );
  905. HRESULT hr;
  906. bool fFound;
  907. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynonyms());
  908. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Seek_ByPair( szName, ID_synset, &fFound ));
  909. if(fFound)
  910. {
  911. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Delete()); STAT_DELETED( Synonyms );
  912. }
  913. else
  914. {
  915. STAT_NOOP( Synonyms );
  916. }
  917. hr = S_OK;
  918. __HCP_FUNC_CLEANUP;
  919. __HCP_FUNC_EXIT(hr);
  920. }
  921. HRESULT Taxonomy::Updater::CreateSynonym( /*[in]*/ long ID_synset ,
  922. /*[in]*/ LPCWSTR szName )
  923. {
  924. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateSynonym" );
  925. HRESULT hr;
  926. bool fFound;
  927. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynonyms());
  928. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Seek_ByPair( szName, ID_synset, &fFound ));
  929. if(!fFound)
  930. {
  931. m_rsSynonyms->m_strKeyword = szName;
  932. m_rsSynonyms->m_ID_synset = ID_synset;
  933. m_rsSynonyms->m_ID_owner = m_ID_owner;
  934. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Insert()); STAT_CREATED( Synonyms );
  935. }
  936. else
  937. {
  938. STAT_NOOP( Synonyms );
  939. }
  940. hr = S_OK;
  941. __HCP_FUNC_CLEANUP;
  942. __HCP_FUNC_EXIT(hr);
  943. }
  944. ////////////////////////////////////////
  945. HRESULT Taxonomy::Updater::LocateSynonyms( /*[in ]*/ LPCWSTR szName ,
  946. /*[out]*/ MPC::WStringList& lst ,
  947. /*[in ]*/ bool fMatchOwner )
  948. {
  949. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateSynonyms" );
  950. HRESULT hr;
  951. bool fFound;
  952. __MPC_EXIT_IF_METHOD_FAILS(hr, GetSynonyms());
  953. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Seek_ByName( szName, &fFound ));
  954. while(fFound)
  955. {
  956. if(fMatchOwner == false || m_rsSynonyms->m_ID_owner == m_ID_owner)
  957. {
  958. WCHAR rgBuf[64]; swprintf( rgBuf, L"SYNSET_%ld", m_rsSynonyms->m_ID_synset );
  959. lst.push_back( rgBuf );
  960. }
  961. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsSynonyms->Move( 0, JET_MoveNext, &fFound ));
  962. }
  963. hr = S_OK;
  964. __HCP_FUNC_CLEANUP;
  965. __HCP_FUNC_EXIT(hr);
  966. }
  967. ////////////////////////////////////////////////////////////////////////////////
  968. ////////////////////////////////////////////////////////////////////////////////
  969. HRESULT Taxonomy::Updater::AddFile( /*[in]*/ LPCWSTR szFile )
  970. {
  971. __HCP_FUNC_ENTRY( "Taxonomy::Updater::AddFile" );
  972. HRESULT hr;
  973. bool fFound;
  974. __MPC_EXIT_IF_METHOD_FAILS(hr, GetHelpImage());
  975. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Seek_ByFile( szFile, &fFound ));
  976. if(fFound)
  977. {
  978. if(m_rsHelpImage->m_ID_owner != m_ID_owner)
  979. {
  980. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  981. }
  982. STAT_NOOP( HelpImage );
  983. }
  984. else
  985. {
  986. JET_SET_FIELD(m_rsHelpImage,m_ID_owner,m_ID_owner);
  987. JET_SET_FIELD(m_rsHelpImage,m_strFile , szFile );
  988. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Insert()); STAT_CREATED( HelpImage );
  989. }
  990. hr = S_OK;
  991. __HCP_FUNC_CLEANUP;
  992. __HCP_FUNC_EXIT(hr);
  993. }
  994. HRESULT Taxonomy::Updater::RemoveFile( /*[in]*/ LPCWSTR szFile )
  995. {
  996. __HCP_FUNC_ENTRY( "Taxonomy::Updater::RemoveFile" );
  997. HRESULT hr;
  998. bool fFound;
  999. __MPC_EXIT_IF_METHOD_FAILS(hr, GetHelpImage());
  1000. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Seek_ByFile( szFile, &fFound ));
  1001. if(fFound)
  1002. {
  1003. if(m_rsHelpImage->m_ID_owner != m_ID_owner)
  1004. {
  1005. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1006. }
  1007. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsHelpImage->Delete()); STAT_DELETED( HelpImage );
  1008. }
  1009. else
  1010. {
  1011. STAT_NOOP( HelpImage );
  1012. }
  1013. hr = S_OK;
  1014. __HCP_FUNC_CLEANUP;
  1015. __HCP_FUNC_EXIT(hr);
  1016. }
  1017. ////////////////////////////////////////////////////////////////////////////////
  1018. ////////////////////////////////////////////////////////////////////////////////
  1019. HRESULT Taxonomy::Updater::AddIndexFile( /*[in]*/ long ID_scope, /*[in]*/ LPCWSTR szStorage, /*[in]*/ LPCWSTR szFile )
  1020. {
  1021. __HCP_FUNC_ENTRY( "Taxonomy::Updater::AddIndexFile" );
  1022. HRESULT hr;
  1023. bool fFound;
  1024. __MPC_EXIT_IF_METHOD_FAILS(hr, GetIndexFiles());
  1025. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Seek_ByScope( ID_scope, &fFound ));
  1026. while(fFound)
  1027. {
  1028. if(!MPC::StrICmp( m_rsIndexFiles->m_strStorage, szStorage ) &&
  1029. !MPC::StrICmp( m_rsIndexFiles->m_strFile , szFile ) )
  1030. {
  1031. if(m_rsIndexFiles->m_ID_owner != m_ID_owner)
  1032. {
  1033. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1034. }
  1035. break;
  1036. }
  1037. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Move( 0, JET_MoveNext, &fFound ));
  1038. }
  1039. JET_SET_FIELD_TRISTATE(m_rsIndexFiles,m_strStorage,m_fValid__Storage,szStorage,STRINGISPRESENT(szStorage));
  1040. JET_SET_FIELD_TRISTATE(m_rsIndexFiles,m_strFile ,m_fValid__File ,szFile ,STRINGISPRESENT(szFile ));
  1041. if(fFound)
  1042. {
  1043. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Update()); STAT_MODIFIED( IndexFiles );
  1044. }
  1045. else
  1046. {
  1047. JET_SET_FIELD(m_rsIndexFiles,m_ID_owner,m_ID_owner);
  1048. JET_SET_FIELD(m_rsIndexFiles,m_ID_scope, ID_scope);
  1049. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Insert()); STAT_CREATED( IndexFiles );
  1050. }
  1051. hr = S_OK;
  1052. __HCP_FUNC_CLEANUP;
  1053. __HCP_FUNC_EXIT(hr);
  1054. }
  1055. HRESULT Taxonomy::Updater::RemoveIndexFile( /*[in]*/ long ID_scope, /*[in]*/ LPCWSTR szStorage, /*[in]*/ LPCWSTR szFile )
  1056. {
  1057. __HCP_FUNC_ENTRY( "Taxonomy::Updater::RemoveIndexFile" );
  1058. HRESULT hr;
  1059. bool fFound;
  1060. __MPC_EXIT_IF_METHOD_FAILS(hr, GetIndexFiles());
  1061. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Seek_ByScope( ID_scope, &fFound ));
  1062. while(fFound)
  1063. {
  1064. if(!MPC::StrICmp( m_rsIndexFiles->m_strStorage, szStorage ) &&
  1065. !MPC::StrICmp( m_rsIndexFiles->m_strFile , szFile ) )
  1066. {
  1067. if(m_rsIndexFiles->m_ID_owner != m_ID_owner)
  1068. {
  1069. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1070. }
  1071. break;
  1072. }
  1073. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Move( 0, JET_MoveNext, &fFound ));
  1074. }
  1075. if(fFound)
  1076. {
  1077. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsIndexFiles->Delete()); STAT_DELETED( IndexFiles );
  1078. }
  1079. else
  1080. {
  1081. STAT_NOOP( IndexFiles );
  1082. }
  1083. hr = S_OK;
  1084. __HCP_FUNC_CLEANUP;
  1085. __HCP_FUNC_EXIT(hr);
  1086. }
  1087. ////////////////////////////////////////////////////////////////////////////////
  1088. ////////////////////////////////////////////////////////////////////////////////
  1089. HRESULT Taxonomy::Updater::AddFullTextSearchQuery( /*[in]*/ long ID_scope, /*[in]*/ LPCWSTR szCHM, /*[in]*/ LPCWSTR szCHQ )
  1090. {
  1091. __HCP_FUNC_ENTRY( "Taxonomy::Updater::AddFullTextSearchQuery" );
  1092. HRESULT hr;
  1093. bool fFound;
  1094. __MPC_EXIT_IF_METHOD_FAILS(hr, GetFullTextSearch());
  1095. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Seek_ByScope( ID_scope, &fFound ));
  1096. while(fFound)
  1097. {
  1098. if(!MPC::StrICmp( m_rsFullTextSearch->m_strCHM, szCHM ))
  1099. {
  1100. if(m_rsFullTextSearch->m_ID_owner != m_ID_owner)
  1101. {
  1102. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1103. }
  1104. break;
  1105. }
  1106. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Move( 0, JET_MoveNext, &fFound ));
  1107. }
  1108. JET_SET_FIELD_TRISTATE(m_rsFullTextSearch,m_strCHM,m_fValid__CHM, szCHM,STRINGISPRESENT(szCHM));
  1109. JET_SET_FIELD_TRISTATE(m_rsFullTextSearch,m_strCHQ,m_fValid__CHQ, szCHQ,STRINGISPRESENT(szCHQ));
  1110. if(fFound)
  1111. {
  1112. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Update()); STAT_MODIFIED( FullTextSearch );
  1113. }
  1114. else
  1115. {
  1116. JET_SET_FIELD(m_rsFullTextSearch,m_ID_owner,m_ID_owner);
  1117. JET_SET_FIELD(m_rsFullTextSearch,m_ID_scope, ID_scope);
  1118. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Insert()); STAT_CREATED( FullTextSearch );
  1119. }
  1120. hr = S_OK;
  1121. __HCP_FUNC_CLEANUP;
  1122. __HCP_FUNC_EXIT(hr);
  1123. }
  1124. HRESULT Taxonomy::Updater::RemoveFullTextSearchQuery( /*[in]*/ long ID_scope, /*[in]*/ LPCWSTR szCHM )
  1125. {
  1126. __HCP_FUNC_ENTRY( "Taxonomy::Updater::RemoveFullTextSearchQuery" );
  1127. HRESULT hr;
  1128. bool fFound;
  1129. __MPC_EXIT_IF_METHOD_FAILS(hr, GetFullTextSearch());
  1130. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Seek_ByScope( ID_scope, &fFound ));
  1131. while(fFound)
  1132. {
  1133. if(!MPC::StrICmp( m_rsFullTextSearch->m_strCHM, szCHM ))
  1134. {
  1135. if(m_rsFullTextSearch->m_ID_owner != m_ID_owner)
  1136. {
  1137. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1138. }
  1139. break;
  1140. }
  1141. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Move( 0, JET_MoveNext, &fFound ));
  1142. }
  1143. if(fFound)
  1144. {
  1145. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsFullTextSearch->Delete()); STAT_DELETED( FullTextSearch );
  1146. }
  1147. else
  1148. {
  1149. STAT_NOOP( FullTextSearch );
  1150. }
  1151. hr = S_OK;
  1152. __HCP_FUNC_CLEANUP;
  1153. __HCP_FUNC_EXIT(hr);
  1154. }
  1155. ////////////////////////////////////////////////////////////////////////////////
  1156. ////////////////////////////////////////////////////////////////////////////////
  1157. HRESULT Taxonomy::Updater::RemoveScope( /*[in]*/ long ID_scope )
  1158. {
  1159. __HCP_FUNC_ENTRY( "Taxonomy::Updater::RemoveScope" );
  1160. HRESULT hr;
  1161. bool fFound;
  1162. __MPC_EXIT_IF_METHOD_FAILS(hr, GetScope());
  1163. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Seek_ByScope( ID_scope, &fFound ));
  1164. if(fFound)
  1165. {
  1166. if(m_rsScope->m_ID_owner != m_ID_owner)
  1167. {
  1168. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1169. }
  1170. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Delete()); STAT_DELETED( Scope );
  1171. }
  1172. else
  1173. {
  1174. STAT_NOOP( Scope );
  1175. }
  1176. hr = S_OK;
  1177. __HCP_FUNC_CLEANUP;
  1178. __HCP_FUNC_EXIT(hr);
  1179. }
  1180. HRESULT Taxonomy::Updater::LocateScope( /*[out]*/ long& ID_scope, /*[out]*/ long& ID_owner, /*[in]*/ LPCWSTR szID )
  1181. {
  1182. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateScope" );
  1183. HRESULT hr;
  1184. bool fFound;
  1185. __MPC_EXIT_IF_METHOD_FAILS(hr, GetScope());
  1186. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Seek_ByID( szID, &fFound ));
  1187. if(fFound)
  1188. {
  1189. ID_scope = m_rsScope->m_ID_scope;
  1190. ID_owner = m_rsScope->m_ID_owner;
  1191. }
  1192. else
  1193. {
  1194. ID_scope = -1;
  1195. ID_owner = -1;
  1196. }
  1197. hr = S_OK;
  1198. __HCP_FUNC_CLEANUP;
  1199. __HCP_FUNC_EXIT(hr);
  1200. }
  1201. HRESULT Taxonomy::Updater::CreateScope( /*[out]*/ long& ID_scope, /*[in]*/ LPCWSTR szID, /*[in]*/ LPCWSTR szName, /*[in]*/ LPCWSTR szCategory )
  1202. {
  1203. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateScope" );
  1204. HRESULT hr;
  1205. bool fFound;
  1206. ID_scope = -1;
  1207. __MPC_EXIT_IF_METHOD_FAILS(hr, GetScope());
  1208. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Seek_ByID( szID, &fFound ));
  1209. if(fFound)
  1210. {
  1211. if(m_rsScope->m_ID_owner != m_ID_owner)
  1212. {
  1213. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1214. }
  1215. }
  1216. JET_SET_FIELD (m_rsScope,m_strID , szID );
  1217. JET_SET_FIELD (m_rsScope,m_strName , szName );
  1218. JET_SET_FIELD_TRISTATE(m_rsScope,m_strCategory,m_fValid__Category,szCategory,STRINGISPRESENT(szCategory));
  1219. if(fFound)
  1220. {
  1221. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Update()); STAT_MODIFIED( Scope );
  1222. }
  1223. else
  1224. {
  1225. JET_SET_FIELD(m_rsScope,m_ID_owner, m_ID_owner);
  1226. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsScope->Insert()); STAT_CREATED( Scope );
  1227. }
  1228. ID_scope = m_rsScope->m_ID_scope;
  1229. hr = S_OK;
  1230. __HCP_FUNC_CLEANUP;
  1231. __HCP_FUNC_EXIT(hr);
  1232. }
  1233. ////////////////////////////////////////////////////////////////////////////////
  1234. ////////////////////////////////////////////////////////////////////////////////
  1235. bool Taxonomy::Updater::NodeCache_FindNode( /*[in ]*/ MPC::wstringUC& strPathUC, /*[out]*/ JetBlue::Id2NodeIter& itNode )
  1236. {
  1237. itNode = m_nodes.find( strPathUC );
  1238. return (itNode != m_nodes.end());
  1239. }
  1240. bool Taxonomy::Updater::NodeCache_FindId( /*[in ]*/ long ID_node, /*[out]*/ JetBlue::Node2IdIter& itId )
  1241. {
  1242. itId = m_nodes_reverse.find( ID_node );
  1243. return (itId != m_nodes_reverse.end());
  1244. }
  1245. void Taxonomy::Updater::NodeCache_Add( /*[in]*/ MPC::wstringUC& strPathUC, /*[in]*/ long ID_node )
  1246. {
  1247. m_nodes [ strPathUC ] = ID_node;
  1248. m_nodes_reverse[ ID_node ] = strPathUC;
  1249. }
  1250. void Taxonomy::Updater::NodeCache_Remove( /*[in]*/ long ID_node )
  1251. {
  1252. JetBlue::Node2IdIter itId;
  1253. JetBlue::Id2NodeIter itNode;
  1254. itId = m_nodes_reverse.find( ID_node );
  1255. if(itId != m_nodes_reverse.end())
  1256. {
  1257. m_nodes .erase( itId->second );
  1258. m_nodes_reverse.erase( itId );
  1259. }
  1260. }
  1261. void Taxonomy::Updater::NodeCache_Clear()
  1262. {
  1263. m_nodes .clear();
  1264. m_nodes_reverse.clear();
  1265. }
  1266. ////////////////////////////////////////////////////////////////////////////////
  1267. ////////////////////////////////////////////////////////////////////////////////
  1268. HRESULT Taxonomy::Updater::DeleteTaxonomyNode( /*[in ]*/ long ID_node )
  1269. {
  1270. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteTaxonomyNode" );
  1271. HRESULT hr;
  1272. bool fFound;
  1273. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTaxonomy());
  1274. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics ());
  1275. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Seek_Node( ID_node, &fFound ));
  1276. if(fFound)
  1277. {
  1278. if(m_rsTaxonomy->m_ID_owner != m_ID_owner)
  1279. {
  1280. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1281. }
  1282. //
  1283. // Before deleting the node, check everything below it can be deleted, then delete it.
  1284. //
  1285. {
  1286. RS_Taxonomy subrs( *m_rsTaxonomy );
  1287. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllSubNodes( &subrs, ID_node, true ));
  1288. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllSubNodes( &subrs, ID_node, false ));
  1289. }
  1290. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Delete()); STAT_DELETED( Taxonomy );
  1291. //
  1292. // Keep the node cache in sync.
  1293. //
  1294. NodeCache_Remove( ID_node );
  1295. }
  1296. else
  1297. {
  1298. STAT_NOOP( Taxonomy );
  1299. }
  1300. hr = S_OK;
  1301. __HCP_FUNC_CLEANUP;
  1302. __HCP_FUNC_EXIT(hr);
  1303. }
  1304. HRESULT Taxonomy::Updater::LocateTaxonomyNode( /*[out]*/ long& ID_node ,
  1305. /*[in ]*/ LPCWSTR szTaxonomyPath ,
  1306. /*[in ]*/ bool fLookForFather )
  1307. {
  1308. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateTaxonomyNode" );
  1309. HRESULT hr;
  1310. MPC::WStringVector vec;
  1311. MPC::WStringVectorIter it;
  1312. MPC::wstring strPath;
  1313. MPC::wstringUC strPathUC;
  1314. JetBlue::Id2NodeIter itNode;
  1315. long idCurrent = -1;
  1316. int iLast;
  1317. int i;
  1318. ID_node = -1;
  1319. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTaxonomy());
  1320. __MPC_EXIT_IF_METHOD_FAILS(hr, Taxonomy::Settings::SplitNodePath( szTaxonomyPath, vec ));
  1321. it = vec.begin();
  1322. iLast = vec.size (); if(fLookForFather) iLast--;
  1323. for(i=0; i<iLast; i++, it++)
  1324. {
  1325. //
  1326. // Build partial node path.
  1327. //
  1328. if(strPath.size()) strPath.append( L"/" );
  1329. strPath.append( *it );
  1330. //
  1331. // If we are already seen the node, it's in the cache.
  1332. //
  1333. if(NodeCache_FindNode( strPathUC = strPath, itNode ))
  1334. {
  1335. idCurrent = itNode->second;
  1336. }
  1337. else
  1338. {
  1339. LPCWSTR szEntry = it->c_str();
  1340. if(m_cache == NULL || FAILED(m_cache->LocateNode( m_ts, idCurrent, szEntry, *m_rsTaxonomy )))
  1341. {
  1342. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Seek_SubNode( idCurrent, szEntry ));
  1343. }
  1344. idCurrent = m_rsTaxonomy->m_ID_node;
  1345. //
  1346. // Update cache.
  1347. //
  1348. NodeCache_Add( strPathUC, idCurrent );
  1349. }
  1350. }
  1351. ID_node = idCurrent;
  1352. hr = S_OK;
  1353. __HCP_FUNC_CLEANUP;
  1354. __HCP_FUNC_EXIT(hr);
  1355. }
  1356. HRESULT Taxonomy::Updater::CreateTaxonomyNode( /*[out]*/ long& ID_node ,
  1357. /*[in ]*/ LPCWSTR szTaxonomyPath ,
  1358. /*[in ]*/ LPCWSTR szTitle ,
  1359. /*[in ]*/ LPCWSTR szDescription ,
  1360. /*[in ]*/ LPCWSTR szURI ,
  1361. /*[in ]*/ LPCWSTR szIconURI ,
  1362. /*[in ]*/ bool fVisible ,
  1363. /*[in ]*/ bool fSubsite ,
  1364. /*[in ]*/ long lNavModel ,
  1365. /*[in ]*/ long lPos )
  1366. {
  1367. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateTaxonomyNode" );
  1368. HRESULT hr;
  1369. LPCWSTR szEntry;
  1370. long ID_parent;
  1371. bool fFound;
  1372. ID_node = -1;
  1373. __MPC_PARAMCHECK_BEGIN(hr)
  1374. __MPC_PARAMCHECK_NOTNULL(szTaxonomyPath);
  1375. __MPC_PARAMCHECK_END();
  1376. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTaxonomy());
  1377. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_parent, szTaxonomyPath, true ));
  1378. //
  1379. // Extract the last component of the Category.
  1380. //
  1381. if((szEntry = wcsrchr( szTaxonomyPath, '/' )))
  1382. {
  1383. szEntry++;
  1384. }
  1385. else
  1386. {
  1387. szEntry = szTaxonomyPath;
  1388. }
  1389. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Seek_SubNode( ID_parent, szEntry, &fFound ));
  1390. if(fFound && m_rsTaxonomy->m_ID_owner != m_ID_owner)
  1391. {
  1392. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1393. }
  1394. JET_SET_FIELD_TRISTATE(m_rsTaxonomy,m_ID_parent ,m_fValid__ID_parent , ID_parent ,(ID_parent != -1 ));
  1395. JET_SET_FIELD (m_rsTaxonomy,m_ID_owner ,m_ID_owner );
  1396. JET_SET_FIELD (m_rsTaxonomy,m_strEntry , szEntry );
  1397. JET_SET_FIELD_TRISTATE(m_rsTaxonomy,m_strTitle ,m_fValid__Title , szTitle ,STRINGISPRESENT(szTitle ));
  1398. JET_SET_FIELD_TRISTATE(m_rsTaxonomy,m_strDescription ,m_fValid__Description , szDescription,STRINGISPRESENT(szDescription));
  1399. JET_SET_FIELD_TRISTATE(m_rsTaxonomy,m_strDescriptionURI,m_fValid__DescriptionURI, szURI ,STRINGISPRESENT(szURI ));
  1400. JET_SET_FIELD_TRISTATE(m_rsTaxonomy,m_strIconURI ,m_fValid__IconURI , szIconURI ,STRINGISPRESENT(szIconURI ));
  1401. JET_SET_FIELD (m_rsTaxonomy,m_fVisible , fVisible );
  1402. JET_SET_FIELD (m_rsTaxonomy,m_fSubsite , fSubsite );
  1403. JET_SET_FIELD (m_rsTaxonomy,m_lNavModel , lNavModel );
  1404. if(fFound)
  1405. {
  1406. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Update()); STAT_MODIFIED( Taxonomy );
  1407. }
  1408. else
  1409. {
  1410. //
  1411. // Respect the positioning attributes only if the Node doesn't already exist.
  1412. //
  1413. JET_SET_FIELD(m_rsTaxonomy, m_lPos, lPos);
  1414. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Insert()); STAT_CREATED( Taxonomy );
  1415. }
  1416. ID_node = m_rsTaxonomy->m_ID_node;
  1417. {
  1418. JetBlue::Node2IdIter itId;
  1419. if(NodeCache_FindId( ID_parent, itId ))
  1420. {
  1421. MPC::wstring strPath = itId->second;
  1422. strPath.append( L"/" );
  1423. strPath.append( szEntry );
  1424. //
  1425. // Update cache.
  1426. //
  1427. NodeCache_Add( MPC::wstringUC( strPath ), ID_node );
  1428. }
  1429. }
  1430. hr = S_OK;
  1431. __HCP_FUNC_CLEANUP;
  1432. __HCP_FUNC_EXIT(hr);
  1433. }
  1434. ////////////////////////////////////////////////////////////////////////////////
  1435. ////////////////////////////////////////////////////////////////////////////////
  1436. HRESULT Taxonomy::Updater::DeleteTopicEntry( /*[in]*/ long ID_topic )
  1437. {
  1438. __HCP_FUNC_ENTRY( "Taxonomy::Updater::DeleteTopicEntry" );
  1439. HRESULT hr;
  1440. bool fFound;
  1441. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics ());
  1442. __MPC_EXIT_IF_METHOD_FAILS(hr, GetMatches());
  1443. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Seek_SingleTopic( ID_topic, &fFound ));
  1444. if(fFound)
  1445. {
  1446. if(m_rsTopics->m_ID_owner != m_ID_owner)
  1447. {
  1448. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1449. }
  1450. __MPC_EXIT_IF_METHOD_FAILS(hr, DeleteAllMatchesPointingToTopic( m_rsMatches, ID_topic ));
  1451. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Delete()); STAT_DELETED( Topics );
  1452. }
  1453. else
  1454. {
  1455. STAT_NOOP( Topics );
  1456. }
  1457. hr = S_OK;
  1458. __HCP_FUNC_CLEANUP;
  1459. __HCP_FUNC_EXIT(hr);
  1460. }
  1461. HRESULT Taxonomy::Updater::LocateTopicEntry( /*[out]*/ long& ID_topic ,
  1462. /*[in ]*/ long ID_node ,
  1463. /*[in ]*/ LPCWSTR szURI ,
  1464. /*[in ]*/ bool fCheckOwner )
  1465. {
  1466. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateTopicEntry" );
  1467. HRESULT hr;
  1468. bool fFound;
  1469. ID_topic = -1;
  1470. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics());
  1471. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Seek_TopicsUnderNode( ID_node, &fFound ));
  1472. while(fFound)
  1473. {
  1474. if(!MPC::StrICmp( m_rsTopics->m_strURI, szURI ))
  1475. {
  1476. if(fCheckOwner && m_rsTopics->m_ID_owner != m_ID_owner)
  1477. {
  1478. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_ACCESS_DENIED);
  1479. }
  1480. ID_topic = m_rsTopics->m_ID_topic;
  1481. break;
  1482. }
  1483. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Move( 0, JET_MoveNext, &fFound ));
  1484. }
  1485. hr = S_OK;
  1486. __HCP_FUNC_CLEANUP;
  1487. __HCP_FUNC_EXIT(hr);
  1488. }
  1489. HRESULT Taxonomy::Updater::CreateTopicEntry( /*[out]*/ long& ID_topic ,
  1490. /*[in]*/ long ID_node ,
  1491. /*[in]*/ LPCWSTR szTitle ,
  1492. /*[in]*/ LPCWSTR szURI ,
  1493. /*[in]*/ LPCWSTR szDescription ,
  1494. /*[in]*/ LPCWSTR szIconURI ,
  1495. /*[in]*/ long lType ,
  1496. /*[in]*/ bool fVisible ,
  1497. /*[in]*/ long lPos )
  1498. {
  1499. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateTopicEntry" );
  1500. HRESULT hr;
  1501. bool fFound;
  1502. ID_topic = -1;
  1503. __MPC_PARAMCHECK_BEGIN(hr)
  1504. __MPC_PARAMCHECK_NOTNULL(szTitle);
  1505. __MPC_PARAMCHECK_NOTNULL(szURI);
  1506. __MPC_PARAMCHECK_END();
  1507. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics());
  1508. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTopicEntry( ID_topic, ID_node, szURI, /*fCheckOwner*/true ));
  1509. JET_SET_FIELD (m_rsTopics,m_ID_node , ID_node );
  1510. JET_SET_FIELD (m_rsTopics,m_ID_owner ,m_ID_owner );
  1511. JET_SET_FIELD_TRISTATE(m_rsTopics,m_strTitle ,m_fValid__Title , szTitle ,STRINGISPRESENT(szTitle ));
  1512. JET_SET_FIELD_TRISTATE(m_rsTopics,m_strURI ,m_fValid__URI , szURI ,STRINGISPRESENT(szURI ));
  1513. JET_SET_FIELD_TRISTATE(m_rsTopics,m_strDescription,m_fValid__Description, szDescription,STRINGISPRESENT(szDescription));
  1514. JET_SET_FIELD_TRISTATE(m_rsTopics,m_strIconURI ,m_fValid__IconURI , szIconURI ,STRINGISPRESENT(szIconURI ));
  1515. JET_SET_FIELD (m_rsTopics,m_lType , lType );
  1516. JET_SET_FIELD (m_rsTopics,m_lPos , lPos );
  1517. JET_SET_FIELD (m_rsTopics,m_fVisible , fVisible );
  1518. if(ID_topic == -1)
  1519. {
  1520. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Insert()); STAT_CREATED( Topics );
  1521. ID_topic = m_rsTopics->m_ID_topic;
  1522. }
  1523. else
  1524. {
  1525. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Update()); STAT_MODIFIED( Topics );
  1526. }
  1527. hr = S_OK;
  1528. __HCP_FUNC_CLEANUP;
  1529. __HCP_FUNC_EXIT(hr);
  1530. }
  1531. ////////////////////////////////////////////////////////////////////////////////
  1532. ////////////////////////////////////////////////////////////////////////////////
  1533. HRESULT Taxonomy::Updater::CreateMatch( /*[in]*/ LPCWSTR szKeyword ,
  1534. /*[in]*/ long ID_topic ,
  1535. /*[in]*/ long lPriority ,
  1536. /*[in]*/ bool fHHK )
  1537. {
  1538. __HCP_FUNC_ENTRY( "Taxonomy::Updater::CreateMatch" );
  1539. HRESULT hr;
  1540. bool fFound;
  1541. __MPC_EXIT_IF_METHOD_FAILS(hr, GetKeywords());
  1542. __MPC_EXIT_IF_METHOD_FAILS(hr, GetMatches ());
  1543. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsKeywords->Seek_ByName( szKeyword, &fFound ));
  1544. if(fFound == false)
  1545. {
  1546. JET_SET_FIELD(m_rsKeywords,m_strKeyword,szKeyword);
  1547. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsKeywords->Insert()); STAT_CREATED( Keywords );
  1548. }
  1549. JET_SET_FIELD(m_rsMatches,m_ID_topic ,ID_topic );
  1550. JET_SET_FIELD(m_rsMatches,m_ID_keyword,m_rsKeywords->m_ID_keyword);
  1551. JET_SET_FIELD(m_rsMatches,m_lPriority ,lPriority );
  1552. JET_SET_FIELD(m_rsMatches,m_fHHK ,fHHK );
  1553. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsMatches->Seek_Pair( m_rsKeywords->m_ID_keyword, ID_topic, &fFound ));
  1554. if(fFound)
  1555. {
  1556. if(m_rsMatches->m_lPriority != lPriority ||
  1557. m_rsMatches->m_fHHK != fHHK )
  1558. {
  1559. JET_SET_FIELD(m_rsMatches,m_lPriority,lPriority);
  1560. JET_SET_FIELD(m_rsMatches,m_fHHK ,fHHK );
  1561. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsMatches->Update()); STAT_MODIFIED( Matches );
  1562. }
  1563. else
  1564. {
  1565. STAT_NOOP( Matches );
  1566. }
  1567. }
  1568. else
  1569. {
  1570. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsMatches->Insert()); STAT_CREATED( Matches );
  1571. }
  1572. hr = S_OK;
  1573. __HCP_FUNC_CLEANUP;
  1574. __HCP_FUNC_EXIT(hr);
  1575. }
  1576. ////////////////////////////////////////////////////////////////////////////////
  1577. ////////////////////////////////////////////////////////////////////////////////
  1578. HRESULT Taxonomy::Updater::MakeRoomForInsert( /*[in ]*/ LPCWSTR szNodeStr ,
  1579. /*[in ]*/ LPCWSTR szMode ,
  1580. /*[in ]*/ LPCWSTR szID ,
  1581. /*[out]*/ long& lPos )
  1582. {
  1583. __HCP_FUNC_ENTRY( "Taxonomy::Updater::MakeRoomForInsert" );
  1584. HRESULT hr;
  1585. QueryResults qr( *this );
  1586. long ID_node;
  1587. lPos = -1;
  1588. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, false ));
  1589. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.MakeRoomForInsert( szMode, szID, ID_node, lPos ));
  1590. hr = S_OK;
  1591. __HCP_FUNC_CLEANUP;
  1592. __HCP_FUNC_EXIT(hr);
  1593. }
  1594. HRESULT Taxonomy::Updater::LocateSubNodes( /*[in] */ long ID_node ,
  1595. /*[in] */ bool fRecurse ,
  1596. /*[in] */ bool fOnlyVisible ,
  1597. /*[out]*/ MatchSet& res )
  1598. {
  1599. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateSubNodes" );
  1600. HRESULT hr;
  1601. __MPC_PARAMCHECK_BEGIN(hr)
  1602. __MPC_PARAMCHECK_NOTNULL(m_cache);
  1603. __MPC_PARAMCHECK_END();
  1604. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->LocateSubNodes( m_ts, ID_node, fRecurse, fOnlyVisible, res ));
  1605. hr = S_OK;
  1606. __HCP_FUNC_CLEANUP;
  1607. __HCP_FUNC_EXIT(hr);
  1608. }
  1609. HRESULT Taxonomy::Updater::LocateNodesFromURL( /*[in ]*/ LPCWSTR szURL ,
  1610. /*[out]*/ MatchSet& res )
  1611. {
  1612. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateNodesFromURL" );
  1613. HRESULT hr;
  1614. __MPC_PARAMCHECK_BEGIN(hr)
  1615. __MPC_PARAMCHECK_NOTNULL(m_cache);
  1616. __MPC_PARAMCHECK_END();
  1617. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->LocateNodesFromURL( m_ts, szURL, res ));
  1618. hr = S_OK;
  1619. __HCP_FUNC_CLEANUP;
  1620. __HCP_FUNC_EXIT(hr);
  1621. }
  1622. HRESULT Taxonomy::Updater::LookupNode( /*[in]*/ LPCWSTR szNodeStr ,
  1623. /*[in]*/ CPCHQueryResultCollection* pColl )
  1624. {
  1625. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LookupNode" );
  1626. HRESULT hr;
  1627. OfflineCache::Entry_Type et = OfflineCache::ET_NODE;
  1628. QueryResults qr( *this );
  1629. long ID_node;
  1630. MPC::wstring strParent;
  1631. __MPC_PARAMCHECK_BEGIN(hr)
  1632. __MPC_PARAMCHECK_NOTNULL(pColl);
  1633. __MPC_PARAMCHECK_END();
  1634. if(m_fUseCache && m_cache && SUCCEEDED(m_cache->RetrieveQuery( m_ts, szNodeStr, et, pColl )))
  1635. {
  1636. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  1637. }
  1638. ////////////////////
  1639. //
  1640. // Find the father of the node.
  1641. //
  1642. if(szNodeStr)
  1643. {
  1644. LPCWSTR szEnd = wcsrchr( szNodeStr, '/' );
  1645. if(szEnd)
  1646. {
  1647. strParent.assign( szNodeStr, szEnd );
  1648. }
  1649. else
  1650. {
  1651. ; // Root
  1652. }
  1653. }
  1654. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, false ));
  1655. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.Append( m_rsTaxonomy, strParent.c_str() ));
  1656. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1657. ////////////////////
  1658. if(m_fUseCache && m_cache && FAILED(m_cache->StoreQuery( m_ts, szNodeStr, et, pColl )))
  1659. {
  1660. ; // Cache failures are not fatal, don't abort.
  1661. }
  1662. hr = S_OK;
  1663. __HCP_FUNC_CLEANUP;
  1664. __HCP_FUNC_EXIT(hr);
  1665. }
  1666. HRESULT Taxonomy::Updater::LookupSubNodes( /*[in]*/ LPCWSTR szNodeStr ,
  1667. /*[in]*/ bool fVisibleOnly ,
  1668. /*[in]*/ CPCHQueryResultCollection* pColl )
  1669. {
  1670. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LookupSubNodes" );
  1671. HRESULT hr;
  1672. OfflineCache::Entry_Type et = fVisibleOnly ? OfflineCache::ET_SUBNODES_VISIBLE : OfflineCache::ET_SUBNODES;
  1673. QueryResults qr( *this );
  1674. long ID_node;
  1675. __MPC_PARAMCHECK_BEGIN(hr)
  1676. __MPC_PARAMCHECK_NOTNULL(pColl);
  1677. __MPC_PARAMCHECK_END();
  1678. if(m_fUseCache && m_cache && SUCCEEDED(m_cache->RetrieveQuery( m_ts, szNodeStr, et, pColl )))
  1679. {
  1680. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  1681. }
  1682. ////////////////////
  1683. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, false ));
  1684. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.LookupNodes( szNodeStr, ID_node, fVisibleOnly ));
  1685. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1686. ////////////////////
  1687. if(m_fUseCache && m_cache && FAILED(m_cache->StoreQuery( m_ts, szNodeStr, et, pColl )))
  1688. {
  1689. ; // Cache failures are not fatal, don't abort.
  1690. }
  1691. hr = S_OK;
  1692. __HCP_FUNC_CLEANUP;
  1693. __HCP_FUNC_EXIT(hr);
  1694. }
  1695. HRESULT Taxonomy::Updater::LookupNodesAndTopics( /*[in]*/ LPCWSTR szNodeStr ,
  1696. /*[in]*/ bool fVisibleOnly ,
  1697. /*[in]*/ CPCHQueryResultCollection* pColl )
  1698. {
  1699. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LookupNodesAndTopics" );
  1700. HRESULT hr;
  1701. OfflineCache::Entry_Type et = fVisibleOnly ? OfflineCache::ET_NODESANDTOPICS_VISIBLE : OfflineCache::ET_NODESANDTOPICS;
  1702. QueryResults qr( *this );
  1703. long ID_node;
  1704. __MPC_PARAMCHECK_BEGIN(hr)
  1705. __MPC_PARAMCHECK_NOTNULL(pColl);
  1706. __MPC_PARAMCHECK_END();
  1707. if(m_fUseCache && m_cache && SUCCEEDED(m_cache->RetrieveQuery( m_ts, szNodeStr, et, pColl )))
  1708. {
  1709. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  1710. }
  1711. ////////////////////
  1712. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, false ));
  1713. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.LookupNodes ( szNodeStr, ID_node, fVisibleOnly ));
  1714. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.LookupTopics( szNodeStr, ID_node, fVisibleOnly ));
  1715. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1716. ////////////////////
  1717. if(m_fUseCache && m_cache && FAILED(m_cache->StoreQuery( m_ts, szNodeStr, et, pColl )))
  1718. {
  1719. ; // Cache failures are not fatal, don't abort.
  1720. }
  1721. hr = S_OK;
  1722. __HCP_FUNC_CLEANUP;
  1723. __HCP_FUNC_EXIT(hr);
  1724. }
  1725. HRESULT Taxonomy::Updater::LookupTopics( /*[in]*/ LPCWSTR szNodeStr ,
  1726. /*[in]*/ bool fVisibleOnly ,
  1727. /*[in]*/ CPCHQueryResultCollection* pColl )
  1728. {
  1729. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LookupTopics" );
  1730. HRESULT hr;
  1731. OfflineCache::Entry_Type et = fVisibleOnly ? OfflineCache::ET_TOPICS_VISIBLE : OfflineCache::ET_TOPICS;
  1732. QueryResults qr( *this );
  1733. long ID_node;
  1734. __MPC_PARAMCHECK_BEGIN(hr)
  1735. __MPC_PARAMCHECK_NOTNULL(pColl);
  1736. __MPC_PARAMCHECK_END();
  1737. if(m_fUseCache && m_cache && SUCCEEDED(m_cache->RetrieveQuery( m_ts, szNodeStr, et, pColl )))
  1738. {
  1739. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  1740. }
  1741. ////////////////////
  1742. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, false ));
  1743. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.LookupTopics( szNodeStr, ID_node, fVisibleOnly ));
  1744. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1745. ////////////////////
  1746. if(m_fUseCache && m_cache && FAILED(m_cache->StoreQuery( m_ts, szNodeStr, et, pColl )))
  1747. {
  1748. ; // Cache failures are not fatal, don't abort.
  1749. }
  1750. hr = S_OK;
  1751. __HCP_FUNC_CLEANUP;
  1752. __HCP_FUNC_EXIT(hr);
  1753. }
  1754. HRESULT Taxonomy::Updater::LocateContext( /*[in]*/ LPCWSTR szURL ,
  1755. /*[in]*/ LPCWSTR szSubSite ,
  1756. /*[in]*/ CPCHQueryResultCollection* pColl )
  1757. {
  1758. __HCP_FUNC_ENTRY( "Taxonomy::Updater::LocateContext" );
  1759. HRESULT hr;
  1760. QueryResults qr( *this );
  1761. Taxonomy::MatchSet setNodes;
  1762. Taxonomy::MatchSet setNodes2;
  1763. Taxonomy::MatchIter it2;
  1764. MPC::wstring strURL;
  1765. MPC::wstring strPath;
  1766. long ID_node;
  1767. bool fFound;
  1768. __MPC_PARAMCHECK_BEGIN(hr)
  1769. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szURL);
  1770. __MPC_PARAMCHECK_NOTNULL(pColl);
  1771. __MPC_PARAMCHECK_END();
  1772. SANITIZEWSTR(szSubSite);
  1773. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics());
  1774. __MPC_EXIT_IF_METHOD_FAILS(hr, CollapseURL( strURL = szURL ));
  1775. //
  1776. // Locate the subsite.
  1777. //
  1778. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szSubSite, false ));
  1779. //
  1780. // Create the set of nodes in the subsite.
  1781. //
  1782. setNodes.insert( ID_node ); // Add the node itself.
  1783. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateSubNodes( ID_node, /*fRecurse*/true, /*fOnlyVisible*/true, setNodes ));
  1784. //
  1785. // Also create the set of nodes matching the URL.
  1786. //
  1787. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateNodesFromURL( strURL.c_str(), setNodes2 ));
  1788. //
  1789. // For all the topics matching the URL, create an entry.
  1790. //
  1791. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Seek_ByURI( strURL.c_str(), &fFound ));
  1792. while(fFound)
  1793. {
  1794. long ID_node = m_rsTopics->m_ID_node;
  1795. if(setNodes.find( ID_node ) != setNodes.end())
  1796. {
  1797. if(m_fUseCache && m_cache)
  1798. {
  1799. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->BuildNodePath( m_ts, ID_node, strPath, /*fParent*/false ));
  1800. }
  1801. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.Append( m_rsTopics, strPath.c_str() ));
  1802. }
  1803. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Move( 0, JET_MoveNext, &fFound ));
  1804. }
  1805. //
  1806. // For all the nodes matching the URL, create an entry.
  1807. //
  1808. for(it2 = setNodes2.begin(); it2 != setNodes2.end(); it2++)
  1809. {
  1810. long ID_node = *it2;
  1811. if(setNodes.find( ID_node ) != setNodes.end())
  1812. {
  1813. if(m_fUseCache && m_cache)
  1814. {
  1815. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->BuildNodePath( m_ts, ID_node, strPath, /*fParent*/false ));
  1816. }
  1817. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.Append( m_rsTopics, strPath.c_str() ));
  1818. }
  1819. }
  1820. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1821. hr = S_OK;
  1822. __HCP_FUNC_CLEANUP;
  1823. __HCP_FUNC_EXIT(hr);
  1824. }
  1825. HRESULT Taxonomy::Updater::KeywordSearch( /*[in]*/ LPCWSTR szQueryStr ,
  1826. /*[in]*/ LPCWSTR szSubSite ,
  1827. /*[in]*/ CPCHQueryResultCollection* pColl ,
  1828. /*[in]*/ MPC::WStringList* lst )
  1829. {
  1830. __HCP_FUNC_ENTRY( "Taxonomy::Updater::KeywordSearch" );
  1831. HRESULT hr;
  1832. Taxonomy::KeywordSearch ks( *this );
  1833. __MPC_PARAMCHECK_BEGIN(hr)
  1834. __MPC_PARAMCHECK_STRING_NOT_EMPTY(szQueryStr);
  1835. __MPC_PARAMCHECK_NOTNULL(pColl);
  1836. __MPC_PARAMCHECK_END();
  1837. __MPC_EXIT_IF_METHOD_FAILS(hr, ks.Execute( szQueryStr, szSubSite, pColl, lst ));
  1838. hr = S_OK;
  1839. __HCP_FUNC_CLEANUP;
  1840. __HCP_FUNC_EXIT(hr);
  1841. }
  1842. HRESULT Taxonomy::Updater::GatherNodes( /*[in]*/ LPCWSTR szNodeStr ,
  1843. /*[in]*/ bool fVisibleOnly ,
  1844. /*[in]*/ CPCHQueryResultCollection* pColl )
  1845. {
  1846. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GatherNodes" );
  1847. HRESULT hr;
  1848. QueryResults qr( *this );
  1849. MatchSet setNodes;
  1850. long ID_node;
  1851. bool fFound;
  1852. __MPC_PARAMCHECK_BEGIN(hr)
  1853. __MPC_PARAMCHECK_NOTNULL(pColl);
  1854. __MPC_PARAMCHECK_END();
  1855. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, /*fLookForFather*/false ));
  1856. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateSubNodes ( ID_node, /*fRecurse */true , fVisibleOnly, setNodes ));
  1857. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Move( 0, JET_MoveFirst, &fFound ));
  1858. while(fFound)
  1859. {
  1860. if(fVisibleOnly == false || m_rsTaxonomy->m_fVisible)
  1861. {
  1862. if(setNodes.find( m_rsTaxonomy->m_ID_node ) != setNodes.end())
  1863. {
  1864. MPC::wstring strPath;
  1865. if(m_fUseCache && m_cache)
  1866. {
  1867. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->BuildNodePath( m_ts, m_rsTaxonomy->m_ID_node, strPath, /*fParent*/true ));
  1868. }
  1869. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.Append( m_rsTaxonomy, strPath.c_str() ));
  1870. }
  1871. }
  1872. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTaxonomy->Move( 0, JET_MoveNext, &fFound ));
  1873. }
  1874. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1875. hr = S_OK;
  1876. __HCP_FUNC_CLEANUP;
  1877. __HCP_FUNC_EXIT(hr);
  1878. }
  1879. HRESULT Taxonomy::Updater::GatherTopics( /*[in]*/ LPCWSTR szNodeStr ,
  1880. /*[in]*/ bool fVisibleOnly ,
  1881. /*[in]*/ CPCHQueryResultCollection* pColl )
  1882. {
  1883. __HCP_FUNC_ENTRY( "Taxonomy::Updater::GatherTopics" );
  1884. HRESULT hr;
  1885. Taxonomy::MatchSet setNodes;
  1886. QueryResults qr( *this );
  1887. long ID_node;
  1888. bool fFound;
  1889. __MPC_PARAMCHECK_BEGIN(hr)
  1890. __MPC_PARAMCHECK_NOTNULL(pColl);
  1891. __MPC_PARAMCHECK_END();
  1892. __MPC_EXIT_IF_METHOD_FAILS(hr, GetTopics());
  1893. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateTaxonomyNode( ID_node, szNodeStr, /*fLookForFather*/false ));
  1894. __MPC_EXIT_IF_METHOD_FAILS(hr, LocateSubNodes ( ID_node, /*fRecurse */true , fVisibleOnly, setNodes ));
  1895. setNodes.insert( ID_node ); // Add the node itself.
  1896. //
  1897. // Create an entry for each topic.
  1898. //
  1899. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Move( 0, JET_MoveFirst, &fFound ));
  1900. while(fFound)
  1901. {
  1902. if(fVisibleOnly == false || m_rsTopics->m_fVisible)
  1903. {
  1904. if(setNodes.find( m_rsTopics->m_ID_node ) != setNodes.end())
  1905. {
  1906. MPC::wstring strPath;
  1907. if(m_fUseCache && m_cache)
  1908. {
  1909. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cache->BuildNodePath( m_ts, m_rsTaxonomy->m_ID_node, strPath, /*fParent*/false ));
  1910. }
  1911. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.Append( m_rsTopics, strPath.c_str() ));
  1912. }
  1913. }
  1914. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rsTopics->Move( 0, JET_MoveNext, &fFound ));
  1915. }
  1916. __MPC_EXIT_IF_METHOD_FAILS(hr, qr.PopulateCollection( pColl ));
  1917. hr = S_OK;
  1918. __HCP_FUNC_CLEANUP;
  1919. __HCP_FUNC_EXIT(hr);
  1920. }