00001 // ******************************************************************* 00002 // Document.cpp 00003 // ******************************************************************* 00004 // 00005 // DESCRIPTION: API for Document class. Used to manipulate a 00006 // given document. 00007 // NOTE: This program makes use of strings and the 00008 // basename() system call. 00009 // 00010 /*************************************************************************** 00011 * Copyright (C) 2003 by drs. Eric D. Schabell * 00012 * erics@cs.kun.nl * 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 ***************************************************************************/ 00019 00020 //-------------------------------------------------------------------- 00021 //#includes 00022 //-------------------------------------------------------------------- 00023 #include <iostream> 00024 #include <string> 00025 #include "Document.h" 00026 00027 using namespace std; 00028 00029 //-------------------------------------------------------------------- 00030 //Purpose: default constructor. 00031 //Preconditions: none. 00032 //Postconditions: a Document object is instantiated and all 00033 // attributes are zeroed. 00034 //Arguments: none. 00035 //Returns: Document. 00036 //Called Funcs: none. 00037 //-------------------------------------------------------------------- 00038 Document::Document () 00039 { 00040 url = "0"; 00041 file = "0"; 00042 conLocation = "0"; 00043 fileLocation = "0"; 00044 } 00045 00046 //-------------------------------------------------------------------- 00047 //Purpose: constructor with url and conversion given.. 00048 //Preconditions: must supply a string document url and a 00049 // string conversion routine. 00050 //Postconditions: a Document object is instantiated with a 00051 // document url, file name and conversion 00052 // routine defined. File location and Conversion 00053 // location are zeroed. 00054 //Arguments: string doc_url, string routine. 00055 //Returns: Document. 00056 //Called Funcs: setDocumentFile(), setDocumentConversion(). 00057 //-------------------------------------------------------------------- 00058 Document::Document(string doc_url, string routine) 00059 { 00060 // setting url and file now. 00061 url = doc_url; 00062 setDocumentFile(); 00063 setDocumentConversion(routine); 00064 00065 // prepare fileLocation and conLocation for latter assignment. 00066 fileLocation = "0"; 00067 conLocation = "0"; 00068 } 00069 00070 //-------------------------------------------------------------------- 00071 //Purpose: default destructor. 00072 //Preconditions: Document object. 00073 //Postconditions: Document object destroyed. 00074 //Arguments: none. 00075 //Returns: 0 00076 //Called Funcs: none. 00077 //-------------------------------------------------------------------- 00078 Document::~Document() 00079 { 00080 // cout << "Destroying Docuemnt object. << endl; 00081 } 00082 00083 //-------------------------------------------------------------------- 00084 //Purpose: obtain the docuemnts complete url. 00085 //Preconditions: Docuemnt object exists. 00086 //Postconditions: returns url attribute. 00087 //Arguments: none. 00088 //Returns: string. 00089 //Called Funcs: none. 00090 //-------------------------------------------------------------------- 00091 string Document::getDocumentUrl() 00092 { 00093 return url; 00094 } 00095 00096 //-------------------------------------------------------------------- 00097 //Purpose: Return the file name if instantiated, otherwise 00098 // returns the url attribute. 00099 //Preconditions: Docuemnt object created. 00100 //Postconditions: success = returns instantiated file attribute. 00101 // failure = returns url if file has not been instantiated, 00102 // which signals a problem with the 00103 // document construction. 00104 //Arguments: none. 00105 //Returns: string 00106 //Called Funcs: none. 00107 //-------------------------------------------------------------------- 00108 string Document::getDocumentFile() 00109 { 00110 if (file == "0") 00111 { 00112 cout << "Error: file not initialized yet?" << endl; 00113 // returning url instead to provide at least some sort of 00114 // file to the caller. 00115 return url; 00116 } 00117 else 00118 { 00119 // file is really only a file name. 00120 return file; 00121 } 00122 } 00123 00124 //-------------------------------------------------------------------- 00125 //Purpose: Return the conversion routine attribute. 00126 //Preconditions: Docuemnt object created. 00127 //Postconditions: returns instantiated file attribute. 00128 //Arguments: none. 00129 //Returns: string 00130 //Called Funcs: none. 00131 //-------------------------------------------------------------------- 00132 string Document::getDocumentConversion() 00133 { 00134 if (conversion == "0") 00135 { 00136 cout << "Error: conversion has not been initialized yet?" << endl; 00137 // return the NULL value for user. 00138 return conversion; 00139 } 00140 else 00141 { 00142 // conversion is initialized, return. 00143 return conversion; 00144 } 00145 } 00146 00147 //-------------------------------------------------------------------- 00148 //Purpose: Return the conLocation attribute. 00149 //Preconditions: Docuemnt object created. 00150 //Postconditions: returns conLocation attribute. 00151 //Arguments: none. 00152 //Returns: string 00153 //Called Funcs: none. 00154 //-------------------------------------------------------------------- 00155 string Document::getConversionLocation() 00156 { 00157 if (conLocation == "0") 00158 { 00159 cout << "Error: conLocation has not been initialized yet?" << endl; 00160 // return the NULL value for user. 00161 return conLocation; 00162 } 00163 else 00164 { 00165 // conLocation is initialized, return. 00166 return conLocation; 00167 } 00168 } 00169 00170 //-------------------------------------------------------------------- 00171 //Purpose: Return the docuemnt file location. 00172 //Preconditions: Docuemnt object created. 00173 //Postconditions: returns fileLocation attribute. 00174 //Arguments: none. 00175 //Returns: string 00176 //Called Funcs: none. 00177 //-------------------------------------------------------------------- 00178 string Document::getFileLocation() 00179 { 00180 return fileLocation; 00181 } 00182 00183 //-------------------------------------------------------------------- 00184 //Purpose: Determine and set the file name by basnaming 00185 // the url attribute. 00186 //Preconditions: Docuemnt object created. 00187 //Postconditions: success = a set file attribute. 00188 // failure = returns error 00189 //Arguments: none. 00190 //Returns: 0. 00191 //Called Funcs: basename(). 00192 //-------------------------------------------------------------------- 00193 void Document::setDocumentFile() 00194 { 00195 // attempt to determine basename() with Linux system call. 00196 if ( basename( url.c_str() ) ) 00197 { 00198 file = basename(url.c_str() ); 00199 return; 00200 } 00201 else 00202 { 00203 cerr << "File name could not be determined with basename()." << endl; 00204 exit(1); 00205 } 00206 } 00207 00208 //-------------------------------------------------------------------- 00209 //Purpose: Instantiates the conversion attribute with the 00210 // given convertion routine. 00211 //Preconditions: Docuemnt object created, convertion routine 00212 // provided. . 00213 //Postconditions: instantiated conversion attribute. 00214 //Arguments: string convertion_request.. 00215 //Returns: 0. 00216 //Called Funcs: none. 00217 //-------------------------------------------------------------------- 00218 void Document::setDocumentConversion(string conversion_request) 00219 { 00220 // set with passed parameter, no checking yet. 00221 conversion = conversion_request; 00222 } 00223 00224 //-------------------------------------------------------------------- 00225 //Purpose: Sets the converted files location to given location. 00226 //Preconditions: Docuemnt object created, location provided. 00227 //Postconditions: conLocation attribute is set with given file 00228 // location. 00229 //Arguments: string conversion_location. 00230 //Returns: 0. 00231 //Called Funcs: none. 00232 //-------------------------------------------------------------------- 00233 void Document::setConversionLocation(string conversion_location) 00234 { 00235 conLocation = conversion_location; 00236 } 00237 00238 //-------------------------------------------------------------------- 00239 //Purpose: Sets the file location to given location. 00240 //Preconditions: Docuemnt object created, location provided. 00241 //Postconditions: fileLocation attribute is set with given file 00242 // location. 00243 //Arguments: string file_location. 00244 //Returns: 0. 00245 //Called Funcs: none. 00246 //-------------------------------------------------------------------- 00247 void Document::setFileLocation(string file_location) 00248 { 00249 fileLocation = file_location; 00250 }