CMS 3D CMS Logo

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