Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsSearchRSS.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsSearchRSS.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 "WsSearchRSS.h"
14 
15 
17  WsTreeTraversal(mt)
18 {
19 }
20 
21 vector<NodePtr> WsSearchRSS::getRSS(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  // TODO : put this next line as options
43  std::string curPath = fn->getPath().string();
44  bool bOk = false;
45  if ( curPath.compare(0, 17, "/Issues&Positions") == 0 ) bOk = true;
46  if ( curPath.compare(0, 26, "/News&Media/Press releases") == 0 ) bOk = true;
47  if ( !bOk ) return ErrorCode::Success;
48  if ( !(
49  fn->getPath().extension().string() == ".fhtml" ||
50  fn->getPath().extension().string() == ".pdf" ||
51  fn->getPath().extension().string() == ".rpg" ||
52  fn->getPath().extension().string() == ".zip"
53  ) )
54  return ErrorCode::Success;
55  /* Vect empty, add the element */
56  if (m_vect.size() == 0) {
57  m_vect.push_back(n);
58  return ErrorCode::Success;
59  }
60  /* File is a latest news, add is at the right position */
61  else {
62  vector<NodePtr>::iterator it;
63  for (it = m_vect.begin(); it != m_vect.end(); ++it) {
64  if (fn->getPublishDate() > dynamic_cast<WsFileNode*>((*it).get())->getPublishDate()) {
65  m_vect.insert(it, n);
66  if (m_vect.size() > m_maxSize)
67  m_vect.pop_back();
68  return ErrorCode::Success;
69  }
70  }
71  if (m_vect.size() < m_maxSize)
72  m_vect.push_back(n);
73  return ErrorCode::Success;
74  }
75 }
76 
WsSearchRSS(NodePtr mt)
Definition: WsSearchRSS.cpp:16
int endTraverseDir(NodePtr n)
Called when a directory has been completely traversed. ie all subnodes(recursively all sub nodes of s...
Definition: WsSearchRSS.cpp:33
boost::shared_ptr< WsAbstractNode > NodePtr
Reprensents a File on disk.
Definition: WsFileNode.h:23
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.
int beginTraverseDir(NodePtr n)
Called when a directory is being traversed.
Definition: WsSearchRSS.cpp:28
const path & getPath()
returns the relative path of the node
Definition: WsNode.cpp:94
vector< NodePtr > getRSS(int nb)
Definition: WsSearchRSS.cpp:21
int traverseFile(NodePtr n)
Called when traversing a fileNode.
Definition: WsSearchRSS.cpp:38
vector< NodePtr > m_vect
Definition: WsSearchRSS.h:31
const int Success
const string getPublishDate()
returns the publish date of the file
Definition: WsFileNode.cpp:57