Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsOption.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2006-Today Guy Deleeuw
3 *
4 * See the LICENSE file for terms of use.
5 */
6 
7 #include <iostream>
8 
9 #include <Wt/WLogger>
10 
11 #include <Main/WsApplication.h>
12 
13 #include "WsOption.h"
14 #include <gdcore/gdCore.h>
15 
16 WsOption::WsOption(const std::string& attribute, const boost::any value)
17  : m_sAttribute(attribute), m_value(value)
18 { }
19 
20 const std::string& WsOption::attribute() const
21 {
22  return m_sAttribute;
23 }
24 
25 void WsOption::setValue(const boost::any& value)
26 {
27  m_value = value;
28 }
29 
30 const boost::any& WsOption::value() const
31 {
32  return m_value;
33 }
34 
36 { }
37 
38 WsOptions::WsOptions(const std::vector<WsOption>& vOptions)
39  : m_vOptions(vOptions)
40 { }
41 
43 {
44  m_vOptions = src.options();
45 }
46 
47 void WsOptions::setOption(const std::string& attribute, boost::any value)
48 {
49  for (int iV = 0; iV < m_vOptions.size(); ++iV) {
50  if ( m_vOptions[iV].attribute() != attribute ) continue;
51  m_vOptions[iV].setValue(value);
52  return;
53  }
54  m_vOptions.push_back(WsOption(attribute, value));
55 }
56 
57 void WsOptions::setOptions(const std::vector<WsOption>& vOptions)
58 {
59  m_vOptions = vOptions;
60 }
61 
62 const boost::any& WsOptions::option(const std::string& attribute) const
63 {
64  for (int iV = 0; iV < m_vOptions.size(); ++iV)
65  if ( m_vOptions[iV].attribute() == attribute )
66  return m_vOptions[iV].value();
67  return m_noOptions;
68 }
69 
70 const std::vector<WsOption>& WsOptions::options() const
71 {
72  return m_vOptions;
73 }
74 
75 void WsOptions::outOptions(const std::string message)
76 {
77  for (int iV = 0; iV < m_vOptions.size(); ++iV)
78  wApp->log("notice") << message << " WsOptions::outOptions() Attribute : " << m_vOptions[iV].attribute() << ", Value : " << Wt::asString(m_vOptions[iV].value());
79 }
80 
82  : Wt::WObject(Wt::WApplication::instance()), m_bLoaded(false), m_bHideImages(false)
83 { }
84 
85 bool WsModule::processPrefix(const std::string& path)
86 {
87  return false;
88 }
89 
90 std::string WsModule::checkPath(const std::string& currentPath)
91 {
92  return currentPath;
93 }
94 
95 void WsModule::setModuleName(const std::string& moduleName)
96 {
98 }
99 
100 const std::string& WsModule::moduleName() const
101 {
102  return m_moduleName;
103 }
104 
105 void WsModule::setSoName(const std::string& soName)
106 {
107  m_soName = soName;
108 }
109 
110 const std::string& WsModule::soName() const
111 {
112  return m_soName;
113 }
114 
115 void WsModule::setFileName(const std::string& fileName)
116 {
118 }
119 
120 const std::string& WsModule::fileName() const
121 {
122  return m_fileName;
123 }
124 
125 void WsModule::setExtensions(const std::string& extensions)
126 {
127  m_extension = extensions;
128  gd_core_string2vector(m_extensions, m_extension.c_str(), "|");
129 }
130 
131 const std::string& WsModule::extension(const std::string& extension) const
132 {
133  if ( extension.size() > 0 ) {
134  for (int iExt = 0; iExt < m_extensions.size(); ++iExt)
135  if ( m_extensions[iExt] == extension ) return extension;
136  }
137  return m_extension;
138 }
139 
140 void WsModule::setPrefix(const std::string& prefix)
141 {
142  m_prefix = prefix;
143 }
144 
145 const std::string& WsModule::prefix() const
146 {
147  return m_prefix;
148 }
149 
150 std::string WsModule::pathWithoutPrefix(const std::string& path)
151 {
152  std::string str(path);
153  boost::algorithm::replace_first(str, prefix(), "");
154  return str;
155 }
156 
157 std::string WsModule::pathWithPrefix(const std::string& path)
158 {
159  std::string str(path);
160  str.insert(0, prefix());
161  return str;
162 }
163 
164 void WsModule::setHideImages(const bool bHide)
165 {
166  m_bHideImages = bHide;
167 }
168 
170 {
171  return m_bHideImages;
172 }
173 
174 void WsModule::setSysPath(const std::string& sysPath)
175 {
176  m_sysPath = sysPath;
177 }
178 
179 const std::string& WsModule::sysPath() const
180 {
181  return m_sysPath;
182 }
183 
184 void WsModule::setDiffPath(const std::string& diffPath)
185 {
187 }
188 
189 const std::string& WsModule::diffPath() const
190 {
191  return m_diffPath;
192 }
virtual bool processPrefix(const std::string &path)
proccess the prefix, return true if processed
Definition: WsOption.cpp:85
const std::string & diffPath() const
Definition: WsOption.cpp:189
WsOption(const std::string &attribute, const boost::any value)
Definition: WsOption.cpp:16
void setValue(const boost::any &value)
Definition: WsOption.cpp:25
bool hideImages()
Definition: WsOption.cpp:169
const std::string & sysPath() const
Definition: WsOption.cpp:179
std::string pathWithPrefix(const std::string &path)
return the relative path with the prefix : example pathWithPrefix("/Test") return "/SiteMap/Test" ...
Definition: WsOption.cpp:157
std::string m_soName
Definition: WsModule.h:107
std::vector< std::string > m_extensions
Definition: WsModule.h:111
std::string m_diffPath
Definition: WsModule.h:113
const std::string & attribute() const
Definition: WsOption.cpp:20
std::string pathWithoutPrefix(const std::string &path)
return the relative path without the prefix : example pathWithoutPrefix("/SiteMap/Test") return "/Tes...
Definition: WsOption.cpp:150
const std::vector< WsOption > & options() const
Get all options.
Definition: WsOption.cpp:70
void setDiffPath(const std::string &diffPath)
Set/Get the difference between the web server (example Apache /var/www) root path and the wittishare ...
Definition: WsOption.cpp:184
void setFileName(const std::string &fileName)
Set/Get the file name that trigger the module : exemple "Staff List".
Definition: WsOption.cpp:115
void setHideImages(const bool bHide)
Set/Get the flag to specified if the images is hided.
Definition: WsOption.cpp:164
const std::string & soName() const
Definition: WsOption.cpp:110
virtual std::string checkPath(const std::string &currentPath)
Return the currentPath, or another path when some action is required for the currentPath example /New...
Definition: WsOption.cpp:90
std::string m_sysPath
Definition: WsModule.h:112
std::string m_prefix
Definition: WsModule.h:110
std::string m_moduleName
Definition: WsModule.h:106
std::string m_extension
Definition: WsModule.h:109
WsModule()
Definition: WsOption.cpp:81
boost::any m_value
Definition: WsOption.h:20
boost::any m_noOptions
Definition: WsOption.h:45
bool m_bHideImages
Definition: WsModule.h:115
const std::string & moduleName() const
Definition: WsOption.cpp:100
void setOption(const std::string &attribute, boost::any value)
Set an options if previously set, update the value.
Definition: WsOption.cpp:47
void setPrefix(const std::string &prefix)
Set/Get prefix for a virtual path, like "/SiteMap".
Definition: WsOption.cpp:140
void setModuleName(const std::string &name)
Set/Get the module name.
Definition: WsOption.cpp:95
const std::string & prefix() const
Definition: WsOption.cpp:145
const boost::any & option(const std::string &attribute) const
Get an options value.
Definition: WsOption.cpp:62
std::vector< WsOption > m_vOptions
Definition: WsOption.h:44
void outOptions(const std::string message)
Output all options.
Definition: WsOption.cpp:75
const std::string & fileName() const
Definition: WsOption.cpp:120
void setSoName(const std::string &soName)
Set/Get the module so name or path ex. libgd.so or /usr/lib/libgd.so.
Definition: WsOption.cpp:105
void setExtensions(const std::string &extensions)
Set/Get the file extension managed by the module : exemple .ods|.odp.
Definition: WsOption.cpp:125
const std::string & extension(const std::string &extension="") const
Definition: WsOption.cpp:131
std::string m_sAttribute
Definition: WsOption.h:19
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Definition: WsOption.cpp:57
void setSysPath(const std::string &sysPath)
Set/Get the system path (example the selected file /var/www/mysite/about/me.fhtml).
Definition: WsOption.cpp:174
const boost::any & value() const
Definition: WsOption.cpp:30
std::string m_fileName
Definition: WsModule.h:108