BOSS 7.0.9
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 06:10:27 maqm Exp $
2// 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 <xercesc/validators/schema/SchemaSymbols.hpp>
8#include "xmlBase/EResolver.h"
9#include "xmlBase/Dom.h"
10#include <xercesc/util/XMLUniDefs.hpp>
11#include <xercesc/util/XMLString.hpp>
12#include "facilities/Util.h"
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) {
22 m_entities.clear();
23 }
24
25 // According to the XML spec, the systemId should be a URI (see
26 // http://www.ietf.org/rfc/rfc2396.txt for the really gory details).
27 // I *think* that, even though $ is reserved in some contexts, it
28 // can be used the way we would be likely to use it, as part of
29 // the introducer for an environment variable $(stuff)
30 // The algorithm is
31 // if publicId is non-null attempt to use it, in particular
32 // expand environment variable references if present
33 //
34 // otherwise expand and use systemId (which must be present)
35
36
37 InputSource*
38 EResolver::resolveEntity(XERCES_CPP_NAMESPACE_QUALIFIER XMLResourceIdentifier* xmlRI) {
39 const XMLCh* publicId = xmlRI->getPublicId();
40 const XMLCh* systemId = xmlRI->getSystemId();
41 const XMLCh* baseURI = xmlRI->getBaseURI();
42 if (publicId != 0) {
43 if (XMLString::stringLen(publicId) > 0) {
44 return translateEnv(publicId, baseURI);
45 }
46 }
47 return translateEnv(systemId, baseURI);
48 }
49
50 InputSource* EResolver::translateEnv(const XMLCh * id, const XMLCh * baseURI)
51 {
52 // Make a std::string out of the spec we're passed
53 char* chId = XMLString::transcode(id);
54 std::string *idStr = new std::string(chId);
55 XMLString::release(&chId);
56 int nSub = facilities::Util::expandEnvVar(idStr);
57
58 m_entities.push_back(idStr);
59
60 if (!nSub) return 0;
61 else if (nSub < 0) {
62 std::cout << "Bad entity name " << idStr << std::endl;
63 return 0;
64 }
65
66 // Otherwise something really did get translated, so make
67 // a new InputSource
68 XMLCh* realName = XMLString::transcode(idStr->c_str());
69
70 // Apparently the InputSource already gets deleted by somebody else,
71 // so we don't have to keep track of it
72 LocalFileInputSource* src = new LocalFileInputSource(baseURI, realName);
73 XMLString::release(&realName);
74 return src;
75
76 }
77
79 for (unsigned i = 0; i < m_entities.size(); i++) {
80 delete m_entities[i];
81 }
82 m_entities.clear();
83 m_nEntity = 0;
84 }
85
87 clean();
88 }
89}
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
virtual ~EResolver()
Definition: EResolver.cxx:86
virtual XERCES_CPP_NAMESPACE_QUALIFIER InputSource * resolveEntity(XERCES_CPP_NAMESPACE_QUALIFIER XMLResourceIdentifier *xmlRI)
Definition: EResolver.cxx:38