Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:33

0001 #include "DetectorDescription/Parser/interface/DDLSAX2Handler.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0005 
0006 #include <iostream>
0007 
0008 using namespace cms::xerces;
0009 
0010 DDLSAX2Handler::DDLSAX2Handler(void)
0011     : attrCount_(0), characterCount_(0), elementCount_(0), spaceCount_(0), sawErrors_(false), userNS_(false) {}
0012 
0013 DDLSAX2Handler::~DDLSAX2Handler(void) {}
0014 
0015 // ---------------------------------------------------------------------------
0016 //  DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
0017 // ---------------------------------------------------------------------------
0018 
0019 void DDLSAX2Handler::startElement(const XMLCh* const uri,
0020                                   const XMLCh* const localname,
0021                                   const XMLCh* const qname,
0022                                   const Attributes& attrs) {
0023   ++elementCount_;
0024   attrCount_ += attrs.getLength();
0025 }
0026 
0027 void DDLSAX2Handler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) {
0028   // do nothing
0029 }
0030 
0031 void DDLSAX2Handler::characters(const XMLCh* const chars, const XMLSize_t length) { characterCount_ += length; }
0032 
0033 void DDLSAX2Handler::comment(const XMLCh* const chars, const XMLSize_t length) {
0034   // do nothing default..
0035 }
0036 
0037 void DDLSAX2Handler::ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length) { spaceCount_ += length; }
0038 
0039 void DDLSAX2Handler::resetDocument(void) {
0040   attrCount_ = 0;
0041   characterCount_ = 0;
0042   elementCount_ = 0;
0043   spaceCount_ = 0;
0044 }
0045 
0046 void DDLSAX2Handler::dumpStats(const std::string& fname) {
0047   std::cout << "DetectorDescription/Parser/interface/DDLSAX2Handler::dumpStats, file: " << fname << " ("
0048             << getElementCount() << " elems, " << getAttrCount() << " attrs, " << getSpaceCount() << " spaces, "
0049             << getCharacterCount() << " chars)" << std::endl;
0050 }
0051 
0052 // ---------------------------------------------------------------------------
0053 //  DDLSAX2Handler: Overrides of the SAX ErrorHandler interface
0054 //  Implements ALL required by the Xerces ErrorHandler interface as of 2007-06-26.
0055 // ---------------------------------------------------------------------------
0056 void DDLSAX2Handler::error(const SAXParseException& e) {
0057   sawErrors_ = true;
0058   edm::LogError("DetectorDescription_Parser_DDLSAX2Handler")
0059       << "\nError at file " << cStr(e.getSystemId()).ptr() << ", line " << e.getLineNumber() << ", char "
0060       << e.getColumnNumber() << "\n  Message: " << cStr(e.getMessage()).ptr() << std::endl;
0061 }
0062 
0063 void DDLSAX2Handler::fatalError(const SAXParseException& e) {
0064   sawErrors_ = true;
0065   edm::LogError("DetectorDescription_Parser_DDLSAX2Handler")
0066       << "\nFatal Error at file " << cStr(e.getSystemId()).ptr() << ", line " << e.getLineNumber() << ", char "
0067       << e.getColumnNumber() << "\n  Message: " << cStr(e.getMessage()).ptr() << std::endl;
0068   throw cms::Exception("DDException") << "DetectorDescription_Parser_Unrecoverable_Error_from_Xerces: "
0069                                       << toString(e.getMessage()) << " file: " << toString(e.getSystemId())
0070                                       << " line: " << e.getLineNumber() << " col: " << e.getColumnNumber();
0071 }
0072 
0073 void DDLSAX2Handler::warning(const SAXParseException& e) {
0074   edm::LogWarning("DetectorDescription_Parser_DDLSAX2Handler")
0075       << "\nWarning at file " << cStr(e.getSystemId()).ptr() << ", line " << e.getLineNumber() << ", char "
0076       << e.getColumnNumber() << "\n  Message: " << cStr(e.getMessage()).ptr() << std::endl;
0077 }
0078 
0079 void DDLSAX2Handler::setUserNS(bool userns) { userNS_ = userns; }
0080 
0081 void DDLSAX2Handler::setNameSpace(const std::string& nms) { nmspace_ = nms; }