BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EResolver.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/xmlBase/src/EResolver.cxx,v 1.1.1.1 2005/10/17
2// 06:10:27 maqm Exp $ author: J. Bogart
3
4// For some obscure reason, adding the following line keeps gcc3.2
5// happy. Otherwise, when the very same file is indirectly included
6// in XMLScanner.hpp below, the compile bombs
7#include "xmlBase/EResolver.h"
8#include "facilities/Util.h"
9#include "xmlBase/Dom.h"
10#include <xercesc/util/XMLString.hpp>
11#include <xercesc/util/XMLUniDefs.hpp>
12#include <xercesc/validators/schema/SchemaSymbols.hpp>
13// #include <xercesc/parsers/DOMParser.hpp>
14#include <xercesc/framework/LocalFileInputSource.hpp>
15#include <xercesc/internal/XMLScanner.hpp>
16#include <xercesc/sax/Locator.hpp>
17
18namespace xmlBase {
19 XERCES_CPP_NAMESPACE_USE
20
21 EResolver::EResolver() : m_nEntity( 0 ) { m_entities.clear(); }
22
23 // According to the XML spec, the systemId should be a URI (see
24 // http://www.ietf.org/rfc/rfc2396.txt for the really gory details).
25 // I *think* that, even though $ is reserved in some contexts, it
26 // can be used the way we would be likely to use it, as part of
27 // the introducer for an environment variable $(stuff)
28 // The algorithm is
29 // if publicId is non-null attempt to use it, in particular
30 // expand environment variable references if present
31 //
32 // otherwise expand and use systemId (which must be present)
33
34 InputSource*
35 EResolver::resolveEntity( XERCES_CPP_NAMESPACE_QUALIFIER XMLResourceIdentifier* xmlRI ) {
36 const XMLCh* publicId = xmlRI->getPublicId();
37 const XMLCh* systemId = xmlRI->getSystemId();
38 const XMLCh* baseURI = xmlRI->getBaseURI();
39 if ( publicId != 0 )
40 {
41 if ( XMLString::stringLen( publicId ) > 0 ) { return translateEnv( publicId, baseURI ); }
42 }
43 return translateEnv( systemId, baseURI );
44 }
45
46 InputSource* EResolver::translateEnv( const XMLCh* id, const XMLCh* baseURI ) {
47 // Make a std::string out of the spec we're passed
48 char* chId = XMLString::transcode( id );
49 std::string* idStr = new std::string( chId );
50 XMLString::release( &chId );
51 int nSub = facilities::Util::expandEnvVar( idStr );
52
53 m_entities.push_back( idStr );
54
55 if ( !nSub ) return 0;
56 else if ( nSub < 0 )
57 {
58 std::cout << "Bad entity name " << idStr << std::endl;
59 return 0;
60 }
61
62 // Otherwise something really did get translated, so make
63 // a new InputSource
64 XMLCh* realName = XMLString::transcode( idStr->c_str() );
65
66 // Apparently the InputSource already gets deleted by somebody else,
67 // so we don't have to keep track of it
68 LocalFileInputSource* src = new LocalFileInputSource( baseURI, realName );
69 XMLString::release( &realName );
70 return src;
71 }
72
74 for ( unsigned i = 0; i < m_entities.size(); i++ ) { delete m_entities[i]; }
75 m_entities.clear();
76 m_nEntity = 0;
77 }
78
80} // namespace xmlBase
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
virtual ~EResolver()
Definition EResolver.cxx:79
virtual XERCES_CPP_NAMESPACE_QUALIFIER InputSource * resolveEntity(XERCES_CPP_NAMESPACE_QUALIFIER XMLResourceIdentifier *xmlRI)
Definition EResolver.cxx:35