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