CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLSAX2FileHandler.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLSAX2FileHandler.cc - description
3  -------------------
4  begin : Tue Oct 23 2001
5  email : case@ucdhep.ucdavis.edu
6 ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * *
12  ***************************************************************************/
13 
18 
22 
23 #include <iostream>
24 
25 // XERCES_CPP_NAMESPACE_USE
26 
28  : cpv_(cpv),
29  xmlelems_()
30 {
31  init();
32 }
33 
34 void
36 {
38  namesMap_.push_back("*** root ***");
39  names_.push_back(namesMap_.size() - 1);
40 }
41 
43 {}
44 
45 // ---------------------------------------------------------------------------
46 // DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
47 // ---------------------------------------------------------------------------
48 void
49 DDLSAX2FileHandler::startElement(const XMLCh* const uri
50  , const XMLCh* const localname
51  , const XMLCh* const qname
52  , const Attributes& attrs)
53 {
54  DCOUT_V('P', "DDLSAX2FileHandler::startElement started");
55 
56  std::string myElementName(StrX(qname).localForm());
57  size_t i = 0;
58  for (; i < namesMap_.size(); ++i) {
59  if ( myElementName == namesMap_.at(i) ) {
60  names_.push_back(i);
61  break;
62  }
63  }
64  if (i >= namesMap_.size()) {
65  namesMap_.push_back(myElementName);
66  names_.push_back(namesMap_.size() - 1);
67  }
68 
69  ++elementTypeCounter_[myElementName];
70  //final way
71  // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName);
72  //temporary way:
73  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
74 
75  unsigned int numAtts = attrs.getLength();
76  std::vector<std::string> attrNames, attrValues;
77 
78  for (unsigned int i = 0; i < numAtts; ++i)
79  {
80  // char* temp2 = XMLString::transcode(attrs.getLocalName(i));
81  // char* temp3 = XMLString::transcode(attrs.getValue(i));
82  attrNames.push_back(std::string(StrX(attrs.getLocalName(i)).localForm()));
83  attrValues.push_back(std::string(StrX(attrs.getValue(i)).localForm()));
84  // XMLString::release(&temp2);
85  // XMLString::release(&temp3);
86  }
87 
88  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
89  // initialize text
90  myElement->loadText(std::string());
91  DCOUT_V('P', "DDLSAX2FileHandler::startElement completed");
92 }
93 
94 void
95 DDLSAX2FileHandler::endElement( const XMLCh* const uri,
96  const XMLCh* const localname,
97  const XMLCh* const qname )
98 {
99  std::string ts(StrX(qname).localForm());
100  const std::string& myElementName = self();
101  DCOUT_V('P', "DDLSAX2FileHandler::endElement started");
102  DCOUT_V('P', " " + myElementName);
103  //final way
104  // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName);
105  //temporary way:
106  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
107 
108  // DDLParser* beingParsed = DDLParser::instance();
109  // std::string nmspace = getnmspace(extractFileName( beingParsed->getCurrFileName()));
110  std::string nmspace = nmspace_;
111  // The need for processElement to have the nmspace so that it can
112  // do the necessary gymnastics made things more complicated in the
113  // effort to allow fully user-controlled namespaces. So the "magic"
114  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
115  // -- Michael Case 2008-11-06
116  // OPTIMISE in the near future, like the current nmspace_ impl.
117  // just set nmspace_ to "!" from Parser based on userNS_ so
118  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
119  if ( userNS_ ) {
120  nmspace = "!";
121  }
122  // std::cout << "namespace " << nmspace_ << std::endl;
123  DDCurrentNamespace::ns() = nmspace;
124  // tell the element it's parent name for recording/reporting purposes
125  myElement->setParent(parent());
126  myElement->setSelf(self());
127  myElement->processElement(myElementName, nmspace, cpv_);
128  DCOUT_V('P', "DDLSAX2FileHandler::endElement completed");
129  names_.pop_back();
130 }
131 
132 void
133 DDLSAX2FileHandler::characters( const XMLCh* const chars,
134  const unsigned int length )
135 {
136  DCOUT_V('P', "DDLSAX2FileHandler::characters started");
137  // std::cout << "character handler started" << std::endl;
138  //DDXMLElement* myElement = NULL;
139  // final way
140  // myElement = xmlelems_.getElement(namesMap_[names_.back()]);
141  //temporary way:
142  // const std::string& myElementName = namesMap_[names_.back()];
143  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(self());//myElementName); //namesMap_[names_.back()]);
144  std::string inString = "";
145  for (unsigned int i = 0; i < length; ++i)
146  {
147  char s = chars[i];
148  inString = inString + s;
149  }
150  if (myElement->gotText())
151  myElement->appendText(inString);
152  else
153  myElement->loadText(inString);
154 
155  DCOUT_V('P', "DDLSAX2FileHandler::characters completed");
156 }
157 
158 void
159 DDLSAX2FileHandler::comment( const XMLCh* const chars
160  , const unsigned int length)
161 {
162  // ignore, discard, overkill since base class also has this...
163 }
164 
165 void
167 {}
168 
169 void
171 {
173 }
174 
175 const std::string&
177 {
178  if (names_.size() > 2)
179  {
180  return namesMap_.at(names_.at(names_.size() - 2));
181  }
182  return namesMap_[0];//.at(names_.at(0));
183 }
184 
185 const std::string&
187 {
188  if (names_.size() > 1) {
189  return namesMap_.at(names_.at(names_.size() - 1));
190  }
191  return namesMap_[0];//.at(names_.at(0));
192 }
int i
Definition: DBlmapReader.cc:9
DDLSAX2FileHandler(DDCompactView &cpv)
virtual const std::string & parent() const
void appendText(const std::string &inText)
append to the current (i.e. most recently added)
virtual const std::string & self() const
void setParent(const std::string &pename)
Set parent element name to central list of names.
virtual void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
static std::string & ns()
type of data representation of DDCompactView
Definition: DDCompactView.h:81
void loadText(const std::string &inText)
Used to load both text and XML comments into this object.
void setSelf(const std::string &sename)
Set self element name to central list of names.
void dumpElementTypeCounter()
This dumps some statistics on elements encountered in the file.
static value_type & instance()
void loadAttributes(const std::string &elemName, const std::vector< std::string > &names, const std::vector< std::string > &values, const std::string &nmspace, DDCompactView &cpv)
Load the element attributes.
Definition: DDXMLElement.cc:44
void characters(const XMLCh *const chars, const unsigned int length)
std::string nmspace_
void comment(const XMLCh *const chars, const unsigned int length)
virtual bool gotText(void) const
gotText()? kind of like gotMilk? Yes = text has already been encountered.
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
std::vector< std::string > namesMap_
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
std::vector< size_t > names_
def qname
Definition: asciidump.py:315
std::map< std::string, int > elementTypeCounter_
static void createConstantsFromEvaluator()
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:36
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:59
DDCompactView & cpv_
Definition: StrX.h:32
string s
Definition: asciidump.py:422
XERCES_CPP_NAMESPACE::Attributes Attributes
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)