otsdaq  v2_04_01
CodeEditor.h
1 #ifndef _ots_CodeEditor_h_
2 #define _ots_CodeEditor_h_
3 
4 #include "otsdaq-core/Macros/CoutMacros.h"
5 #include "otsdaq-core/Macros/StringMacros.h"
6 #include "otsdaq-core/MessageFacility/MessageFacility.h"
7 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
8 #include "xgi/Method.h" //for cgicc::Cgicc
9 
10 #include <iostream>
11 #include <string>
12 #include <unordered_map>
13 #include <vector>
14 
15 namespace ots
16 {
17 class HttpXmlDocument;
18 
19 // CodeEditor
20 // This class provides the functionality for editing, saving, and building code
22 {
23  public:
24  CodeEditor();
25 
26  // request are handled here
27  void xmlRequest(const std::string& option,
28  cgicc::Cgicc& cgiIn,
29  HttpXmlDocument* xmlOut,
30  const std::string& username);
31 
32  private:
33  void getDirectoryContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
34  void getPathContent(const std::string& basepath,
35  const std::string& path,
36  HttpXmlDocument* xmlOut);
37  void getFileContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
38  void saveFileContent(cgicc::Cgicc& cgiIn,
39  HttpXmlDocument* xmlOut,
40  const std::string& username);
41  void build(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut, const std::string& username);
42 
43  std::string safePathString(const std::string& path);
44  std::string safeExtensionString(const std::string& extension);
45 
46  public:
47  static const std::string SPECIAL_TYPE_FEInterface, SPECIAL_TYPE_DataProcessor,
48  SPECIAL_TYPE_Table, SPECIAL_TYPE_ControlsInterface, SPECIAL_TYPE_Tools,
49  SPECIAL_TYPE_UserData, SPECIAL_TYPE_OutputData;
50 
51  static const std::string SOURCE_BASE_PATH, USER_DATA_PATH, OTSDAQ_DATA_PATH;
52 
53  static std::map<std::string /*special type*/,
54  std::set<std::string> /*special file paths*/>
55  getSpecialsMap(void);
56 
57  static void readFile(const std::string& basepath,
58  const std::string& path,
59  std::string& contents);
60  static void writeFile(const std::string& basepath,
61  const std::string& path,
62  const std::string& contents,
63  const std::string& username,
64  const unsigned long long& insertPos = -1,
65  const std::string& insertString = "");
66 
67  const std::set<std::string> ALLOWED_FILE_EXTENSIONS_;
68 };
69 
70 } // namespace ots
71 
72 #endif