XmlEntityLoader.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename XmlEntityLoader.cpp
00024  * @Description Implementation of the XmlEntityLoader function
00025  * @Status Implementing
00026  * @Version $Id: XmlEntityLoader.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Marco Barbosa
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include "XmlEntityLoader.hpp"
00033 
00034 #include <string>
00035 
00036 #include <FilePathSearch.hpp>
00037 
00038 using namespace mermaid::support::xml;
00039 using std::string;
00040 using mermaid::support::system::FilePathSearch;
00041 
00042 
00043 
00044 xmlExternalEntityLoader XmlEntityLoader::defaultLoader_ = xmlGetExternalEntityLoader();
00045 
00046 
00047 
00048 xmlParserInputPtr XmlEntityLoader::loaderFunction (const char * URL,
00049     const char * ID,
00050     xmlParserCtxtPtr context)
00051 {
00052 #if 0
00053   cerr << "XmlEntityLoader::loaderFunction : ";
00054   if (URL != 0) {
00055     cerr << "URL:" << URL;
00056   }
00057   if (ID != 0) {
00058     cerr << " ID:" << ID;
00059   }
00060   
00061   cerr << endl;
00062 #endif
00063   
00064   xmlParserInputPtr ret = defaultLoader_ (URL, ID, context);
00065   
00066   // default loader could not find file, lets see if its one of the known paths
00067   
00068   if ( (ret == 0) & (URL != 0)) {
00069     string fileFullPath;
00070     
00071     try {
00072       // look directly for URL
00073       fileFullPath = FilePathSearch::getFullPathForFile (string (URL));
00074     }
00075     catch (...) {
00076       // look only for file name
00077       // cerr << "XmlEntityLoader::loaderFunction : could not find file : " << URL << endl;
00078       string url (URL);
00079       int slashPos = url.find_last_of ("/");
00080       string fileName = url.substr (slashPos + 1);
00081       // cerr << "XmlEntityLoader::loaderFunction : looking for file : " << fileName << endl;
00082       
00083       try {
00084         fileFullPath = FilePathSearch::getFullPathForFile (fileName);
00085       }
00086       catch (...) {
00087         // cerr << "XmlEntityLoader::loaderFunction : could not find file : " << fileName << endl;
00088       }
00089     }
00090     
00091     ret = defaultLoader_ (fileFullPath.c_str(), ID, context);
00092   }
00093   
00094   return ret;
00095 }
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3