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 
17 
21 
22 #include <iostream>
23 
24 // XERCES_CPP_NAMESPACE_USE
25 
27  : cpv_(cpv),
28  xmlelems_()
29 {
30  init();
31 }
32 
33 void
35 {
37  namesMap_.push_back("*** root ***");
38  names_.push_back(namesMap_.size() - 1);
39 }
40 
42 {}
43 
44 // ---------------------------------------------------------------------------
45 // DDLSAX2Handler: Implementation of the SAX DocumentHandler interface
46 // ---------------------------------------------------------------------------
47 void
48 DDLSAX2FileHandler::startElement(const XMLCh* const uri
49  , const XMLCh* const localname
50  , const XMLCh* const qname
51  , const Attributes& attrs)
52 {
53  DCOUT_V('P', "DDLSAX2FileHandler::startElement started");
54 
55  std::string myElementName(StrX(qname).localForm());
56  size_t i = 0;
57  for (; i < namesMap_.size(); ++i) {
58  if ( myElementName == namesMap_.at(i) ) {
59  names_.push_back(i);
60  break;
61  }
62  }
63  if (i >= namesMap_.size()) {
64  namesMap_.push_back(myElementName);
65  names_.push_back(namesMap_.size() - 1);
66  }
67 
68  ++elementTypeCounter_[myElementName];
69  //final way
70  // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName);
71  //temporary way:
72  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
73 
74  unsigned int numAtts = attrs.getLength();
75  std::vector<std::string> attrNames, attrValues;
76 
77  for (unsigned int i = 0; i < numAtts; ++i)
78  {
79  // char* temp2 = XMLString::transcode(attrs.getLocalName(i));
80  // char* temp3 = XMLString::transcode(attrs.getValue(i));
81  attrNames.push_back(std::string(StrX(attrs.getLocalName(i)).localForm()));
82  attrValues.push_back(std::string(StrX(attrs.getValue(i)).localForm()));
83  // XMLString::release(&temp2);
84  // XMLString::release(&temp3);
85  }
86 
87  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
88  // initialize text
89  myElement->loadText(std::string());
90  DCOUT_V('P', "DDLSAX2FileHandler::startElement completed");
91 }
92 
93 void
94 DDLSAX2FileHandler::endElement( const XMLCh* const uri,
95  const XMLCh* const localname,
96  const XMLCh* const qname )
97 {
98  std::string ts(StrX(qname).localForm());
99  const std::string& myElementName = self();
100  DCOUT_V('P', "DDLSAX2FileHandler::endElement started");
101  DCOUT_V('P', " " + myElementName);
102  //final way
103  // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName);
104  //temporary way:
105  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
106 
107  // DDLParser* beingParsed = DDLParser::instance();
108  // std::string nmspace = getnmspace(extractFileName( beingParsed->getCurrFileName()));
109  std::string nmspace = nmspace_;
110  // The need for processElement to have the nmspace so that it can
111  // do the necessary gymnastics made things more complicated in the
112  // effort to allow fully user-controlled namespaces. So the "magic"
113  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
114  // -- Michael Case 2008-11-06
115  // OPTIMISE in the near future, like the current nmspace_ impl.
116  // just set nmspace_ to "!" from Parser based on userNS_ so
117  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
118  if ( userNS_ ) {
119  nmspace = "!";
120  }
121  // std::cout << "namespace " << nmspace_ << std::endl;
122  DDCurrentNamespace::ns() = nmspace;
123  // tell the element it's parent name for recording/reporting purposes
124  myElement->setParent(parent());
125  myElement->setSelf(self());
126  myElement->processElement(myElementName, nmspace, cpv_);
127  DCOUT_V('P', "DDLSAX2FileHandler::endElement completed");
128  names_.pop_back();
129 }
130 
131 void
132 DDLSAX2FileHandler::characters( const XMLCh* const chars,
133  const unsigned int length )
134 {
135  DCOUT_V('P', "DDLSAX2FileHandler::characters started");
136  // std::cout << "character handler started" << std::endl;
137  //DDXMLElement* myElement = NULL;
138  // final way
139  // myElement = xmlelems_.getElement(namesMap_[names_.back()]);
140  //temporary way:
141  // const std::string& myElementName = namesMap_[names_.back()];
142  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(self());//myElementName); //namesMap_[names_.back()]);
143  std::string inString = "";
144  for (unsigned int i = 0; i < length; ++i)
145  {
146  char s = chars[i];
147  inString = inString + s;
148  }
149  if (myElement->gotText())
150  myElement->appendText(inString);
151  else
152  myElement->loadText(inString);
153 
154  DCOUT_V('P', "DDLSAX2FileHandler::characters completed");
155 }
156 
157 void
158 DDLSAX2FileHandler::comment( const XMLCh* const chars
159  , const unsigned int length)
160 {
161  // ignore, discard, overkill since base class also has this...
162 }
163 
164 void
166 {}
167 
168 void
170 {
172 }
173 
174 const std::string&
176 {
177  if (names_.size() > 2)
178  {
179  return namesMap_.at(names_.at(names_.size() - 2));
180  }
181  return namesMap_[0];//.at(names_.at(0));
182 }
183 
184 const std::string&
186 {
187  if (names_.size() > 1) {
188  return namesMap_.at(names_.at(names_.size() - 1));
189  }
190  return namesMap_[0];//.at(names_.at(0));
191 }
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:77
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:41
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:34
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
DDCompactView & cpv_
Definition: StrX.h:32
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)