ATLAS Offline Software
Public Member Functions | Protected Attributes | Private Attributes | List of all members
XercesParser Class Reference

#include <XercesParser.h>

Inheritance diagram for XercesParser:
Collaboration diagram for XercesParser:

Public Member Functions

 XercesParser (XMLHandlerStore &xs)
 
 XercesParser (XMLHandlerStore &xs, const std::string &)
 
virtual ~XercesParser ()
 
virtual bool ParseFile (const std::string &) override
 
virtual bool ParseFileAndNavigate (AGDDController &c, const std::string &) override
 
virtual bool ParseString (const std::string &) override
 
virtual bool ParseStringAndNavigate (AGDDController &c, const std::string &) override
 
virtual bool WriteToFile (const std::string &) override
 
virtual void navigateTree (AGDDController &c) override
 
virtual void elementLoop () override
 
virtual void elementLoop (AGDDController &c, xercesc::DOMNode *) override
 
bool Initialize ()
 
bool Finalize ()
 

Protected Attributes

std::string m_fileName
 

Private Attributes

xercesc::DOMDocument * m_doc
 
xercesc::XercesDOMParser * m_parser
 
bool m_initialized
 
XMLHandlerStorem_xs
 

Detailed Description

Definition at line 18 of file XercesParser.h.

Constructor & Destructor Documentation

◆ XercesParser() [1/2]

XercesParser::XercesParser ( XMLHandlerStore xs)

Definition at line 33 of file XercesParser.cxx.

34  : IAGDDParser(),m_doc(0),m_parser(0),m_initialized(false),
35  m_xs(xs)
36 {
37 }

◆ XercesParser() [2/2]

XercesParser::XercesParser ( XMLHandlerStore xs,
const std::string &  s 
)

Definition at line 39 of file XercesParser.cxx.

40  : IAGDDParser(s),m_doc(0),m_parser(0),m_initialized(false),
41  m_xs(xs)
42 {
43 }

◆ ~XercesParser()

XercesParser::~XercesParser ( )
virtual

Definition at line 26 of file XercesParser.cxx.

27 {
28  delete m_parser;
29  m_parser=0;
30  Finalize();
31 }

Member Function Documentation

◆ elementLoop() [1/2]

void XercesParser::elementLoop ( )
overridevirtual

Implements IAGDDParser.

Definition at line 193 of file XercesParser.cxx.

193 {}

◆ elementLoop() [2/2]

virtual void XercesParser::elementLoop ( AGDDController c,
xercesc::DOMNode *   
)
overridevirtual

Implements IAGDDParser.

◆ Finalize()

bool XercesParser::Finalize ( )

Definition at line 243 of file XercesParser.cxx.

244 {
245  XMLPlatformUtils::Terminate();
246  m_initialized=false;
247  return 0;
248 }

◆ Initialize()

bool XercesParser::Initialize ( )

Definition at line 227 of file XercesParser.cxx.

228 {
229  try {
231  }
232 
233  catch(const XMLException &toCatch) {
234  XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
235  << " Exception message:"
236  << XERCES_STD_QUALIFIER endl;
237  return 1;
238  }
239  m_initialized=true;
240  return 0;
241 }

◆ navigateTree()

void XercesParser::navigateTree ( AGDDController c)
overridevirtual

Implements IAGDDParser.

Definition at line 180 of file XercesParser.cxx.

181 {
182  if (!m_doc) {
183  MsgStream log(Athena::getMessageSvc(), "XercesParser");
184  log<<MSG::WARNING<<"navigateTree() - something is wrong! no document set! doing nothing!"<<endmsg;
185  return;
186  }
187  DOMNode* node = 0;
188  node = dynamic_cast<DOMNode*>(m_doc->getDocumentElement());
189  if( !node ) std::abort();
190  elementLoop(c, node);
191 }

◆ ParseFile()

bool XercesParser::ParseFile ( const std::string &  s_in)
overridevirtual

Implements IAGDDParser.

Definition at line 45 of file XercesParser.cxx.

46 {
47  bool errorsOccured = false;
48  m_fileName=s_in;
49  std::string s=PathResolver::find_file(s_in,"XMLPATH",PathResolver::RecursiveSearch);
50  if (s.empty()) {
51  MsgStream log(Athena::getMessageSvc(), "XercesParser");
52  log<<MSG::WARNING<<"ParseFile() - something wrong, could not find XML file "<<s<<endmsg;
53  errorsOccured = true;
54  }
55  else
56  {
57  if (!m_initialized) Initialize();
58  m_parser = new XercesDOMParser;
59  try
60  {
61  m_parser->parse(s.c_str());
62  }
63  catch (const OutOfMemoryException&)
64  {
65  XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
66  errorsOccured = true;
67  }
68  catch (const XMLException& e)
69  {
70  XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n Message: "
71  << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
72  errorsOccured = true;
73  }
74  catch (const DOMException& e)
75  {
76  const unsigned int maxChars = 2047;
77  XMLCh errText[maxChars + 1];
78 
79  XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << s << "'\n"
80  << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
81 
82  if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
83  XERCES_STD_QUALIFIER cerr << "Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
84 
85  errorsOccured = true;
86  }
87  catch (...)
88  {
89  XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
90  errorsOccured = true;
91  }
92  m_doc=m_parser->getDocument();
93  return errorsOccured;
94  }
95  return errorsOccured;
96 }

◆ ParseFileAndNavigate()

bool XercesParser::ParseFileAndNavigate ( AGDDController c,
const std::string &  s 
)
overridevirtual

Implements IAGDDParser.

Definition at line 97 of file XercesParser.cxx.

99 {
100  bool errorOccured = ParseFile(s);
101  if (errorOccured) return false;
102  navigateTree(c);
103  return true;
104 }

◆ ParseString()

bool XercesParser::ParseString ( const std::string &  s)
overridevirtual

Implements IAGDDParser.

Definition at line 105 of file XercesParser.cxx.

106 {
107  const char* str=s.c_str();
108  MemBufInputSource memBuf ((const XMLByte*)str,strlen(str),"prodInfo",false);
109  m_parser = new XercesDOMParser;
110  bool errorsOccured = false;
111  if (!m_initialized) Initialize();
112  try
113  {
114  m_parser->parse(memBuf);
115  }
116  catch (const OutOfMemoryException&)
117  {
118  XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
119  errorsOccured = true;
120  }
121  catch (const XMLException& e)
122  {
123  XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n Message: "
124  << XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
125  errorsOccured = true;
126  }
127  catch (const DOMException& e)
128  {
129  const unsigned int maxChars = 2047;
130  XMLCh errText[maxChars + 1];
131 
132  XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << s << "'\n"
133  << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
134 
135  if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
136  XERCES_STD_QUALIFIER cerr << "Message is: " << XMLString::transcode(errText) << XERCES_STD_QUALIFIER endl;
137 
138  errorsOccured = true;
139  }
140  catch (...)
141  {
142  XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
143  errorsOccured = true;
144  }
145  m_doc=m_parser->getDocument();
146  return errorsOccured;
147 }

◆ ParseStringAndNavigate()

bool XercesParser::ParseStringAndNavigate ( AGDDController c,
const std::string &  s 
)
overridevirtual

Implements IAGDDParser.

Definition at line 148 of file XercesParser.cxx.

150 {
151  bool errorOccured = ParseString(s);
152  if (!errorOccured) navigateTree(c);
153  return true;
154 }

◆ WriteToFile()

bool XercesParser::WriteToFile ( const std::string &  s)
overridevirtual

Implements IAGDDParser.

Definition at line 156 of file XercesParser.cxx.

157 {
158  XMLCh tempStr[100];
159  XMLString::transcode("LS 3.0 Core 2.0", tempStr, 99);
160  DOMImplementation* implementation = DOMImplementationRegistry::getDOMImplementation(tempStr);
161  DOMLSSerializer* serializer = ((DOMImplementationLS*)implementation)->createLSSerializer();
162  // if one wants a nicely indented file -- not in this case as it goes to the DB and be compressed
163  // DOMConfiguration* domconfig = serializer->getDomConfig();
164  // domconfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
165  XMLFormatTarget* target = new LocalFileFormatTarget(s.c_str());
166  DOMLSOutput* domoutput = ((DOMImplementationLS*)implementation)->createLSOutput();
167  // remove all comments
168  if( m_doc->getDOMConfig()->canSetParameter(XMLUni::fgDOMComments, true) ) m_doc->getDOMConfig()->setParameter(XMLUni::fgDOMComments, false);
169  m_doc->normalizeDocument();
170 
171  domoutput->setByteStream(target);
172  serializer->write(m_doc, domoutput);
173  domoutput->release();
174  serializer->release();
175  delete target;
176 
177  return true;
178 }

Member Data Documentation

◆ m_doc

xercesc::DOMDocument* XercesParser::m_doc
private

Definition at line 36 of file XercesParser.h.

◆ m_fileName

std::string IAGDDParser::m_fileName
protectedinherited

Definition at line 31 of file IAGDDParser.h.

◆ m_initialized

bool XercesParser::m_initialized
private

Definition at line 38 of file XercesParser.h.

◆ m_parser

xercesc::XercesDOMParser* XercesParser::m_parser
private

Definition at line 37 of file XercesParser.h.

◆ m_xs

XMLHandlerStore& XercesParser::m_xs
private

Definition at line 39 of file XercesParser.h.


The documentation for this class was generated from the following files:
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PathResolver::RecursiveSearch
@ RecursiveSearch
Definition: PathResolver.h:28
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
IAGDDParser::IAGDDParser
IAGDDParser()
Definition: IAGDDParser.h:17
XercesParser::m_initialized
bool m_initialized
Definition: XercesParser.h:38
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
XercesParser::navigateTree
virtual void navigateTree(AGDDController &c) override
Definition: XercesParser.cxx:180
IAGDDParser::m_fileName
std::string m_fileName
Definition: IAGDDParser.h:31
XercesParser::m_xs
XMLHandlerStore & m_xs
Definition: XercesParser.h:39
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
XercesParser::m_doc
xercesc::DOMDocument * m_doc
Definition: XercesParser.h:36
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
calibdata.implementation
implementation
Definition: calibdata.py:43
str
Definition: BTagTrackIpAccessor.cxx:11
XercesParser::Finalize
bool Finalize()
Definition: XercesParser.cxx:243
COOLRates.target
target
Definition: COOLRates.py:1106
XercesParser::elementLoop
virtual void elementLoop() override
Definition: XercesParser.cxx:193
XercesParser::m_parser
xercesc::XercesDOMParser * m_parser
Definition: XercesParser.h:37
XercesParser::ParseString
virtual bool ParseString(const std::string &) override
Definition: XercesParser.cxx:105
XercesParser::ParseFile
virtual bool ParseFile(const std::string &) override
Definition: XercesParser.cxx:45
python.compressB64.c
def c
Definition: compressB64.py:93
node
Definition: memory_hooks-stdcmalloc.h:74
XercesParser::Initialize
bool Initialize()
Definition: XercesParser.cxx:227