otsdaq  v2_05_02_indev
HttpXmlDocument.h
1 #ifndef ots_HttpXmlDocument_h
2 #define ots_HttpXmlDocument_h
3 
4 #include "otsdaq/XmlUtilities/XmlDocument.h"
5 
6 #include <stdexcept>
7 #include <vector>
8 #include <xercesc/dom/DOMElement.hpp>
9 #include <xercesc/parsers/XercesDOMParser.hpp>
10 
11 namespace ots
12 {
13 // clang-format off
15 {
16  public:
17  HttpXmlDocument (std::string cookieCode = "", std::string displayName = "");
18  HttpXmlDocument (const HttpXmlDocument& doc);
19  HttpXmlDocument& operator= (const HttpXmlDocument& doc);
20  ~HttpXmlDocument (void);
21 
22  void setHeader ( std::string cookieCode = "",
23  std::string displayName = "" );
24  xercesc::DOMElement * getRootDataElement (void ) { return dataElement_; }
25  xercesc::DOMElement * addTextElementToData (const std::string & field,
26  const std::string & value = "" );
27  xercesc::DOMElement * addBinaryStringToData (const std::string & field,
28  const std::string & binary );
29  void copyDataChildren ( HttpXmlDocument & document );
30  std::string getMatchingValue (const std::string & field,
31  const unsigned int occurance = 0 );
32  void getAllMatchingValues (const std::string & field,
33  std::vector<std::string> & retVec);
34  xercesc::DOMElement * getMatchingElement (const std::string & field,
35  const unsigned int occurance = 0 );
36  xercesc::DOMElement * getMatchingElementInSubtree ( xercesc::DOMElement * currEl,
37  const std::string & field,
38  const unsigned int occurance = 0 );
39  void getAllMatchingElements (const std::string & field,
40  std::vector<xercesc::DOMElement*> & retVec );
41  void outputXmlDocument ( std::ostringstream * out,
42  bool dispStdOut = false,
43  bool allowWhiteSpace = false);
44  bool loadXmlDocument (const std::string & filePath );
45  unsigned int getChildrenCount ( xercesc::DOMElement * parent = 0 );
46  void removeDataElement ( unsigned int dataChildIndex = 0 ); // default to first child
47 
48  private:
49  void recursiveAddElementToParent ( xercesc::DOMElement * child ,
50  xercesc::DOMElement * parent ,
51  bool html = false );
52  void recursiveFindAllElements ( xercesc::DOMElement * currEl ,
53  const std::string & field ,
54  std::vector<std::string> * retVec );
55  void recursiveFindAllElements ( xercesc::DOMElement * currEl ,
56  const std::string & field ,
57  std::vector<xercesc::DOMElement*> * retVec );
58  void recursiveOutputXmlDocument ( xercesc::DOMElement * currEl ,
59  std::ostringstream * out ,
60  bool dispStdOut = false ,
61  std::string tabStr = "" ,
62  bool allowWhiteSpace = false);
63  void recursiveFixTextFields ( xercesc::DOMElement * currEl );
64  std::string recursiveFindElementValue ( xercesc::DOMElement * currEl ,
65  const std::string & field ,
66  const unsigned int occurance ,
67  unsigned int & count );
68  xercesc::DOMElement * recursiveFindElement ( xercesc::DOMElement * currEl ,
69  const std::string & field ,
70  const unsigned int occurance ,
71  unsigned int & count );
72 
73  xercesc::DOMElement * headerElement_ ;
74  xercesc::DOMElement * dataElement_ ;
75 
76  const std::string headerTagName_ ;
77  const std::string dataTagName_ ;
78  const std::string cookieCodeTagName_ ;
79  const std::string displayNameTagName_;
80 };
81 // clang-format on
82 } // namespace ots
83 
84 #endif // ots_HttpXmlDocument_h