Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsLatestNews.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsLatestNews.cpp
4  *
5  * Description:
6  *
7  * Created: 04/18/2012 12:34:02 PM
8  *
9  * Author: Benoit Daccache, ben.daccache@gmail.com
10  *
11  */
12 
13 #include "WsLatestNews.h"
14 
15 
17  WsTreeTraversal(mt)
18 {
19 }
20 
21 vector<NodePtr> WsLatestNews::getLatestNews(int nb)
22 {
23  m_maxSize = nb;
24  start();
25  return m_vect;
26 }
27 
29 {
30  return ErrorCode::Success;
31 }
32 
34 {
35  return ErrorCode::Success;
36 }
37 
39 {
40  WsFileNode* fn = dynamic_cast<WsFileNode*>(n.get());
41  if ( fn->getProperties().get()->get("global", "in_view", "true") == "false" ) return ErrorCode::Success;
42  if ( !(
43  fn->getPath().extension().string() == ".fhtml" ||
44  fn->getPath().extension().string() == ".pdf" ||
45  fn->getPath().extension().string() == ".rpg" ||
46  fn->getPath().extension().string() == ".zip"
47  ) )
48  return ErrorCode::Success;
49  boost::filesystem::path wsRes = fn->getPath();
50  bool bRes = false;
51  while (wsRes.string() != "/") {
52  wsRes = wsRes.parent_path();
53  if ( wsRes.filename().string() == "ws.res" ) {
54  bRes = true;
55  break;
56  }
57  if ( wsRes.filename().string() == "ws" ) {
58  bRes = true;
59  break;
60  }
61  continue;
62  }
63  if ( bRes ) return ErrorCode::Success;
64  /* Vect empty, add the element */
65  if (m_vect.size() == 0) {
66  m_vect.push_back(n);
67  return ErrorCode::Success;
68  }
69  /* File is a latest news, add is at the right position */
70  else {
71  vector<NodePtr>::iterator it;
72  for (it = m_vect.begin(); it != m_vect.end(); ++it) {
73  WsFileNode* temp = dynamic_cast<WsFileNode*>((*it).get());
74  if (fn->getPublishDate() > temp->getPublishDate()) {
75  m_vect.insert(it, n);
76  if (m_vect.size() > m_maxSize)
77  m_vect.pop_back();
78  return ErrorCode::Success;
79  }
80  }
81  if (m_vect.size() < m_maxSize)
82  m_vect.push_back(n);
83  return ErrorCode::Success;
84  }
85 }
86 
boost::shared_ptr< WsAbstractNode > NodePtr
vector< NodePtr > getLatestNews(int nb)
int endTraverseDir(NodePtr n)
Called when a directory has been completely traversed. ie all subnodes(recursively all sub nodes of s...
Reprensents a File on disk.
Definition: WsFileNode.h:23
vector< NodePtr > m_vect
Definition: WsLatestNews.h:31
Used to traverse the tree.
NodePropertiesPtr getProperties()
get the properties of the node If the properties are not set (no conf found, or node retrieved from s...
Definition: WsNode.cpp:175
int start()
start traversing the Tree.
const path & getPath()
returns the relative path of the node
Definition: WsNode.cpp:94
int traverseFile(NodePtr n)
Called when traversing a fileNode.
const int Success
WsLatestNews(NodePtr mt)
int beginTraverseDir(NodePtr n)
Called when a directory is being traversed.
const string getPublishDate()
returns the publish date of the file
Definition: WsFileNode.cpp:57