CMS 3D CMS Logo

DDLSAX2FileHandler.cc
Go to the documentation of this file.
6 
7 using namespace cms::xerces;
8 
9 class DDCompactView;
10 
11 // XERCES_CPP_NAMESPACE_USE
12 
14  : cpv_(cpv)
15 {
16  init();
17 }
18 
19 void
21 {
23  namesMap_.push_back("*** root ***");
24  names_.push_back(namesMap_.size() - 1);
25 }
26 
28 {}
29 
30 void
31 DDLSAX2FileHandler::startElement( const XMLCh* const uri,
32  const XMLCh* const localname,
33  const XMLCh* const qname,
34  const Attributes& attrs )
35 {
36  std::string myElementName(cStr(qname).ptr());
37  size_t i = 0;
38  for (; i < namesMap_.size(); ++i) {
39  if ( myElementName == namesMap_.at(i) ) {
40  names_.push_back(i);
41  break;
42  }
43  }
44  if (i >= namesMap_.size()) {
45  namesMap_.push_back(myElementName);
46  names_.push_back(namesMap_.size() - 1);
47  }
48 
49  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
50 
51  unsigned int numAtts = attrs.getLength();
52  std::vector<std::string> attrNames, attrValues;
53 
54  for (unsigned int i = 0; i < numAtts; ++i)
55  {
56  attrNames.push_back(std::string(cStr(attrs.getLocalName(i)).ptr()));
57  attrValues.push_back(std::string(cStr(attrs.getValue(i)).ptr()));
58  }
59 
60  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
61  // initialize text
62  myElement->loadText(std::string());
63 }
64 
65 void
66 DDLSAX2FileHandler::endElement( const XMLCh* const uri,
67  const XMLCh* const localname,
68  const XMLCh* const qname )
69 {
70  std::string ts(cStr(qname).ptr());
71  const std::string& myElementName = self();
72 
73  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName);
74 
75  std::string nmspace = nmspace_;
76  // The need for processElement to have the nmspace so that it can
77  // do the necessary gymnastics made things more complicated in the
78  // effort to allow fully user-controlled namespaces. So the "magic"
79  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
80  // -- Michael Case 2008-11-06
81  // OPTIMISE in the near future, like the current nmspace_ impl.
82  // just set nmspace_ to "!" from Parser based on userNS_ so
83  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
84  if ( userNS_ ) {
85  nmspace = "!";
86  }
87 
88  DDCurrentNamespace::ns() = nmspace;
89  // tell the element it's parent name for recording/reporting purposes
90  myElement->setParent(parent());
91  myElement->setSelf(self());
92  myElement->processElement(myElementName, nmspace, cpv_);
93 
94  names_.pop_back();
95 }
96 
97 void
98 DDLSAX2FileHandler::characters( const XMLCh* const chars,
99  const XMLSize_t length )
100 {
101  DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(self());
102  std::string inString = "";
103  for (XMLSize_t i = 0; i < length; ++i)
104  {
105  char s = chars[i];
106  inString = inString + s;
107  }
108  if (myElement->gotText())
109  myElement->appendText(inString);
110  else
111  myElement->loadText(inString);
112 }
113 
114 void
115 DDLSAX2FileHandler::comment( const XMLCh* const chars,
116  const XMLSize_t length )
117 {}
118 
119 void
121 {
123 }
124 
125 const std::string&
127 {
128  if (names_.size() > 2)
129  {
130  return namesMap_.at(names_.at(names_.size() - 2));
131  }
132  return namesMap_[0];//.at(names_.at(0));
133 }
134 
135 const std::string&
137 {
138  if (names_.size() > 1) {
139  return namesMap_.at(names_.at(names_.size() - 1));
140  }
141  return namesMap_[0];//.at(names_.at(0));
142 }
int i
Definition: DBlmapReader.cc:9
DDLSAX2FileHandler(DDCompactView &cpv)
virtual const std::string & parent() const
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
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()
std::vector< std::string > namesMap_
type of data representation of DDCompactView
Definition: DDCompactView.h:90
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.
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:36
void comment(const XMLCh *const chars, const XMLSize_t length) override
ZStr< char > cStr(XMLCh const *str)
std::string nmspace_
void characters(const XMLCh *const chars, const XMLSize_t length) override
virtual bool gotText(void) const
gotText()? kind of like gotMilk? Yes = text has already been encountered.
std::vector< size_t > names_
static void createConstantsFromEvaluator()
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:38
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDCompactView & cpv_
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) override
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...