ATLAS Offline Software
Loading...
Searching...
No Matches
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
std::unique_ptr< xercesc::XercesDOMParser > m_parser
bool m_initialized
XMLHandlerStorem_xs

Detailed Description

Definition at line 19 of file XercesParser.h.

Constructor & Destructor Documentation

◆ XercesParser() [1/2]

XercesParser::XercesParser ( XMLHandlerStore & xs)

Definition at line 31 of file XercesParser.cxx.

32 : IAGDDParser(),m_doc(0),m_initialized(false),
33 m_xs(xs)
34{
35}
xercesc::DOMDocument * m_doc
XMLHandlerStore & m_xs

◆ XercesParser() [2/2]

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

Definition at line 37 of file XercesParser.cxx.

38 : IAGDDParser(s),m_doc(0),m_initialized(false),
39 m_xs(xs)
40{
41}

◆ ~XercesParser()

XercesParser::~XercesParser ( )
virtual

Definition at line 26 of file XercesParser.cxx.

27{
28 Finalize();
29}

Member Function Documentation

◆ elementLoop() [1/2]

void XercesParser::elementLoop ( )
overridevirtual

Implements IAGDDParser.

Definition at line 191 of file XercesParser.cxx.

191{}

◆ elementLoop() [2/2]

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

Implements IAGDDParser.

◆ Finalize()

bool XercesParser::Finalize ( )

Definition at line 241 of file XercesParser.cxx.

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

◆ Initialize()

bool XercesParser::Initialize ( )

Definition at line 225 of file XercesParser.cxx.

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

◆ navigateTree()

void XercesParser::navigateTree ( AGDDController & c)
overridevirtual

Implements IAGDDParser.

Definition at line 178 of file XercesParser.cxx.

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

◆ ParseFile()

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

Implements IAGDDParser.

Definition at line 43 of file XercesParser.cxx.

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

◆ ParseFileAndNavigate()

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

Implements IAGDDParser.

Definition at line 95 of file XercesParser.cxx.

97{
98 bool errorOccured = ParseFile(s);
99 if (errorOccured) return false;
100 navigateTree(c);
101 return true;
102}
virtual bool ParseFile(const std::string &) override
virtual void navigateTree(AGDDController &c) override

◆ ParseString()

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

Implements IAGDDParser.

Definition at line 103 of file XercesParser.cxx.

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

◆ ParseStringAndNavigate()

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

Implements IAGDDParser.

Definition at line 146 of file XercesParser.cxx.

148{
149 bool errorOccured = ParseString(s);
150 if (!errorOccured) navigateTree(c);
151 return true;
152}
virtual bool ParseString(const std::string &) override

◆ WriteToFile()

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

Implements IAGDDParser.

Definition at line 154 of file XercesParser.cxx.

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

Member Data Documentation

◆ m_doc

xercesc::DOMDocument* XercesParser::m_doc
private

Definition at line 37 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 39 of file XercesParser.h.

◆ m_parser

std::unique_ptr<xercesc::XercesDOMParser> XercesParser::m_parser
private

Definition at line 38 of file XercesParser.h.

◆ m_xs

XMLHandlerStore& XercesParser::m_xs
private

Definition at line 40 of file XercesParser.h.


The documentation for this class was generated from the following files: