Hauptseite | Liste aller Namensbereiche | Klassenhierarchie | Übersicht | Auflistung der Dateien | Elemente eines Namensbereiches | Datenstruktur-Elemente | Datei-Elemente

psfaCGI.cpp Dateireferenz

#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <sstream>
#include <cgicc/Cgicc.h>
#include "psfa/DbReadDriverMySql.hpp"
#include "psfa/Config.hpp"
#include "psfa/Helper.hpp"
#include "Demo-Template.hpp"

Include-Abhängigkeitsdiagramm für psfaCGI.cpp:

Include dependency graph

gehe zum Quellcode dieser Datei

Funktionen

void setUpPsfa ()
void getOptions (psfa::sVec &vec, std::string &options, std::string def)
void printVec (psfa::sVec &vec, std::ostringstream &stream)
int main (int, char **)


Dokumentation der Funktionen

void getOptions psfa::sVec vec,
std::string &  options,
std::string  def
 

Definiert in Zeile 71 der Datei psfaCGI.cpp.

Benutzt psfa::sVec.

Wird benutzt von main().

00072 {
00073   std::ostringstream opts;
00074   
00075   opts << "<option value=\""
00076        << def
00077        << "\">"
00078        << def
00079        << "</option>\n";
00080   psfa::sVec::iterator i;
00081   psfa::sVec::iterator iEnd = vec.end();
00082   for( i = vec.begin(); i != iEnd; ++i ) {
00083     opts << "<option value=\""
00084     << *i
00085     << "\">"
00086     << *i
00087     << "</option>\n";
00088   }
00089   options = opts.str();
00090   return;
00091 }

int main int  ,
char ** 
 

Definiert in Zeile 112 der Datei psfaCGI.cpp.

Benutzt getOptions(), psfa::IndexData_SP, printVec(), searchForm, setUpPsfa(), psfahelper::splitString() und psfa::sVec.

00113 {
00114   using std::cout;
00115   using std::endl;
00116   using std::string;
00117   using std::ostringstream;
00118   using std::vector;
00119   using psfa::DbReadDriver;
00120   using psfa::DbReadDriverMySql;
00121   using psfa::SearchData;
00122   using psfa::sVec;
00123   using psfa::Config;
00124   using psfa::IndexData_SP;
00125   using psfahelper::pathIsReadable;
00126   using psfahelper::splitString;
00127   using cgicc::Cgicc;
00128   using cgicc::CgiEnvironment;
00129   using cgicc::FormEntry;
00130   using cgicc::form_iterator;
00131 
00132   setUpPsfa();
00133   DbReadDriver *read = new DbReadDriverMySql;
00134     
00135   sVec pools;
00136   sVec result;
00137   string options("");
00138   string tmp;
00139   string::size_type tplPos;
00140 
00141   read->getPools( pools );
00142   psfa::sVec::iterator p;
00143   psfa::sVec::iterator pEnd = pools.end();
00144   for( p = pools.begin(); p != pEnd; ++p ) {
00145     read->getSearchTags( *p, result );
00146     getOptions( result, options, "Such-Tags" );
00147     tmp = "PSFA--option_" + *p + "_search";
00148     tplPos = searchForm.find( tmp );
00149     if( tplPos < string::npos ) {
00150       searchForm.replace( tplPos, tmp.size(), options );
00151     }
00152     options = "";
00153     result.clear();
00154 
00155     read->getKontextTags( *p, result );
00156     getOptions( result, options, "Kontext-Tags" );
00157     tmp = "PSFA--option_" + *p + "_kontext";
00158     tplPos = searchForm.find( tmp );
00159     if( tplPos < string::npos ) {
00160       searchForm.replace( tplPos, tmp.size(), options );
00161     }
00162     options = "";
00163     result.clear();
00164 
00165     read->getUnits( *p, result );
00166     getOptions( result, options, "Einheiten" );
00167     tmp = "PSFA--option_" + *p + "_unit";
00168     tplPos = searchForm.find( tmp );
00169     if( tplPos < string::npos ) {
00170       searchForm.replace( tplPos, tmp.size(), options );
00171     }
00172     options = "";
00173     result.clear();
00174 
00175     read->getFiles( *p, result );
00176     getOptions( result, options, "Dateien" );
00177     tmp = "PSFA--option_" + *p + "_file";
00178     tplPos = searchForm.find( tmp );
00179     if( tplPos < string::npos ) {
00180       searchForm.replace( tplPos, tmp.size(), options );
00181     }
00182     options = "";
00183     result.clear();
00184 
00185     read->getUniqueContent( *p, result );
00186     getOptions( result, options, "Inhalte" );
00187     tmp = "PSFA--option_" + *p + "_content";
00188     tplPos = searchForm.find( tmp );
00189     if( tplPos < string::npos ) {
00190       searchForm.replace( tplPos, tmp.size(), options );
00191     }
00192     options = "";
00193     result.clear();
00194   }
00195 
00196   string pool("");
00197   string action("");
00198 
00199   Cgicc cgi;
00200   const vector< FormEntry > vFormEntries = cgi.getElements();
00201   vector< FormEntry >::const_iterator f;
00202   vector< FormEntry >::const_iterator fEnd = vFormEntries.end();
00203   for ( f = vFormEntries.begin(); f != fEnd; ++f ) {
00204     sVec formSubmit;
00205     splitString( f->getName(), formSubmit, "_" );
00206     if( formSubmit[0] == "submit" ) {
00207       pool = formSubmit[1];
00208       action = formSubmit[2];
00209     }
00210   }
00211 
00212   int resCount = 0;
00213   ostringstream resCountStream;
00214   ostringstream resStream;
00215   
00216   if( action == "showPools" ) {
00217     printVec( pools, resStream );
00218     resCount = pools.size();
00219   }
00220   else if( action == "tag" ) {
00221     read->getSearchTags( pool, result );
00222     printVec( result, resStream );
00223     resCount = result.size();
00224   }
00225   else if( action == "kontext" ) {
00226     read->getKontextTags( pool, result );
00227     printVec( result, resStream );
00228     resCount = result.size();
00229   }
00230   else if( action == "unit" ) {
00231     read->getUnits( pool, result );
00232     printVec( result, resStream );
00233     resCount = result.size();
00234   }
00235   else if( action == "file" ) {
00236     read->getFiles( pool, result );
00237     printVec( result, resStream );
00238     resCount = result.size();
00239   }
00240   else if( action == "content" ) {
00241     read->getUniqueContent( pool, result );
00242     printVec( result, resStream );
00243     resCount = result.size();
00244   }
00245   else if( action == "entry" ) {
00246     SearchData search;
00247     tmp = "check_" + pool + "_att";
00248     if( cgi.queryCheckbox( tmp ) ) {
00249       search.incAtts = true;
00250     }
00251     tmp = "check_" + pool + "_pos";
00252     if( cgi.queryCheckbox( tmp ) ) {
00253       search.incPosData = true;
00254     }
00255 
00256     tmp = "select_" + pool + "_search";
00257     form_iterator fV = cgi[tmp];
00258     if( fV->getValue() != "Such-Tags" ) {
00259       search.searchTag = fV->getValue();
00260     }
00261     tmp = "select_" + pool + "_kontext";
00262     fV = cgi.getElement(tmp);
00263     if( fV->getValue() != "Kontext-Tags" ) {
00264       search.kontextTag = fV->getValue();
00265     }
00266     tmp = "select_" + pool + "_unit";
00267     fV = cgi.getElement(tmp);
00268     if( fV->getValue() != "Einheiten" ) {
00269       search.unit = fV->getValue();
00270     }
00271     tmp = "select_" + pool + "_content";
00272     fV = cgi.getElement(tmp);
00273     if( fV->getValue() != "Inhalte" ) {
00274       search.content = fV->getValue();
00275     }
00276     
00277     typedef std::vector< IndexData_SP > iVec;
00278     iVec entries;
00279     IndexData_SP data;
00280     
00281     resCount = read->getEntries( pool, search, entries );
00282     resStream << "<table>\n";
00283     iVec::iterator i;
00284     iVec::iterator iEnd = entries.end();
00285     for( i = entries.begin(); i != iEnd; ++i ) {
00286       data = *i;
00287       resStream << "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n"
00288       << "<tr>\n"
00289       << "<td>Such-Tag</td>"
00290       << "<td>"
00291       << data->tag
00292       << "</td>"
00293       << "</tr>\n";
00294       if( search.incAtts ) {
00295    if( !data->attributes.empty() ) {
00296      resStream << "<tr>\n"
00297           << "<td>Attribute</td>"
00298           << "<td>\n"
00299           << "<table>\n"
00300           << "<tr><td>Name</td><td>Wert</td></tr>";
00301      psfa::AttMap::iterator a;
00302      psfa::AttMap::iterator aEnd = data->attributes.end();
00303      for( a = data->attributes.begin(); a != aEnd; ++a ) {
00304        resStream << "<tr><td>"
00305             << a->first
00306             << "</td><td>"
00307             << a->second
00308             << "</td></tr>";
00309      }
00310      resStream << "</table>\n"
00311           << "</td>\n"
00312           << "</tr>\n";
00313    }
00314       }
00315       resStream << "<tr>\n"
00316       << "<td>Inhalt</td>"
00317       << "<td>"
00318       << data->content
00319       << "</td>"
00320       << "</tr>\n"
00321       << "<tr>\n"
00322       << "<td>Kontext</td>"
00323       << "<td>"
00324       << data->kontext
00325       << "</td>"
00326       << "</tr>\n"
00327       << "<tr>\n"
00328       << "<td>Einheit</td>"
00329       << "<td>"
00330       << data->unit
00331       << "</td>"
00332       << "</tr>\n"
00333       << "<tr>\n"
00334       << "<td>Datei</td>"
00335       << "<td>"
00336       << data->file
00337       << "</td>"
00338       << "</tr>\n";
00339       if( search.incPosData ) {
00340    resStream << "<tr>\n"
00341         << "<td>Start-Zeile</td>"
00342         << "<td>"
00343         << data->lineStart
00344         << "</td>"
00345         << "</tr>\n"
00346         << "<tr>\n"
00347         << "<td>Start-Kolumne</td>"
00348         << "<td>"
00349         << data->columnStart
00350         << "</td>"
00351         << "</tr>\n"
00352         << "<tr>\n"
00353         << "<td>Stop-Zeile</td>"
00354         << "<td>"
00355         << data->lineStop
00356         << "</td>"
00357         << "</tr>\n"
00358         << "<tr>\n"
00359         << "<td>Stop-Kolumne</td>"
00360         << "<td>"
00361         << data->columnStop
00362         << "</td>"
00363         << "</tr>\n"
00364         << "<tr>\n"
00365         << "<td>Start-Position</td>"
00366         << "<td>"
00367         << data->posStart
00368         << "</td>"
00369         << "</tr>\n"
00370         << "<tr>\n"
00371         << "<td>Stop-Position</td>"
00372         << "<td>"
00373         << data->posEnd
00374         << "</td>"
00375         << "</tr>\n";
00376       }
00377     }
00378     resStream << "</table>\n";
00379   }
00380   
00381   resCountStream << resCount;
00382   tmp = "PSFA--count";
00383   tplPos = searchForm.find( tmp );
00384   if( tplPos < string::npos ) {
00385     searchForm.replace( tplPos, tmp.size(), resCountStream.str() );
00386   }
00387     
00388   tmp = "PSFA--result";
00389   tplPos = searchForm.find( tmp );
00390   if( tplPos < string::npos ) {
00391     searchForm.replace( tplPos, tmp.size(), resStream.str() );
00392   }
00393   
00394   cout << "Content-Type: text/html" << endl
00395        << endl
00396        << searchForm 
00397        << endl;
00398 
00399   delete read;
00400   return 0;
00401 }

void printVec psfa::sVec vec,
std::ostringstream &  stream
 

Definiert in Zeile 95 der Datei psfaCGI.cpp.

Benutzt psfa::sVec.

Wird benutzt von main().

00096 {
00097   using psfa::sVec;
00098   
00099   stream << "<table>\n";
00100   sVec::iterator i;
00101   sVec::iterator iEnd = vec.end();
00102   for( i = vec.begin(); i != iEnd; ++i ) {
00103     stream << "<tr><td>"
00104       << *i
00105       << "</td></tr>\n";
00106   }
00107   stream << "</table>\n";
00108 }

void setUpPsfa  ) 
 

Definiert in Zeile 35 der Datei psfaCGI.cpp.

Benutzt psfahelper::pathIsReadable() und psfa::sVec.

Wird benutzt von main().

00036 {
00037   using psfa::sVec;
00038   using psfa::Config;
00039   using psfahelper::pathIsReadable;
00040 
00041   sVec psfaConfigs;
00042   psfaConfigs.reserve( 3 );
00043   const char* env = getenv("PSFA_CONFIG");
00044   if ( env ) {
00045     psfaConfigs.push_back( env );
00046     delete env;
00047   }
00048   env = std::getenv("HOME");
00049   if ( env ) {
00050     std::string h( env );
00051     h += "/.psfa/psfa_conf.xml";
00052     psfaConfigs.push_back( h );
00053     delete env;
00054   }
00055   psfaConfigs.push_back( "/etc/psfa_conf.xml" );
00056 
00057   Config* conf = Config::getConfig();
00058   sVec::iterator i;
00059   sVec::iterator iEnd = psfaConfigs.end();
00060   for( i = psfaConfigs.begin(); i != iEnd; ++i ) {
00061     if( pathIsReadable( *i ) ) {
00062       conf->parseConfig( *i );
00063     }
00064   }
00065   return;
00066 }


Erzeugt am Mon Jul 12 11:45:07 2004 für PSFA von doxygen 1.3.4