CMS 3D CMS Logo

DDLSAX2Handler.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 
8 using namespace cms::xerces;
9 
11  : attrCount_(0),
12  characterCount_(0),
13  elementCount_(0),
14  spaceCount_(0),
15  sawErrors_(false),
16  userNS_(false)
17 {}
18 
20 {}
21 
22 // ---------------------------------------------------------------------------
23 // DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
24 // ---------------------------------------------------------------------------
25 
26 void
27 DDLSAX2Handler::startElement( const XMLCh* const uri,
28  const XMLCh* const localname,
29  const XMLCh* const qname,
30  const Attributes& attrs )
31 {
32  ++elementCount_;
33  attrCount_ += attrs.getLength();
34 }
35 
36 void
37 DDLSAX2Handler::endElement( const XMLCh* const uri,
38  const XMLCh* const localname,
39  const XMLCh* const qname )
40 {
41  // do nothing
42 }
43 
44 void
45 DDLSAX2Handler::characters( const XMLCh* const chars,
46  const XMLSize_t length )
47 {
48  characterCount_ += length;
49 }
50 
51 void
52 DDLSAX2Handler::comment( const XMLCh *const chars, const XMLSize_t length )
53 {
54  // do nothing default..
55 }
56 
57 void
58 DDLSAX2Handler::ignorableWhitespace( const XMLCh* const chars,
59  const XMLSize_t length )
60 {
61  spaceCount_ += length;
62 }
63 
64 void
66 {
67  attrCount_ = 0;
68  characterCount_ = 0;
69  elementCount_ = 0;
70  spaceCount_ = 0;
71 }
72 
73 void
75 {
76  std::cout << "DetectorDescription/Parser/interface/DDLSAX2Handler::dumpStats, file: "
77  << fname << " ("
78  << getElementCount() << " elems, "
79  << getAttrCount() << " attrs, "
80  << getSpaceCount() << " spaces, "
81  << getCharacterCount() << " chars)" << std::endl;
82 }
83 
84 // ---------------------------------------------------------------------------
85 // DDLSAX2Handler: Overrides of the SAX ErrorHandler interface
86 // Implements ALL required by the Xerces ErrorHandler interface as of 2007-06-26.
87 // ---------------------------------------------------------------------------
88 void
90 {
91  sawErrors_ = true;
92  edm::LogError("DetectorDescription_Parser_DDLSAX2Handler")
93  << "\nError at file " << cStr(e.getSystemId()).ptr()
94  << ", line " << e.getLineNumber()
95  << ", char " << e.getColumnNumber()
96  << "\n Message: " << cStr(e.getMessage()).ptr() << std::endl;
97 }
98 
99 void
101 {
102  sawErrors_ = true;
103  edm::LogError("DetectorDescription_Parser_DDLSAX2Handler")
104  << "\nFatal Error at file " << cStr(e.getSystemId()).ptr()
105  << ", line " << e.getLineNumber()
106  << ", char " << e.getColumnNumber()
107  << "\n Message: "
108  << cStr(e.getMessage()).ptr() << std::endl;
109  throw cms::Exception("DDException") << "DetectorDescription_Parser_Unrecoverable_Error_from_Xerces: "
110  << toString(e.getMessage())
111  << " file: " << toString(e.getSystemId())
112  << " line: " << e.getLineNumber() << " col: " << e.getColumnNumber();
113 }
114 
115 void
117 {
118  edm::LogWarning("DetectorDescription_Parser_DDLSAX2Handler")
119  << "\nWarning at file " << cStr(e.getSystemId()).ptr()
120  << ", line " << e.getLineNumber()
121  << ", char " << e.getColumnNumber()
122  << "\n Message: " << cStr(e.getMessage()).ptr() << std::endl;
123 }
124 
125 void
127 {
128  userNS_ = userns;
129 }
130 
131 void
133 {
134  nmspace_ = nms;
135 }
~DDLSAX2Handler() override
void error(const SAXParseException &exception) override
unsigned int getAttrCount() const
Get the count of attributes processed so far.
XMLSize_t spaceCount_
XMLSize_t characterCount_
XMLSize_t attrCount_
XMLSize_t elementCount_
void fatalError(const SAXParseException &exception) override
void characters(const XMLCh *chars, XMLSize_t length) override
virtual void setUserNS(bool userns)
ZStr< char > cStr(XMLCh const *str)
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
std::string nmspace_
unsigned int getElementCount() const
Get the count of elements processed so far.
unsigned int getCharacterCount() const
Get the count of characters processed so far.
void comment(const XMLCh *chars, XMLSize_t length) override
unsigned int getSpaceCount() const
Get the count of spaces processed so far.
void endElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
void warning(const SAXParseException &exception) override
void resetDocument() override
string fname
main script
virtual void setNameSpace(const std::string &nms)
void ignorableWhitespace(const XMLCh *chars, XMLSize_t length) override
XERCES_CPP_NAMESPACE::Attributes Attributes
virtual void dumpStats(const std::string &fname)
XERCES_CPP_NAMESPACE::SAXParseException SAXParseException
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override