Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

main.cpp File Reference

#include <iostream>
#include <string>
#include <cstdlib>
#include <pqxx/all.h>
#include "Broker.h"
#include "Document.h"

Include dependency graph for main.cpp:

Include dependency graph

Go to the source code of this file.

Enumerations

enum  Flag {
  listingQuery, remoteServer, representaionTypeQuery, featureTypeQuery,
  none
}

Functions

void usage ()
Flag determineArgs (string myArg)
void displayQueryResults (Result query)
int main (int argc, char *const argv[])

Variables

const int MIN_ARGS = 2


Enumeration Type Documentation

enum Flag
 

Enumeration values:
listingQuery 
remoteServer 
representaionTypeQuery 
featureTypeQuery 
none 

Definition at line 40 of file main.cpp.

Referenced by determineArgs(), and main().

00040           {                             // handles agrs passed.
00041     listingQuery,
00042     remoteServer,
00043     representaionTypeQuery,
00044     featureTypeQuery,
00045     none
00046 };


Function Documentation

Flag determineArgs string  myArg  ) 
 

Definition at line 103 of file main.cpp.

References featureTypeQuery, Flag, listingQuery, none, remoteServer, and representaionTypeQuery.

Referenced by main().

00104 {
00105     Flag myFlag;
00106 
00107     // check for listing query request.
00108     if ( myArg == "-l" )
00109     {
00110         return ( myFlag = listingQuery );
00111     }
00112     else
00113     {
00114         // check for representation type query request.
00115         if ( myArg == "-r" )
00116         {
00117             return ( myFlag = representaionTypeQuery );
00118         }
00119     }
00120 
00121     // check if remote server requested.
00122     if ( myArg == "-s" )
00123     {
00124         return ( myFlag = remoteServer );
00125     }
00126     else
00127     {
00128         // check for feature type query request.
00129         if ( myArg == "-f" )
00130         {
00131             return ( myFlag = featureTypeQuery );
00132         }
00133         else
00134         {
00135             return ( myFlag = none );
00136         }
00137     }
00138 }

void displayQueryResults Result  query  ) 
 

Definition at line 149 of file main.cpp.

Referenced by main().

00150 {
00151     int tabsize = 4;  // for report layout.
00152 
00153     // Process each successive result tuple with this loop,
00154     // remember there are 5 columns.
00155     cout << "Routine Name";
00156     cout << '\t' << '\t' << "From Feature";
00157     cout << '\t' << "From Representation";
00158     cout << '\t' << "To Feature";
00159     cout << '\t' << "To Representation";
00160     cout << endl;
00161     cout << "===========";
00162     cout << '\t' << '\t' << "===========";
00163     cout << '\t' << "================";
00164     cout << '\t' << "===========";
00165     cout << '\t' << "==============" << endl;
00166 
00167     //    for (Result::const_iterator c = R.begin(); c != R.end(); ++c)
00168     for ( Result::size_type i = 0; i != query.size(); ++i )
00169     {
00170         // Output column elements.
00171         cout << query[i]["routine_name"];
00172         cout << '\t' << '\t';
00173 
00174         // check for formating text, the size of next element.
00175         if ( query[i]["routine_name"].size() < ( tabsize + tabsize ) )
00176         {
00177             // small, need extra tab.
00178             cout << '\t';
00179         }
00180         cout << query[i]["from_feature_type"];
00181         cout << '\t';
00182 
00183         // check for formating text, the size of next element.
00184         if ( query[i]["from_feature_type"].size() < ( tabsize + tabsize ) )
00185         {
00186             // small, need extra tab.
00187             cout << '\t';
00188         }
00189         cout << query[i]["from_representation_type"];
00190         cout << '\t' << '\t';
00191 
00192         // check for formating text, the size of next element.
00193         if ( query[i]["from_representation_type"].size() < ( tabsize + tabsize )
00194            )
00195         {
00196             // small, need extra tab.
00197             cout << '\t';
00198         }
00199         cout << query[i]["to_feature_type"];
00200         cout << '\t';
00201 
00202         // check for formating text, the size of next element.
00203         if ( query[i]["to_feature_type"].size() < ( tabsize + tabsize ) )
00204         {
00205             // small, need extra tab.
00206             cout << '\t';
00207         }
00208         cout << query[i]["to_representation_type"];
00209         cout << endl;
00210     }
00211 }

int main int  argc,
char *const   argv[]
 

Definition at line 232 of file main.cpp.

References Broker::convertDocument(), determineArgs(), displayQueryResults(), featureTypeQuery, Flag, Broker::getConversionListing(), Document::getConversionLocation(), Document::getDocumentConversion(), Document::getDocumentFile(), Broker::getFeatureTypeListing(), Broker::getRepresentationTypeListing(), listingQuery, MIN_ARGS, none, remoteServer, representaionTypeQuery, and usage().

Referenced by DocConversionTestSuite::DocConversionTestSuite().

00233 {
00234     // Check for no args.
00235     if ( argc < MIN_ARGS )
00236     {
00237         cout << "Wrong usage of docconvert options." << endl;
00238         usage();
00239         exit(1);
00240     }
00241 
00242     // determine which flags if any.
00243     --argc;
00244     ++argv;
00245     string argument = argv[0];
00246     Flag myFlag = determineArgs( argument );
00247 
00248     switch( myFlag )
00249     {
00250 
00251     case listingQuery:
00252 
00253         if ( argc != 1 )
00254         {
00255             // means more options after flag.
00256             usage();
00257             exit(1);
00258         }
00259         else
00260         {
00261             // no more options, so get listing.
00262             Broker myBroker;
00263             Result myResult = myBroker.getConversionListing();
00264             if ( myResult.size() > 0 )
00265             {
00266                 cout << endl << endl;
00267                 cout << "A listing of all possible conversions provided by the ";
00268                 cout << "DocConversion application:";
00269                 cout << endl << endl;
00270 
00271                 displayQueryResults( myResult );
00272             }
00273             else
00274             {
00275                 cout << "Something wrong with -l listing query results...";
00276                 cout << endl;
00277                 exit(1);
00278             }
00279         }
00280         // done here so bail.
00281         break;
00282 
00283     case remoteServer:
00284 
00285         if ( argc != ( MIN_ARGS * 2 ) )
00286         {
00287             usage();
00288             exit(1);
00289         }
00290         else
00291         {
00292             // extract the server name, conversion and document.
00293             ++argv;
00294             string myserver = argv[0];
00295             ++argv;
00296             string myconversion = argv[0];
00297             ++argv;
00298             string mydocuri = argv[0];
00299 
00300             // create our Document.
00301             Document myDoc( mydocuri, myconversion );
00302 
00303             // inform user.
00304             cout << "Converting document: " << endl;
00305             cout << "   " << myDoc.getDocumentFile() << endl;
00306             cout << "From URI: " << endl;
00307             cout << "   " << mydocuri << endl;
00308             cout << "Using conversion routine:" << endl;
00309             cout << "   " << myDoc.getDocumentConversion();
00310             cout << endl << endl;
00311 
00312             // setup remote Broker and request conversion.
00313             Broker docTransformer( myserver );
00314 
00315             if ( docTransformer.convertDocument( myDoc ) )
00316             {
00317                 cout << "Conversion is available somewhere in ";
00318                 cout << myDoc.getConversionLocation();
00319                 cout << ":" << endl;
00320 
00321                 // setup system call for displaying conversion results dir.
00322                 string call = "cd " + myDoc.getConversionLocation() +
00323                               "; " + " ls -lhd /tmp/*";
00324                 system( call.c_str() );
00325                 cout << endl;
00326                 cout << "Thank you for using DocConversion!" << endl;
00327             }
00328             else
00329             {
00330                 cout << "Conversion was not possible..." << endl;
00331                 cout << "Maybe a bad document URI, wanna take a look ";
00332                 cout << "at usage?" << endl;
00333                 usage();
00334                 exit( 1 );
00335             }
00336         }
00337         // done here so bail.
00338         break;
00339 
00340     case representaionTypeQuery:
00341 
00342         if ( argc != MIN_ARGS )
00343         {
00344             // means more args after passed parameter.
00345             usage();
00346             exit(1);
00347         }
00348         else
00349         {
00350             ++argv;
00351             string requestedRepType = argv[0];
00352             Broker myBroker;
00353             Result myRepResult =
00354                 myBroker.getRepresentationTypeListing( requestedRepType );
00355             if ( myRepResult.size() > 0 )
00356             {
00357                 cout << endl << endl;
00358                 cout << "Based on the given representation type, the following routines ";
00359                 cout << " are provided by the DocConversion application:";
00360                 cout << endl << endl;
00361                 displayQueryResults( myRepResult );
00362             }
00363             else
00364             {
00365                 cout << "The representation type you requested is not available on our ";
00366                 cout << endl;
00367                 cout << "system... This could mean that the database is unavailable at ";
00368                 cout << endl;
00369                 cout << "this time, or that the feature type is really not provided by ";
00370                 cout << endl;
00371                 cout << "our system.";
00372                 cout << endl;
00373             }
00374         }
00375         // done here so bail.
00376         break;
00377 
00378     case featureTypeQuery:
00379 
00380         if ( argc != MIN_ARGS )
00381         {
00382             // means more args after passed parameter.
00383             usage();
00384             exit(1);
00385         }
00386         else
00387         {
00388             ++argv;
00389             // passed feature type parameter.
00390             string requestedFeatureType = argv[0];
00391             Broker myBroker;
00392             Result myFeatureResult =
00393                 myBroker.getFeatureTypeListing( requestedFeatureType );
00394             if ( myFeatureResult.size() > 0 )
00395             {
00396                 cout << endl << endl;
00397                 cout << "Based on the given feature type, the following routines ";
00398                 cout << " are provided by the DocConversion application:";
00399                 cout << endl << endl;
00400                 displayQueryResults( myFeatureResult );
00401             }
00402             else
00403             {
00404                 cout << "The feature type you requested is not available on our system... ";
00405                 cout << endl;
00406                 cout << "This could mean that the database is unavailable at this time, ";
00407                 cout << endl;
00408                 cout << "or that the feature type is really not provided by our system.";
00409                 cout << endl;
00410             }
00411         }
00412         // done here so bail.
00413         break;
00414 
00415     case none:
00416 
00417         // no options, so  deal with document conversion.
00418         if ( argc != MIN_ARGS )
00419         {
00420             usage();
00421             exit(1);
00422         }
00423         else
00424         {
00425             // extract the conversion and document
00426             string myconversion = argv[0];
00427             ++argv;
00428             string mydocuri = argv[0];
00429 
00430             // create our Document.
00431             Document myDoc( mydocuri, myconversion );
00432 
00433             // inform user.
00434             cout << "Converting document: " << endl;
00435             cout << "   " << myDoc.getDocumentFile() << endl;
00436             cout << "From URI: " << endl;
00437             cout << "   " << mydocuri << endl;
00438             cout << "Using conversion routine:" << endl;
00439             cout << "   " << myDoc.getDocumentConversion();
00440             cout << endl << endl;
00441 
00442             // setup default Broker and request conversion.
00443             Broker docTransformer;
00444             if ( docTransformer.convertDocument( myDoc ) )
00445             {
00446                 cout << "Conversion is available somewhere in " <<
00447                 myDoc.getConversionLocation();
00448                 cout << ":" << endl;
00449 
00450                 // setup system call for displaying conversion results dir.
00451                 string call = "cd " + myDoc.getConversionLocation() + "; " +
00452                               " ls -lhd /tmp/*";
00453                 system( call.c_str() );
00454                 cout << endl;
00455                 cout << "Thank you for using DocConversion!" << endl;
00456             }
00457             else
00458             {
00459                 cout << "Conversion was not possible..." << endl;
00460                 cout << "Maybe a bad document URI, wanna take a look at usage?" << endl;
00461                 usage();
00462                 exit( 1 );
00463             }
00464         }
00465         // done here so bail.
00466         break;
00467     } // end switch.
00468 
00469     //
00470     // Say goodbye!
00471     //
00472     cout << endl << endl;
00473     cout << "Thank you for allowing DocConversion to be your converison ";
00474     cout << endl;
00475     cout << "service provider. We look forward to helping you again in ";
00476     cout << endl;
00477     cout << "the near future.";
00478     cout << endl;
00479     cout << "                           'The DocConversion Team'" << endl;
00480 }

Here is the call graph for this function:

void usage  ) 
 

Definition at line 57 of file main.cpp.

Referenced by main().

00058 {
00059     cout << endl;
00060     cout << "Usage: " << endl;
00061     cout << "docconversion [options] <conversion> <document URI>" << endl;
00062     cout << "docconverison -l" << endl;
00063     cout << endl;
00064     cout << "Options:";
00065     cout << endl;
00066     cout << "-l             = show list of available converison routines from ";
00067     cout << endl;
00068     cout << "                 the Clearinghouse database.";
00069     cout << endl << endl;
00070     cout << "-r <representation-type>  = show list of available conversions ";
00071     cout << "based " << endl;
00072     cout << "                 on the supplied representaiton type (such as ";
00073     cout << "pdf, html, text, gz, *)." << endl;
00074     cout << "                 This will show all conversion routines where ";
00075     cout << "the supplied type" << endl;
00076     cout << "                 is available as a conversion'from' this type, ";
00077     cout << "or as a conversion" << endl;
00078     cout << "                 'to' this type.";
00079     cout << endl << endl;
00080     cout << "-s <server>    = hostname of converison server to be used.";
00081     cout << endl << "                 Default is localhost conversions.";
00082     cout << endl << endl;
00083     cout << "<conversion>   = name of conversion ";
00084     cout << "routine to be used.";
00085     cout << endl << endl;
00086     cout << "<document URI> = location of document to be converted {html|ftp}.";
00087     cout << endl << endl;
00088     cout << "Note: to check all possible feature|representation types you can pass the '*' (in quotes).";
00089     cout << endl << endl;
00090     return;
00091 }


Variable Documentation

const int MIN_ARGS = 2 [static]
 

Definition at line 39 of file main.cpp.

Referenced by main().


Generated on Thu Dec 4 14:39:18 2003 for docconversion.kdevelop by doxygen 1.3.4