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