00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef Web_Page_Control_Hpp
00010 #define Web_Page_Control_Hpp
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include "ocXML.h"
00057
00058 class base_functor
00059 {
00060 protected:
00061 page & pg;
00062 public:
00063 base_functor(page & ipg):pg(ipg){;}
00064 virtual ~base_functor(){;}
00065
00066 virtual bool operator()( xmlNode & node )
00067 {
00068 return false;
00069 }
00070 virtual string getXmlAttribute( xmlNode & node, string name )
00071 {
00072 string sRet;
00073 node_attr::iterator x = node.attr.find(name);
00074 if( x!=node.attr.end())
00075 {
00076 sRet=x->second;
00077 }
00078 return sRet;
00079 }
00080 };
00081
00082 class top_functor: public base_functor
00083 {
00084 public:
00085 top_functor(page & ipg):base_functor(ipg){;}
00086 virtual ~top_functor(){;}
00087
00088 virtual bool operator()( xmlNode & node )
00089 {
00090 return pg.emitTop();
00091 }
00092 };
00093
00094 class end_functor: public base_functor
00095 {
00096 public:
00097 end_functor(page & ipg):base_functor(ipg){;}
00098 virtual ~end_functor(){;}
00099
00100 virtual bool operator()( xmlNode & node )
00101 {
00102 return pg.emitEnd();
00103 }
00104 };
00105 class menu_functor: public base_functor
00106 {
00107 public:
00108 menu_functor(page & ipg):base_functor(ipg){;}
00109 virtual ~menu_functor(){;}
00110
00111 virtual bool operator()( xmlNode & node )
00112 {
00113 string open, close;
00114 node_attr::iterator x = node.attr.find("open");
00115 if( x!=node.attr.end() )
00116 {
00117 open=x->second;
00118 x = node.attr.find("close");
00119 if( x!=node.attr.end())
00120 {
00121 close=x->second;
00122
00123 cleanHandlerMap( pg.get_menus().handlers );
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 string boundStart, boundEnd;
00147 x = node.attr.find("child_open");
00148 if( x!=node.attr.end()) boundStart = x->second;
00149 x = node.attr.find("child_close");
00150 if( x!=node.attr.end()) boundEnd = x->second;
00151 pg.emitMenu( open, close, boundStart, boundEnd );
00152 }
00153 }
00154 return true;
00155 }
00156 };
00157 class content_functor: public base_functor
00158 {
00159 public:
00160 content_functor(page & ipg):base_functor(ipg){;}
00161 virtual ~content_functor(){;}
00162
00163 virtual bool operator()( xmlNode & node )
00164 {
00165 bool bRet = false;
00166 string items, replace_tag;
00167 node_attr::iterator x = node.attr.find("items");
00168 if( x!=node.attr.end() )
00169 {
00170 items=x->second;
00171 x = node.attr.find("replace-tag");
00172 if( x==node.attr.end())
00173 {
00174 x = node.attr.find("replace_tag");
00175 }
00176 if( x!=node.attr.end())
00177 {
00178 replace_tag=x->second;
00179 bRet = pg.emitContent( items, replace_tag );
00180 }
00181 else
00182 {
00183 cout << "no content replace tag" << endl;
00184 }
00185 }
00186 else
00187 {
00188 cout << "no content items" << endl;
00189 }
00190 return bRet;
00191 }
00192 };
00193
00194 class spacer_functor: public base_functor
00195 {
00196 public:
00197 spacer_functor(page & ipg):base_functor(ipg){;}
00198 virtual ~spacer_functor(){;}
00199
00200 virtual bool operator()( xmlNode & node )
00201 {
00202 bool bRet = false;
00203 string name, replace_tag;
00204 node_attr::iterator x = node.attr.find("name");
00205 if( x!=node.attr.end() )
00206 {
00207 name=x->second;
00208 bRet = pg.emitSpacer( name );
00209 }
00210 else
00211 {
00212 cout << "no spacer name specified" << endl;
00213 }
00214 return bRet;
00215 }
00216 };
00217 typedef map< string, base_functor *> pf_map;
00218
00219 class page_control
00220 {
00221 protected:
00222
00223 page & pg;
00224 string control;
00225 pf_map function_map;
00226 public:
00227 page_control(page & ipg):pg(ipg),control(pg.loaded_control_string())
00228 {
00229 function_map.insert( make_pair( string("top"), new top_functor(pg) ) );
00230 function_map.insert( make_pair( string("end"), new end_functor(pg) ) );
00231 function_map.insert( make_pair( string("menu"), new menu_functor(pg) ) );
00232 function_map.insert( make_pair( string("content"), new content_functor(pg) ) );
00233 function_map.insert( make_pair( string("spacer"), new spacer_functor(pg) ) );
00234 }
00235 ~page_control()
00236 {
00237 pf_map::iterator pos;
00238 for( pos=function_map.begin(); pos!=function_map.end(); ++pos )
00239 {
00240 delete pos->second;
00241 }
00242 }
00243 page_control & addOp ( string name, base_functor * op)
00244 {
00245 function_map.insert( make_pair( name, op ) );
00246 return *this;
00247 }
00248 virtual bool emit( void )
00249 {
00250 bool bRet = false;
00251 xmlParser ctrlParse(control);
00252 ctrlParse.parse();
00253 node_vector & xnodes = ctrlParse.nodeList();
00254 int i;
00255
00256
00257 for(i=1;i<xnodes.size();i++)
00258 {
00259 xmlNode & node = xnodes[i];
00260 bRet = emit( node );
00261 }
00262 return bRet;
00263 }
00264
00265 bool emit( xmlNode & node )
00266 {
00267 string name = node.name;
00268 pf_map::iterator pos = function_map.find(name);
00269 if( pos!=function_map.end() )
00270 {
00271 base_functor & rFunc = * pos->second;
00272 rFunc(node);
00273 }
00274 }
00275 };
00276
00277 #endif