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.

225 lines
8.0 KiB

  1. //
  2. // MODULE: HTMLFrag.h
  3. //
  4. // PURPOSE: declaration of the CHTMLFragments and CHTMLFragmentsTS classes.
  5. // This is how CInfer packages up fragments of HTML to be rendered in accord
  6. // with a template.
  7. //
  8. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  9. //
  10. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  11. //
  12. // AUTHOR: Joe Mabel
  13. //
  14. // ORIGINAL DATE: 8-27-1998
  15. //
  16. // NOTES:
  17. //
  18. // Version Date By Comments
  19. //--------------------------------------------------------------------
  20. // V3.0 8-27-98 JM Original
  21. //
  22. //////////////////////////////////////////////////////////////////////
  23. #ifndef __HTMLFRAG_H_
  24. #define __HTMLFRAG_H_
  25. #include <vector>
  26. using namespace std;
  27. // JSM V3.2
  28. #include <map>
  29. using namespace std;
  30. #include "apgtsstr.h"
  31. // Predefined variable names
  32. // They belong to DISPLAY command
  33. #define VAR_PROBLEM_ASK _T("ProblemAsk")
  34. #define VAR_RECOMMENDATIONS _T("Recommendations")
  35. #define VAR_STATES _T("States")
  36. #define VAR_QUESTIONS _T("Questions")
  37. #define VAR_SUCCESS _T("Success")
  38. #define VAR_STARTFORM _T("StartForm")
  39. // V3.2 Additions.
  40. namespace
  41. {
  42. const CString kstrCond_NumericCompare= _T("NumericCompare");
  43. }
  44. struct FragmentID
  45. {
  46. FragmentID() : Index(-1) {};
  47. FragmentID(const CString & v, int i) : VarName(v), Index(i) {};
  48. CString VarName; // must be a known, predefined variable name
  49. int Index; // index into array associated with this variable name
  50. // OR -1 for not relevant
  51. bool operator < (const FragmentID & fid) const
  52. { return (VarName < fid.VarName || Index < fid.Index); };
  53. bool operator == (const FragmentID & fid) const
  54. { return (VarName == fid.VarName || Index == fid.Index); };
  55. };
  56. class CHTMLValue
  57. {
  58. CString m_strValName;
  59. CString m_strValValue;
  60. public:
  61. CHTMLValue() {}
  62. CHTMLValue(const CString& name) : m_strValName(name) {}
  63. CHTMLValue(const CString& name, const CString& value) : m_strValName(name), m_strValValue(value) {}
  64. virtual ~CHTMLValue() {}
  65. public:
  66. bool operator == (const CHTMLValue& sib);
  67. void SetName(const CString& name) {m_strValName = name;}
  68. CString GetName() {return m_strValName;}
  69. bool SetValue(const CString& value);
  70. bool GetNumeric(long&);
  71. bool GetString(CString&);
  72. bool GetBoolean(bool&);
  73. bool IsValid() {return IsNumeric() || IsString() || IsBoolean();}
  74. bool IsNumeric();
  75. bool IsString();
  76. bool IsBoolean();
  77. };
  78. // vectors definition
  79. typedef vector<FragmentID> FragmentIDVector;
  80. typedef vector<CHTMLValue> HTMLValueVector;
  81. // Template should see only a const object of this class
  82. class CHTMLFragments
  83. {
  84. HTMLValueVector m_HTMLValueVector;
  85. public:
  86. enum FragCommand { eNotOfInterest, eResource };
  87. public:
  88. CHTMLFragments() {};
  89. virtual ~CHTMLFragments()=0 {};
  90. // pure virtuals
  91. virtual int GetCount(const FragmentIDVector & fidvec) const =0;
  92. virtual CString GetText(const FragmentIDVector & fidvec, const FragCommand fragCmd= eNotOfInterest ) =0;
  93. virtual bool IsValidSeqOfVars(const FragmentIDVector & arrParents, const FragmentIDVector & arrChildren) const =0 ;
  94. // value handling
  95. virtual bool SetValue(const CString& assignment_expression);
  96. virtual CHTMLValue* GetValue(const CString& value_name);
  97. // JSM V3.2 needed by mechanism which replaces <!GTS property "netprop">
  98. // w/ the corresponding BNTS network property
  99. virtual CString GetNetProp(const CString & strNetPropName) = 0;
  100. // V3.2 enhancement for the Start Over button.
  101. virtual void SetStartOverLink( const CString & str ) {};
  102. virtual CString GetStartOverLink() {return _T("");}
  103. };
  104. // Implementation specific to the predefined variables above
  105. class CHTMLFragmentsTS : public CHTMLFragments
  106. {
  107. #ifdef __DEBUG_CUSTOM
  108. protected:
  109. #else
  110. private:
  111. #endif
  112. const bool m_bIncludesHistoryTable;
  113. const bool m_bIncludesHiddenHistory;
  114. CString m_strStartForm; // The fixed, initial part of the HTML form on every
  115. // page that has a form. (The FORM tag + the topic
  116. // name in a hidden field of that form)
  117. CString m_strProblem; // problem name (for history table)
  118. vector<CString> m_vstrVisitedNodes; // name of each visited node (for history table)
  119. #pragma warning(disable:4786)
  120. vector< vector<CString> > m_vvstrStatesOfVisitedNodes; // text corresponding
  121. // to each state of each visited node (for history table).
  122. // This includes radio button.
  123. CString m_strCurrentNode; // full text for current node, sometimes includes
  124. // hidden history
  125. CString m_strCurrentNodeSimple; // text for current node, always excludes hidden history
  126. CString m_strHiddenHistory; // If there is to be no history table, this encodes
  127. // the history in hidden fields (for an HTML form)
  128. CString m_strNil;
  129. CString m_strYes; // constant "Yes" for m_bSuccess == true
  130. bool m_bSuccess; // true only is current node is BYE (success) node.
  131. const CString m_strScriptPath; // path to the resource directory, used for server side logic.
  132. CString m_strStartOverLink; // V3.2 - for Online TS, contains the text for the start over
  133. // link (which is disguised as a button). Unlike other
  134. // properties, this is set by APGTSContext and gotten
  135. // by CInfer, not set by CInfer and gotten by CAPGTSHTIReader
  136. // V3.2 map BNTS network property name to net property (value)
  137. // allows us to convert <!GTS property "netprop"> when reading the HTI file
  138. map<CString,CString> m_mapstrNetProps;
  139. private:
  140. CHTMLFragmentsTS(); // Do not instantiate
  141. public:
  142. CHTMLFragmentsTS( const CString & strScriptPath, bool bIncludesHistoryTable );
  143. ~CHTMLFragmentsTS();
  144. // inherited methods
  145. int GetCount(const FragmentIDVector & fidvec) const;
  146. CString GetText( const FragmentIDVector & fidvec, const FragCommand fragCmd= eNotOfInterest );
  147. virtual bool IsValidSeqOfVars(const FragmentIDVector & arrParents, const FragmentIDVector & arrChildren) const;
  148. void SetStartOverLink( const CString & str ); // V3.2 enhancement for the Start Over button.
  149. CString GetStartOverLink(); // V3.2 enhancement for the Start Over button.
  150. // methods specific to this class
  151. void SetStartForm(const CString & str);
  152. void SetProblemText(const CString & str);
  153. void SetCurrentNodeText(const CString & str);
  154. void SetHiddenHistoryText(const CString & str);
  155. void SetSuccessBool(bool bSuccess);
  156. CString GetCurrentNodeText();
  157. int PushBackVisitedNodeText(const CString & str);
  158. int PushBackStateText(UINT iVisitedNode, const CString & str);
  159. bool IncludesHistoryTable() const;
  160. bool IncludesHiddenHistory() const;
  161. // Functions which parse and evaluate numeric and string conditionals.
  162. bool NumericConditionEvaluatesToTrue( const CString & str );
  163. bool StringConditionEvaluatesToTrue( const CString & str );
  164. CString RemoveOuterParenthesis( const CString & str );
  165. bool RetNumericOperands( const CString & str, const CString & strOperator,
  166. long &lLeftOperand, long &lRightOperand );
  167. bool RetStringOperands( const CString & str, const CString & strOperator,
  168. CString & strLeftOperand, CString & strRightOperand );
  169. int CleanStringOperand( CString& strOperand );
  170. // JSM V3.2 these functions used by the mechanism which replaces
  171. // <!GTS property "netprop"> w/ the corresponding BNTS network property
  172. //
  173. // CAPGTSHTIReader finds the names of the network properties and passes
  174. // them in via AddNetPropName
  175. // CInfer later gets the network property names, calls the BNTS
  176. // to find out the network property values, and passes the values to HTMLFragmentsTS
  177. // Later, CAPGTSHTIReader queries HTMLFragmentsTS for network property values
  178. // during the parsing process.
  179. //
  180. // add the name of a network property to the internal list
  181. void AddNetPropName(const CString & strNetPropName);
  182. // returns the network property, requested by name. (returns null if not avail.)
  183. CString GetNetProp(const CString & strNetPropName);
  184. // set the value of the network property identified by strNetPropName
  185. BOOL SetNetProp(CString strNetPropName, CString strNetProp);
  186. // iterate (by name) thru the list of net props
  187. BOOL IterateNetProp(CString & strNameIterator);
  188. // end JSM V3.2
  189. private:
  190. void RebuildCurrentNodeText();
  191. };
  192. #endif // __HTMLFRAG_H_