Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "DetectorDescription/Parser/interface/DDLSAX2FileHandler.h"
00015 #include "DetectorDescription/Parser/src/StrX.h"
00016 #include "DetectorDescription/Parser/src/DDXMLElement.h"
00017
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 #include "DetectorDescription/Core/interface/DDConstant.h"
00020 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00021
00022 #include <iostream>
00023
00024
00025
00026 DDLSAX2FileHandler::DDLSAX2FileHandler( DDCompactView & cpv )
00027 : cpv_(cpv),
00028 xmlelems_()
00029 {
00030 init();
00031 }
00032
00033 void
00034 DDLSAX2FileHandler::init( void )
00035 {
00036 createDDConstants();
00037 namesMap_.push_back("*** root ***");
00038 names_.push_back(namesMap_.size() - 1);
00039 }
00040
00041 DDLSAX2FileHandler::~DDLSAX2FileHandler( void )
00042 {}
00043
00044
00045
00046
00047 void
00048 DDLSAX2FileHandler::startElement(const XMLCh* const uri
00049 , const XMLCh* const localname
00050 , const XMLCh* const qname
00051 , const Attributes& attrs)
00052 {
00053 DCOUT_V('P', "DDLSAX2FileHandler::startElement started");
00054
00055 std::string myElementName(StrX(qname).localForm());
00056 size_t i = 0;
00057 for (; i < namesMap_.size(); ++i) {
00058 if ( myElementName == namesMap_.at(i) ) {
00059 names_.push_back(i);
00060 break;
00061 }
00062 }
00063 if (i >= namesMap_.size()) {
00064 namesMap_.push_back(myElementName);
00065 names_.push_back(namesMap_.size() - 1);
00066 }
00067
00068 ++elementTypeCounter_[myElementName];
00069
00070
00071
00072 DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
00073
00074 unsigned int numAtts = attrs.getLength();
00075 std::vector<std::string> attrNames, attrValues;
00076
00077 for (unsigned int i = 0; i < numAtts; ++i)
00078 {
00079
00080
00081 attrNames.push_back(std::string(StrX(attrs.getLocalName(i)).localForm()));
00082 attrValues.push_back(std::string(StrX(attrs.getValue(i)).localForm()));
00083
00084
00085 }
00086
00087 myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
00088
00089 myElement->loadText(std::string());
00090 DCOUT_V('P', "DDLSAX2FileHandler::startElement completed");
00091 }
00092
00093 void
00094 DDLSAX2FileHandler::endElement( const XMLCh* const uri,
00095 const XMLCh* const localname,
00096 const XMLCh* const qname )
00097 {
00098 std::string ts(StrX(qname).localForm());
00099 const std::string& myElementName = self();
00100 DCOUT_V('P', "DDLSAX2FileHandler::endElement started");
00101 DCOUT_V('P', " " + myElementName);
00102
00103
00104
00105 DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
00106
00107
00108
00109 std::string nmspace = nmspace_;
00110
00111
00112
00113
00114
00115
00116
00117
00118 if ( userNS_ ) {
00119 nmspace = "!";
00120 }
00121
00122 DDCurrentNamespace::ns() = nmspace;
00123
00124 myElement->setParent(parent());
00125 myElement->setSelf(self());
00126 myElement->processElement(myElementName, nmspace, cpv_);
00127 DCOUT_V('P', "DDLSAX2FileHandler::endElement completed");
00128 names_.pop_back();
00129 }
00130
00131 void
00132 DDLSAX2FileHandler::characters( const XMLCh* const chars,
00133 const unsigned int length )
00134 {
00135 DCOUT_V('P', "DDLSAX2FileHandler::characters started");
00136
00137
00138
00139
00140
00141
00142 DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(self());
00143 std::string inString = "";
00144 for (unsigned int i = 0; i < length; ++i)
00145 {
00146 char s = chars[i];
00147 inString = inString + s;
00148 }
00149 if (myElement->gotText())
00150 myElement->appendText(inString);
00151 else
00152 myElement->loadText(inString);
00153
00154 DCOUT_V('P', "DDLSAX2FileHandler::characters completed");
00155 }
00156
00157 void
00158 DDLSAX2FileHandler::comment( const XMLCh* const chars
00159 , const unsigned int length)
00160 {
00161
00162 }
00163
00164 void
00165 DDLSAX2FileHandler::dumpElementTypeCounter( void )
00166 {}
00167
00168 void
00169 DDLSAX2FileHandler::createDDConstants( void ) const
00170 {
00171 DDConstant::createConstantsFromEvaluator();
00172 }
00173
00174 const std::string&
00175 DDLSAX2FileHandler::parent( void ) const
00176 {
00177 if (names_.size() > 2)
00178 {
00179 return namesMap_.at(names_.at(names_.size() - 2));
00180 }
00181 return namesMap_[0];
00182 }
00183
00184 const std::string&
00185 DDLSAX2FileHandler::self( void ) const
00186 {
00187 if (names_.size() > 1) {
00188 return namesMap_.at(names_.at(names_.size() - 1));
00189 }
00190 return namesMap_[0];
00191 }