00001 /* 00002 00003 The cgiTemplates class 00004 ---------------------- 00005 The rationale behind this class 00006 is the separation of content 00007 and style from function. 00008 00009 Content and Style stay in a standard html (or XML) 00010 page. After a page is written using a WYSIWYG 00011 editor (or whatever) it is marked up with SGML 00012 comments to mark the begining and ending of paragraphs. 00013 00014 Comment Format: 00015 ======================================== 00016 00017 paragraph beginning: <!--@label--> 00018 00019 paragraph ending: <!--/@label--> 00020 00021 ======================================== 00022 The label can be any alpha-numeric 00023 sequence of characters 00024 00025 Function comes from the cgi program. 00026 The cgi program calls this class to load and parse 00027 the html/xml into paragraphs. 00028 00029 The program can then intersperse dynamically 00030 generated content with the static paragraphs. 00031 00032 User defined argument markers can be placed in the 00033 paragraphs so as to be replaced by program variables. 00034 Replacement is most easily accomplished by using the 00035 ocString methods replace and replaceAll. For type conversion 00036 to string there is a function template called ocAppend( string, var ). 00037 ocAppend and ocString are included in the "ocString.h" file 00038 00039 Having worked in some of the scripted environments, I believe this 00040 method is superior in terms of performance, flexibility and reliability. 00041 00042 All code is compiled, the parsing is fast, and is done against 00043 a well defined set of tokens. 00044 00045 The user can completely change the visual interface 00046 without effecting the function (so long as the SGML comments and 00047 argument markers are preserved.) 00048 00049 All code checks are done at compile time rather 00050 that run time - this means the user is less likely to be exposed 00051 to some un-anticipated error. 00052 00053 Copyright 2002 - Open Core Class Library 00054 Author David McCombs 00055 00056 */ 00057 #ifndef CGI_PARAGRAPHS_H 00058 #define CGI_PARAGRAPHS_H 00059 00060 #include <map> 00061 #include <string> 00062 #include <fstream> 00063 #include <iomanip> 00064 #include "ocString.h" 00065 00066 typedef map < string, string > paragraphMap; 00067 00068 class cgiTemplates 00069 { 00070 private: 00071 ocString unparsed; 00072 paragraphMap parsed; 00073 bool comments; 00074 bool parse ( void ); 00075 00076 public: 00077 // default and only constructor 00078 cgiTemplates(); 00079 00080 // non virtual destructor 00081 ~cgiTemplates(); 00082 00083 // load and parse the file */ 00084 bool load ( const char * filename ); 00085 cgiTemplates & operator = ( const cgiTemplates & in ); 00086 00087 // return the paragraph labeled by 'key 00088 string & getParagraph( const string & key ); 00089 string & getParagraph( const char * key ); 00090 00091 // to have the tag name appear as an SGML comment around inserted paragraphs... 00092 void commentsOn(void); 00093 void commentsOff(void); // the default 00094 00095 // return the content of the html file unparsed 00096 string & getUnparsedHtml( void ); 00097 00098 // return the whole array of parsed paragraphs 00099 inline paragraphMap & getParagraphs( void ) { return parsed; } 00100 }; 00101 00102 #endif
1.2.18