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