CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DDLSAX2FileHandler Class Reference

DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file. More...

#include <DDLSAX2FileHandler.h>

Inheritance diagram for DDLSAX2FileHandler:
DDLSAX2Handler DDLSAX2ExpressionHandler

Public Member Functions

void characters (const XMLCh *chars, XMLSize_t length) override
 
void comment (const XMLCh *chars, XMLSize_t length) override
 
void createDDConstants () const
 creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents More...
 
 DDLSAX2FileHandler (DDCompactView &cpv, DDLElementRegistry &)
 
void endElement (const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
 
void init ()
 
void startElement (const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
 
 ~DDLSAX2FileHandler () override
 
- Public Member Functions inherited from DDLSAX2Handler
void characters (const XMLCh *chars, XMLSize_t length) override
 
void comment (const XMLCh *chars, XMLSize_t length) override
 
 DDLSAX2Handler ()
 
virtual void dumpStats (const std::string &fname)
 
void endElement (const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
 
void error (const SAXParseException &exception) override
 
void fatalError (const SAXParseException &exception) override
 
unsigned int getAttrCount () const
 Get the count of attributes processed so far. More...
 
unsigned int getCharacterCount () const
 Get the count of characters processed so far. More...
 
unsigned int getElementCount () const
 Get the count of elements processed so far. More...
 
bool getSawErrors () const
 Did the XML parser see any errors? More...
 
unsigned int getSpaceCount () const
 Get the count of spaces processed so far. More...
 
void ignorableWhitespace (const XMLCh *chars, XMLSize_t length) override
 
void resetDocument () override
 
virtual void setNameSpace (const std::string &nms)
 
virtual void setUserNS (bool userns)
 
void startElement (const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
 
void warning (const SAXParseException &exception) override
 
 ~DDLSAX2Handler () override
 

Protected Member Functions

DDLElementRegistryregistry ()
 

Private Member Functions

virtual const std::string & parent () const
 
virtual const std::string & self () const
 

Private Attributes

DDCompactViewcpv_
 
std::vector< size_t > names_
 
std::vector< std::string > namesMap_
 
DDLElementRegistryregistry_
 

Additional Inherited Members

- Public Types inherited from DDLSAX2Handler
using Attributes = XERCES_CPP_NAMESPACE::Attributes
 
using SAXParseException = XERCES_CPP_NAMESPACE::SAXParseException
 
- Protected Attributes inherited from DDLSAX2Handler
XMLSize_t attrCount_
 
XMLSize_t characterCount_
 
XMLSize_t elementCount_
 
std::string nmspace_
 
bool sawErrors_
 
XMLSize_t spaceCount_
 
bool userNS_
 

Detailed Description

DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file.

Author
Michael Case

DDLSAX2FileHandler.h - description

begin: Tue Oct 23 2001

DDLSAX2FileHandler has the same structure as the DDLSAX2ConfigHandler as they both inherit from DDLSAX2Handler which inherits from Xerces C++ DefaultHandler. SAX2 is event driven. So, when the start of an element is encountered in the XML, then a call is made to the handler's startElement. The same for endElement.

The design of DDXMLElement allows for processing whichever type of Element the XML Parser encounters.

Definition at line 35 of file DDLSAX2FileHandler.h.

Constructor & Destructor Documentation

◆ DDLSAX2FileHandler()

DDLSAX2FileHandler::DDLSAX2FileHandler ( DDCompactView cpv,
DDLElementRegistry reg 
)

Definition at line 13 of file DDLSAX2FileHandler.cc.

13  : cpv_(cpv), registry_{reg} {
14  init();
15 }

◆ ~DDLSAX2FileHandler()

DDLSAX2FileHandler::~DDLSAX2FileHandler ( )
override

Definition at line 22 of file DDLSAX2FileHandler.cc.

22 {}

Member Function Documentation

◆ characters()

void DDLSAX2FileHandler::characters ( const XMLCh *  chars,
XMLSize_t  length 
)
override

Definition at line 84 of file DDLSAX2FileHandler.cc.

84  {
85  auto myElement = registry_.getElement(self());
86  std::string inString = "";
87  for (XMLSize_t i = 0; i < length; ++i) {
88  char s = chars[i];
89  inString = inString + s;
90  }
91  if (myElement->gotText())
92  myElement->appendText(inString);
93  else
94  myElement->loadText(inString);
95 }

References DDLElementRegistry::getElement(), mps_fire::i, registry_, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ comment()

void DDLSAX2FileHandler::comment ( const XMLCh *  chars,
XMLSize_t  length 
)
override

Definition at line 97 of file DDLSAX2FileHandler.cc.

97 {}

◆ createDDConstants()

void DDLSAX2FileHandler::createDDConstants ( void  ) const

creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents

Definition at line 99 of file DDLSAX2FileHandler.cc.

References DDConstant::createConstantsFromEvaluator(), DDLElementRegistry::evaluator(), and registry_.

Referenced by DDLParser::parse(), and DDLParser::parseOneFile().

◆ endElement()

void DDLSAX2FileHandler::endElement ( const XMLCh *  uri,
const XMLCh *  localname,
const XMLCh *  qname 
)
override

Definition at line 56 of file DDLSAX2FileHandler.cc.

56  {
57  std::string ts(cStr(qname).ptr());
58  const std::string& myElementName = self();
59 
60  auto myElement = registry_.getElement(myElementName);
61 
62  std::string nmspace = nmspace_;
63  // The need for processElement to have the nmspace so that it can
64  // do the necessary gymnastics made things more complicated in the
65  // effort to allow fully user-controlled namespaces. So the "magic"
66  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
67  // -- Michael Case 2008-11-06
68  // OPTIMISE in the near future, like the current nmspace_ impl.
69  // just set nmspace_ to "!" from Parser based on userNS_ so
70  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
71  if (userNS_) {
72  nmspace = "!";
73  }
74 
75  DDCurrentNamespace::ns() = nmspace;
76  // tell the element it's parent name for recording/reporting purposes
77  myElement->setParent(parent());
78  myElement->setSelf(self());
79  myElement->processElement(myElementName, nmspace, cpv_);
80 
81  names_.pop_back();
82 }

References cpv_, cms::xerces::cStr(), DDLElementRegistry::getElement(), names_, DDLSAX2Handler::nmspace_, DDCurrentNamespace::ns(), parent(), registry_, AlCaHLTBitMon_QueryRunRegistry::string, and DDLSAX2Handler::userNS_.

◆ init()

void DDLSAX2FileHandler::init ( void  )

Definition at line 17 of file DDLSAX2FileHandler.cc.

17  {
18  namesMap_.emplace_back("*** root ***");
19  names_.emplace_back(namesMap_.size() - 1);
20 }

References names_, and namesMap_.

◆ parent()

const std::string & DDLSAX2FileHandler::parent ( void  ) const
privatevirtual

Definition at line 103 of file DDLSAX2FileHandler.cc.

103  {
104  if (names_.size() > 2) {
105  return namesMap_.at(names_.at(names_.size() - 2));
106  }
107  return namesMap_[0]; //.at(names_.at(0));
108 }

References names_, and namesMap_.

Referenced by endElement().

◆ registry()

DDLElementRegistry& DDLSAX2FileHandler::registry ( )
inlineprotected

Definition at line 55 of file DDLSAX2FileHandler.h.

55 { return registry_; }

References registry_.

Referenced by DDLSAX2ExpressionHandler::startElement().

◆ self()

const std::string & DDLSAX2FileHandler::self ( void  ) const
privatevirtual

Definition at line 110 of file DDLSAX2FileHandler.cc.

110  {
111  if (names_.size() > 1) {
112  return namesMap_.at(names_.at(names_.size() - 1));
113  }
114  return namesMap_[0]; //.at(names_.at(0));
115 }

References names_, and namesMap_.

Referenced by crabFunctions.CrabTask::update().

◆ startElement()

void DDLSAX2FileHandler::startElement ( const XMLCh *  uri,
const XMLCh *  localname,
const XMLCh *  qname,
const Attributes attrs 
)
override

Definition at line 24 of file DDLSAX2FileHandler.cc.

27  {
28  std::string myElementName(cStr(qname).ptr());
29  size_t i = 0;
30  for (; i < namesMap_.size(); ++i) {
31  if (myElementName == namesMap_.at(i)) {
32  names_.emplace_back(i);
33  break;
34  }
35  }
36  if (i >= namesMap_.size()) {
37  namesMap_.emplace_back(myElementName);
38  names_.emplace_back(namesMap_.size() - 1);
39  }
40 
41  auto myElement = registry_.getElement(myElementName);
42 
43  unsigned int numAtts = attrs.getLength();
44  std::vector<std::string> attrNames, attrValues;
45 
46  for (unsigned int i = 0; i < numAtts; ++i) {
47  attrNames.emplace_back(std::string(cStr(attrs.getLocalName(i)).ptr()));
48  attrValues.emplace_back(std::string(cStr(attrs.getValue(i)).ptr()));
49  }
50 
51  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
52  // initialize text
53  myElement->loadText(std::string());
54 }

References cpv_, cms::xerces::cStr(), DDLElementRegistry::getElement(), mps_fire::i, names_, namesMap_, DDLSAX2Handler::nmspace_, registry_, and AlCaHLTBitMon_QueryRunRegistry::string.

Member Data Documentation

◆ cpv_

DDCompactView& DDLSAX2FileHandler::cpv_
private

Definition at line 64 of file DDLSAX2FileHandler.h.

Referenced by endElement(), and startElement().

◆ names_

std::vector<size_t> DDLSAX2FileHandler::names_
private

Definition at line 63 of file DDLSAX2FileHandler.h.

Referenced by endElement(), init(), parent(), self(), and startElement().

◆ namesMap_

std::vector<std::string> DDLSAX2FileHandler::namesMap_
private

Definition at line 62 of file DDLSAX2FileHandler.h.

Referenced by init(), parent(), self(), and startElement().

◆ registry_

DDLElementRegistry& DDLSAX2FileHandler::registry_
private
mps_fire.i
i
Definition: mps_fire.py:428
DDLSAX2FileHandler::cpv_
DDCompactView & cpv_
Definition: DDLSAX2FileHandler.h:64
cms::xerces::cStr
ZStr< char > cStr(XMLCh const *str)
Definition: XercesStrUtils.h:33
DDLElementRegistry::evaluator
ClhepEvaluator & evaluator()
Definition: DDLElementRegistry.h:42
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DDLSAX2FileHandler::init
void init()
Definition: DDLSAX2FileHandler.cc:17
DDLSAX2Handler::userNS_
bool userNS_
Definition: DDLSAX2Handler.h:85
DDLSAX2Handler::nmspace_
std::string nmspace_
Definition: DDLSAX2Handler.h:86
DDLSAX2FileHandler::parent
virtual const std::string & parent() const
Definition: DDLSAX2FileHandler.cc:103
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDLSAX2FileHandler::namesMap_
std::vector< std::string > namesMap_
Definition: DDLSAX2FileHandler.h:62
DDLElementRegistry::getElement
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
Definition: DDLElementRegistry.cc:43
DDCurrentNamespace::ns
static std::string & ns()
Definition: DDCurrentNamespace.cc:3
DDLSAX2FileHandler::names_
std::vector< size_t > names_
Definition: DDLSAX2FileHandler.h:63
DDLSAX2FileHandler::registry_
DDLElementRegistry & registry_
Definition: DDLSAX2FileHandler.h:65
DDConstant::createConstantsFromEvaluator
static void createConstantsFromEvaluator(ClhepEvaluator &)
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:27