/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/xmlBase/xmlBase-00-00-03/src/EResolver.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/xmlBase/src/EResolver.cxx,v 1.1.1.1 2005/10/17 06:10:27 maqm Exp $
00002 // author:  J. Bogart
00003 
00004 // For some obscure reason, adding the following line keeps gcc3.2
00005 // happy.  Otherwise, when the very same file is indirectly included
00006 // in XMLScanner.hpp below, the compile bombs
00007 #include <xercesc/validators/schema/SchemaSymbols.hpp>
00008 #include "xmlBase/EResolver.h"
00009 #include "xmlBase/Dom.h"
00010 #include <xercesc/util/XMLUniDefs.hpp>
00011 #include <xercesc/util/XMLString.hpp>
00012 #include "facilities/Util.h"
00013 // #include <xercesc/parsers/DOMParser.hpp>
00014 #include <xercesc/framework/LocalFileInputSource.hpp>
00015 #include <xercesc/internal/XMLScanner.hpp>
00016 #include <xercesc/sax/Locator.hpp>
00017 
00018 namespace xmlBase {
00019   XERCES_CPP_NAMESPACE_USE
00020   
00021   EResolver::EResolver() : m_nEntity(0) {
00022     m_entities.clear();
00023   }
00024 
00025   // According to the XML spec, the systemId should be a URI (see
00026   // http://www.ietf.org/rfc/rfc2396.txt for the really gory details).
00027   // I *think* that, even though $ is reserved in some contexts, it
00028   // can be used the way we would be likely to use it, as part of
00029   // the introducer for an environment variable $(stuff)
00030   // The algorithm is
00031   //    if publicId is non-null attempt to use it, in particular
00032   //    expand environment variable references if present
00033   //
00034   //    otherwise expand and use systemId (which must be present)  
00035   
00036 
00037   InputSource*
00038   EResolver::resolveEntity(XERCES_CPP_NAMESPACE_QUALIFIER XMLResourceIdentifier* xmlRI) {
00039     const XMLCh* publicId = xmlRI->getPublicId();
00040     const XMLCh* systemId = xmlRI->getSystemId();
00041     const XMLCh* baseURI = xmlRI->getBaseURI();
00042     if (publicId != 0) {
00043       if (XMLString::stringLen(publicId) > 0) {
00044         return translateEnv(publicId, baseURI); 
00045       }    
00046     }
00047     return translateEnv(systemId, baseURI);
00048   }
00049 
00050   InputSource* EResolver::translateEnv(const XMLCh * id, const XMLCh * baseURI)
00051   {
00052     // Make a std::string out of the spec we're passed
00053     char* chId = XMLString::transcode(id);  
00054     std::string *idStr = new std::string(chId);
00055     XMLString::release(&chId);
00056     int nSub = facilities::Util::expandEnvVar(idStr);
00057 
00058     m_entities.push_back(idStr);
00059     
00060     if (!nSub) return 0;     
00061     else if (nSub < 0) {
00062       std::cout << "Bad entity name " << idStr << std::endl;
00063       return 0;
00064     }
00065 
00066     // Otherwise something really did get translated, so make
00067     // a new InputSource
00068     XMLCh* realName = XMLString::transcode(idStr->c_str());
00069 
00070     // Apparently the InputSource already gets deleted by somebody else,
00071     // so we don't have to keep track of it
00072     LocalFileInputSource*  src = new LocalFileInputSource(baseURI, realName);
00073     XMLString::release(&realName);
00074     return src;
00075 
00076   }
00077 
00078   void EResolver::clean() {
00079     for (unsigned i = 0; i < m_entities.size(); i++) {
00080       delete m_entities[i];
00081     }
00082     m_entities.clear();
00083     m_nEntity = 0;
00084   }
00085 
00086   EResolver::~EResolver() {
00087     clean();
00088   }
00089 }

Generated on Tue Nov 29 22:57:57 2016 for BOSS_7.0.2 by  doxygen 1.4.7