00001 #include <iostream> 00002 #include "DataTable.h" 00003 #include "Database.h" 00004 #include "XMLTableParser.h" 00005 00006 #include <stddef.h> 00007 #include <stdio.h> 00008 #include <sys/types.h> 00009 #include <dirent.h> 00010 #include <fstream> 00011 #include <sstream> 00012 00034 class Parser 00035 { 00036 00037 private: 00038 00039 std::string _url; // URL for network files 00040 std::string _fileName; // fileName for disk file (also for network local /tmp file) 00041 bool _isANetworkFile; // true if a network file 00042 00043 std::vector<DataTable *> _tables; // List of all data tables that have been read in 00044 00045 std::vector<xmlNode*> _xmlTableTagPointers; // Pointers to the start of tables in XML files 00046 00047 // 00048 // FileTypeClassifier _fileTypeClassifier; // The FileTypeClassifier class opens files to determine their type. 00049 // 00050 FileTypeClassifier::FILE_TYPE _fileType; 00051 const char* _fileTypeName; 00052 00053 // 00054 // 2006.08.22.ET addendum: 00055 // 00056 XMLTagManager _xmlTagManager; 00057 00058 00059 #ifdef MYSQLPP 00060 Database _currentMysqlTable; 00061 #endif 00062 00063 // Read in the supported XML tags for use in parsing 00064 void _readXMLFormats(); 00065 00066 // Read file based on type 00067 void _readXML(std::string data); 00068 void _readDelimited(std::string data); 00069 void _readMadeline(std::string data); 00070 00071 // Used to determine format of flat files 00072 int _determineNumberOfBlocks(std::string inString); 00073 00074 // Used to determine number of tables in XML file. Fills in the _pointers variable with table tags 00075 void _countTables(xmlNode *node); 00076 00077 // Used to convert a file into a string 00078 std::string _stringify(std::string name); 00079 00080 public: 00081 00082 Parser(); 00083 ~Parser(); 00084 void display(); 00085 00086 void readFile(const std::string &filename); 00087 void readNetworkFile(const std::string &url); 00088 00089 #ifdef MYSQLPP 00090 void readMysql(std::string tableName); 00091 void connectMysql(std::string host,std::string port, std::string user, std::string password, std::string database); 00092 void queryMysql(const char* sqlQuery) {_currentMysqlTable.query(sqlQuery);} 00093 #endif 00094 00095 DataTable * getTable(unsigned i) { return _tables[i];} 00096 00097 00098 const int getNumberOfTables( void ) const { return _tables.size(); }; 00099 00100 std::string getName(void) const { return _fileName; }; 00101 std::string getURL(void) const { return _url; }; 00102 bool isANetworkFile(void) const { return _isANetworkFile; }; 00103 00104 }; 00105