00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __URNRESOLVER_H__
00030 #define __URNRESOLVER_H__
00031
00032 #include "H3DApi.h"
00033 #include <map>
00034 #include <fstream>
00035 #include <iostream>
00036 #include <string>
00037
00038 using namespace std;
00039
00040 namespace H3D {
00062 class H3DAPI_API URNResolver {
00063 public:
00064
00065
00068 URNResolver( const string &_config_file = "" ){
00069 config_file = _config_file;
00070 initialised = false;
00071 }
00072
00074 void loadConfigFile( const string &config_file );
00075
00081 void addURNResolveRule( const string &name_space,
00082 const string &prefix,
00083 const string &path ) {
00084 string key = "urn:";
00085 key = key + toLower( name_space ) + ":" + prefix;
00086 urn_prefix_map[ key ] = path;
00087 }
00088
00089
00092 string resolveURN( const string &urn );
00093
00094 protected:
00095
00096 static const unsigned int MAX_LINE_SIZE = 1024;
00097 bool nonCaseEquals( const string &s1,
00098 const string &s2 ) {
00099 if( s1.size() != s2.size() ) return false;
00100
00101 for( unsigned int i = 0; i < s1.size(); i++ ) {
00102 if( toupper( s1[i]) != toupper( s2[i] ) )
00103 return false;
00104 }
00105 return true;
00106 }
00107
00108 bool hasPrefix( const string &s,
00109 const string &prefix ) {
00110 if( prefix.size() > s.size() ) return false;
00111 for( unsigned int i = 0; i < prefix.size(); i++ )
00112 if( s[i] != prefix[i] ) return false;
00113 return true;
00114 }
00115
00116 string toLower( const string &s ) {
00117 string res = s;
00118 for( unsigned int i = 0; i < s.size(); i++ )
00119 res[i] = tolower( s[i] );
00120 return res;
00121 }
00122
00123 struct lessthan_string {
00124 bool operator()(const string & s1, const string & s2) const {
00125 if( s1.size() < s2.size() ) return true;
00126 return s1 < s2;
00127 }
00128 };
00129
00130 typedef map< string, string, lessthan_string > URNmap;
00131 URNmap urn_prefix_map;
00132 string config_file;
00133 bool initialised;
00134 };
00135 }
00136
00137 #endif