00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <iostream>
00026 #include <string>
00027 #include <cstdlib>
00028 #include <pqxx/all.h>
00029 #include "Broker.h"
00030 #include "Document.h"
00031
00032 using namespace std;
00033 using namespace pqxx;
00034
00035
00036
00037
00038
00039 static const int MIN_ARGS = 2;
00040 enum Flag {
00041 listingQuery,
00042 remoteServer,
00043 representaionTypeQuery,
00044 featureTypeQuery,
00045 none
00046 };
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void usage()
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 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 Flag determineArgs( string myArg )
00104 {
00105 Flag myFlag;
00106
00107
00108 if ( myArg == "-l" )
00109 {
00110 return ( myFlag = listingQuery );
00111 }
00112 else
00113 {
00114
00115 if ( myArg == "-r" )
00116 {
00117 return ( myFlag = representaionTypeQuery );
00118 }
00119 }
00120
00121
00122 if ( myArg == "-s" )
00123 {
00124 return ( myFlag = remoteServer );
00125 }
00126 else
00127 {
00128
00129 if ( myArg == "-f" )
00130 {
00131 return ( myFlag = featureTypeQuery );
00132 }
00133 else
00134 {
00135 return ( myFlag = none );
00136 }
00137 }
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 void displayQueryResults( Result query )
00150 {
00151 int tabsize = 4;
00152
00153
00154
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
00168 for ( Result::size_type i = 0; i != query.size(); ++i )
00169 {
00170
00171 cout << query[i]["routine_name"];
00172 cout << '\t' << '\t';
00173
00174
00175 if ( query[i]["routine_name"].size() < ( tabsize + tabsize ) )
00176 {
00177
00178 cout << '\t';
00179 }
00180 cout << query[i]["from_feature_type"];
00181 cout << '\t';
00182
00183
00184 if ( query[i]["from_feature_type"].size() < ( tabsize + tabsize ) )
00185 {
00186
00187 cout << '\t';
00188 }
00189 cout << query[i]["from_representation_type"];
00190 cout << '\t' << '\t';
00191
00192
00193 if ( query[i]["from_representation_type"].size() < ( tabsize + tabsize )
00194 )
00195 {
00196
00197 cout << '\t';
00198 }
00199 cout << query[i]["to_feature_type"];
00200 cout << '\t';
00201
00202
00203 if ( query[i]["to_feature_type"].size() < ( tabsize + tabsize ) )
00204 {
00205
00206 cout << '\t';
00207 }
00208 cout << query[i]["to_representation_type"];
00209 cout << endl;
00210 }
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 int main( int argc, char *const argv[] )
00233 {
00234
00235 if ( argc < MIN_ARGS )
00236 {
00237 cout << "Wrong usage of docconvert options." << endl;
00238 usage();
00239 exit(1);
00240 }
00241
00242
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
00256 usage();
00257 exit(1);
00258 }
00259 else
00260 {
00261
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
00281 break;
00282
00283 case remoteServer:
00284
00285 if ( argc != ( MIN_ARGS * 2 ) )
00286 {
00287 usage();
00288 exit(1);
00289 }
00290 else
00291 {
00292
00293 ++argv;
00294 string myserver = argv[0];
00295 ++argv;
00296 string myconversion = argv[0];
00297 ++argv;
00298 string mydocuri = argv[0];
00299
00300
00301 Document myDoc( mydocuri, myconversion );
00302
00303
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
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
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
00338 break;
00339
00340 case representaionTypeQuery:
00341
00342 if ( argc != MIN_ARGS )
00343 {
00344
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
00376 break;
00377
00378 case featureTypeQuery:
00379
00380 if ( argc != MIN_ARGS )
00381 {
00382
00383 usage();
00384 exit(1);
00385 }
00386 else
00387 {
00388 ++argv;
00389
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
00413 break;
00414
00415 case none:
00416
00417
00418 if ( argc != MIN_ARGS )
00419 {
00420 usage();
00421 exit(1);
00422 }
00423 else
00424 {
00425
00426 string myconversion = argv[0];
00427 ++argv;
00428 string mydocuri = argv[0];
00429
00430
00431 Document myDoc( mydocuri, myconversion );
00432
00433
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
00443 Broker docTransformer;
00444 if ( docTransformer.convertDocument( myDoc ) )
00445 {
00446 cout << "Conversion is available somewhere in " <<
00447 myDoc.getConversionLocation();
00448 cout << ":" << endl;
00449
00450
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
00466 break;
00467 }
00468
00469
00470
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 }