CMS 3D CMS Logo

DDLSAX2Handler.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLSAX2Handler.cc  -  description
00003                              -------------------
00004     begin                : Mon Oct 22 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 // ---------------------------------------------------------------------------
00015 //  Includes
00016 // ---------------------------------------------------------------------------
00017 #include "DetectorDescription/Parser/interface/DDLSAX2Handler.h"
00018 #include "StrX.h"
00019 #include "DetectorDescription/Base/interface/DDException.h"
00020 
00021 // Xerces C++ dependencies
00022 #include <xercesc/sax2/Attributes.hpp>
00023 #include <xercesc/sax/SAXParseException.hpp>
00024 #include <xercesc/sax/SAXException.hpp>
00025 
00026 #include <iostream>
00027 #include <vector>
00028 #include <string>
00029 
00030 // CMSSW Framework Dependency
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032 
00033 // ---------------------------------------------------------------------------
00034 //  DDLSAX2Handler: Constructors and Destructor
00035 // ---------------------------------------------------------------------------
00036 DDLSAX2Handler::DDLSAX2Handler() :
00037 
00038   attrCount_(0)
00039   , characterCount_(0)
00040   , elementCount_(0)
00041   , spaceCount_(0)
00042   , sawErrors_(false)
00043 {
00044 
00045 }
00046 
00047 DDLSAX2Handler::~DDLSAX2Handler()
00048 {
00049 
00050 }
00051 
00052 // ---------------------------------------------------------------------------
00053 //  DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
00054 // ---------------------------------------------------------------------------
00055 
00056 void DDLSAX2Handler::startElement(const XMLCh* const uri
00057                                   , const XMLCh* const localname
00058                                   , const XMLCh* const qname
00059                                   , const Attributes& attrs)
00060 {
00061   ++elementCount_;
00062   attrCount_ += attrs.getLength();
00063 }
00064 
00065 void DDLSAX2Handler::endElement(const XMLCh* const uri
00066                                     , const XMLCh* const localname
00067                                     , const XMLCh* const qname)
00068 {
00069   // do nothing
00070 }
00071 
00072 
00073 void DDLSAX2Handler::characters(  const   XMLCh* const    chars
00074                                   , const unsigned int    length)
00075 {
00076   characterCount_ += length;
00077 }
00078 
00079 void DDLSAX2Handler::comment( const XMLCh *const chars, const unsigned int length )
00080 {
00081   // do nothing default..
00082 }
00083 
00084 void DDLSAX2Handler::ignorableWhitespace( const   XMLCh* const chars
00085                                           , const unsigned int length)
00086 {
00087   spaceCount_ += length;
00088 }
00089 
00090 void DDLSAX2Handler::resetDocument()
00091 {
00092   attrCount_ = 0;
00093   characterCount_ = 0;
00094   elementCount_ = 0;
00095   spaceCount_ = 0;
00096 }
00097 
00098 void DDLSAX2Handler::dumpStats(const std::string& fname)
00099 {
00100 
00101   std::cout << "DetectorDescription/Parser/interface/DDLSAX2Handler::dumpStats, file: " 
00102        << fname << " ("
00103        << getElementCount() << " elems, "
00104        << getAttrCount() << " attrs, "
00105        << getSpaceCount() << " spaces, "
00106        << getCharacterCount() << " chars)" << std::endl;
00107 
00108 }
00109 
00110 // ---------------------------------------------------------------------------
00111 //  DDLSAX2Handler: Overrides of the SAX ErrorHandler interface
00112 //  Implements ALL required by the Xerces ErrorHandler interface as of 2007-06-26.
00113 // ---------------------------------------------------------------------------
00114 void DDLSAX2Handler::error(const SAXParseException& e)
00115 {
00116   sawErrors_ = true;
00117   edm::LogError("DetectorDescription_Parser_DDLSAX2Handler") 
00118     << "\nError at file " << StrX(e.getSystemId())
00119     << ", line " << e.getLineNumber()
00120     << ", char " << e.getColumnNumber()
00121     << "\n  Message: " << StrX(e.getMessage()) << std::endl;
00122   //  throw DDException(std::string("Unrecoverable Error: ") + std::string(StrX(e.getMessage()).localForm()));     
00123 }
00124 
00125 void DDLSAX2Handler::fatalError(const SAXParseException& e)
00126 {
00127   sawErrors_ = true;
00128   edm::LogError("DetectorDescription_Parser_DDLSAX2Handler") 
00129     << "\nFatal Error at file " << StrX(e.getSystemId())
00130     << ", line " << e.getLineNumber()
00131     << ", char " << e.getColumnNumber()
00132     << "\n  Message: " 
00133     << StrX(e.getMessage()) << std::endl;
00134   throw DDException(std::string("DetectorDescription_Parser_Unrecoverable_Error_from_Xerces: "))
00135     << std::string(StrX(e.getMessage()).localForm())
00136     << " file: " << std::string(StrX(e.getSystemId()).localForm())
00137     << " line: " << e.getLineNumber() << " col: " << e.getColumnNumber();
00138 }
00139 
00140 void DDLSAX2Handler::warning(const SAXParseException& e)
00141 {
00142   edm::LogWarning("DetectorDescription_Parser_DDLSAX2Handler") 
00143     << "\nWarning at file " << StrX(e.getSystemId())
00144     << ", line " << e.getLineNumber()
00145     << ", char " << e.getColumnNumber()
00146     << "\n  Message: " << StrX(e.getMessage()) << std::endl;
00147 }
00148 
00149 std::string DDLSAX2Handler::getnmspace(const std::string& fname)
00150 {
00151   size_t j = 0;
00152   std::string ret="";
00153   while (j < fname.size() && fname[j] != '.')
00154     ++j;
00155   if (j < fname.size() && fname[j] == '.')
00156     ret = fname.substr(0, j);
00157   return ret;
00158 }

Generated on Tue Jun 9 17:32:24 2009 for CMSSW by  doxygen 1.5.4