Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsTreeSerializer.cpp
Go to the documentation of this file.
1 
14 #include "WsTreeSerializer.h"
15 
16 using namespace Json;
17 
18 
20  m_rootNode(tree->getRoot()),
21  m_rootPath(tree->getRootPath()),
22  m_stamp(tree->getStamp())
23 {
24 }
25 
27 {
28  /* Avoid Segfault if user has access to nothing */
29  if (m_rootNode.get() == 0)
30  return ErrorCode::Success;
31  /* Serialize the rootPath */
32  m_root["root_path"] = m_rootPath.string();
33  m_root["stamp"] = m_stamp;
34  /* Serialize all the children of the root */
35  return addSub(m_root["nodes"], m_rootNode);
36 }
37 
39 {
40  if (n.get()->isDirectory()) {
41  /* Add type and properties */
42  v[n.get()->getFullPath().string()]["type"] = "DIRECTORY";
43  v[n.get()->getFullPath().string()]["properties"] = n.get()->getProperties().get()->getRoot();
44  v[n.get()->getFullPath().string()]["modifdate"] = (double)n.get()->getModifyDate();
45  v[n.get()->getFullPath().string()]["creatdate"] = (double)n.get()->getCreateDate();
46  /* Add the Files */
47  vector<NodePtr> childrenFiles = n.get()->getFiles();
48  /* Iterate on children files and Serialize each node */
49  for (int i = 0; i < childrenFiles.size(); ++i) {
50  /* Set the type of the node */
51  v[n.get()->getFullPath().string()]["children"][childrenFiles[i].get()->getFullPath().string()]["type"] = "FILE";
52  v[n.get()->getFullPath().string()]["children"][childrenFiles[i].get()->getFullPath().string()]["properties"] = childrenFiles[i].get()->getProperties().get()->getRoot();
53  v[n.get()->getFullPath().string()]["children"][childrenFiles[i].get()->getFullPath().string()]["size"] = (double)childrenFiles[i].get()->getSize();
54  v[n.get()->getFullPath().string()]["children"][childrenFiles[i].get()->getFullPath().string()]["modifdate"] = (double)childrenFiles[i].get()->getModifyDate();
55  v[n.get()->getFullPath().string()]["children"][childrenFiles[i].get()->getFullPath().string()]["creatdate"] = (double)childrenFiles[i].get()->getCreateDate();
56  }
57  /* Add the dirs */
58  vector<NodePtr> childrenDir = n.get()->getDirectories();
59  for (int i = 0; i < childrenDir.size(); ++i) {
60  /* Recursivly add the children of each directory */
61  addSub(v[n.get()->getFullPath().string()]["children"], childrenDir[i]);
62  }
63  } else {
64  LOG(ERROR) << "WsTreeTraversal::addSub() : Node is a file ";
65  return ErrorCode::Failure;
66  }
67  return ErrorCode::Success;
68 }
69 
71 {
72  return m_root.toStyledString();
73 }
boost::shared_ptr< WsAbstractNode > NodePtr
const int Failure
Reprensents an access tree.
Definition: WsAccessTree.h:24
Json::Value m_root
WsTreeSerializer(WsAccessTree *tree)
Constructor.
#define LOG
Definition: WsLogger.h:22
int addSub(Json::Value &v, NodePtr n)
adds a SubNode to the tree corresponding to the Json entry
int serialize()
serialize the given data structur
Serialize the menuTree to send it over network.
std::string m_stamp
const std::string Value
Definition: WsRequestType.h:39
const std::string getSerializedForm()
returns the Json text representing the given structure
const int Success
#define ERROR
Definition: WsLogger.h:42
boost::filesystem::path m_rootPath