DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file. More...
#include <DDLSAX2FileHandler.h>
Public Member Functions | |
void | characters (const XMLCh *const chars, const unsigned int length) |
void | comment (const XMLCh *const chars, const unsigned int length) |
DDLSAX2FileHandler (DDCompactView &cpv) | |
void | dumpElementTypeCounter () |
This dumps some statistics on elements encountered in the file. | |
void | endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) |
void | init () |
virtual const std::string & | parent () const |
virtual const std::string & | self () const |
void | startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) |
~DDLSAX2FileHandler () | |
Protected Member Functions | |
void | createDDConstants () const |
creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents | |
Protected Attributes | |
DDCompactView & | cpv_ |
std::map< std::string, int > | elementTypeCounter_ |
std::vector< size_t > | names_ |
std::vector< std::string > | namesMap_ |
DDLElementRegistry | xmlelems_ |
DDLSAX2FileHandler is the SAX2 Handler for XML files found in the configuration file.
DDLSAX2FileHandler.h - description ------------------- begin: Tue Oct 23 2001 email: case@ucdhep.ucdavis.edu
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 40 of file DDLSAX2FileHandler.h.
DDLSAX2FileHandler::DDLSAX2FileHandler | ( | DDCompactView & | cpv | ) |
DDLSAX2FileHandler::~DDLSAX2FileHandler | ( | void | ) |
Definition at line 41 of file DDLSAX2FileHandler.cc.
{}
void DDLSAX2FileHandler::characters | ( | const XMLCh *const | chars, |
const unsigned int | length | ||
) | [virtual] |
Reimplemented from DDLSAX2Handler.
Definition at line 132 of file DDLSAX2FileHandler.cc.
References DDXMLElement::appendText(), DCOUT_V, DDXMLElement::gotText(), i, instance, DDXMLElement::loadText(), and alignCSCRings::s.
{ DCOUT_V('P', "DDLSAX2FileHandler::characters started"); // std::cout << "character handler started" << std::endl; //DDXMLElement* myElement = NULL; // final way // myElement = xmlelems_.getElement(namesMap_[names_.back()]); //temporary way: // const std::string& myElementName = namesMap_[names_.back()]; DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(self());//myElementName); //namesMap_[names_.back()]); std::string inString = ""; for (unsigned int i = 0; i < length; ++i) { char s = chars[i]; inString = inString + s; } if (myElement->gotText()) myElement->appendText(inString); else myElement->loadText(inString); DCOUT_V('P', "DDLSAX2FileHandler::characters completed"); }
void DDLSAX2FileHandler::comment | ( | const XMLCh *const | chars, |
const unsigned int | length | ||
) | [virtual] |
Reimplemented from DDLSAX2Handler.
Definition at line 158 of file DDLSAX2FileHandler.cc.
{
// ignore, discard, overkill since base class also has this...
}
void DDLSAX2FileHandler::createDDConstants | ( | void | ) | const [protected] |
creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the documents
Definition at line 169 of file DDLSAX2FileHandler.cc.
References DDConstant::createConstantsFromEvaluator().
Referenced by init().
void DDLSAX2FileHandler::dumpElementTypeCounter | ( | void | ) |
This dumps some statistics on elements encountered in the file.
Definition at line 165 of file DDLSAX2FileHandler.cc.
Referenced by DDLParser::parse().
{}
void DDLSAX2FileHandler::endElement | ( | const XMLCh *const | uri, |
const XMLCh *const | localname, | ||
const XMLCh *const | qname | ||
) | [virtual] |
Reimplemented from DDLSAX2Handler.
Reimplemented in DDLSAX2ExpressionHandler.
Definition at line 94 of file DDLSAX2FileHandler.cc.
References cpv_, DCOUT_V, instance, names_, DDLSAX2Handler::nmspace_, DDCurrentNamespace::ns(), parent(), DDXMLElement::processElement(), DDXMLElement::setParent(), DDXMLElement::setSelf(), and DDLSAX2Handler::userNS_.
{ std::string ts(StrX(qname).localForm()); const std::string& myElementName = self(); DCOUT_V('P', "DDLSAX2FileHandler::endElement started"); DCOUT_V('P', " " + myElementName); //final way // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName); //temporary way: DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName); // DDLParser* beingParsed = DDLParser::instance(); // std::string nmspace = getnmspace(extractFileName( beingParsed->getCurrFileName())); std::string nmspace = nmspace_; // The need for processElement to have the nmspace so that it can // do the necessary gymnastics made things more complicated in the // effort to allow fully user-controlled namespaces. So the "magic" // trick of setting nmspace to "!" is used :(... I don't like this magic trick // -- Michael Case 2008-11-06 // OPTIMISE in the near future, like the current nmspace_ impl. // just set nmspace_ to "!" from Parser based on userNS_ so // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22 if ( userNS_ ) { nmspace = "!"; } // std::cout << "namespace " << nmspace_ << std::endl; DDCurrentNamespace::ns() = nmspace; // tell the element it's parent name for recording/reporting purposes myElement->setParent(parent()); myElement->setSelf(self()); myElement->processElement(myElementName, nmspace, cpv_); DCOUT_V('P', "DDLSAX2FileHandler::endElement completed"); names_.pop_back(); }
void DDLSAX2FileHandler::init | ( | void | ) |
Definition at line 34 of file DDLSAX2FileHandler.cc.
References createDDConstants(), names_, and namesMap_.
Referenced by DDLSAX2FileHandler().
{ createDDConstants(); namesMap_.push_back("*** root ***"); names_.push_back(namesMap_.size() - 1); }
const std::string & DDLSAX2FileHandler::parent | ( | void | ) | const [virtual] |
Definition at line 175 of file DDLSAX2FileHandler.cc.
References names_, and namesMap_.
Referenced by endElement().
const std::string & DDLSAX2FileHandler::self | ( | void | ) | const [virtual] |
void DDLSAX2FileHandler::startElement | ( | const XMLCh *const | uri, |
const XMLCh *const | localname, | ||
const XMLCh *const | qname, | ||
const Attributes & | attrs | ||
) | [virtual] |
Reimplemented from DDLSAX2Handler.
Reimplemented in DDLSAX2ExpressionHandler.
Definition at line 48 of file DDLSAX2FileHandler.cc.
References cpv_, DCOUT_V, elementTypeCounter_, i, instance, DDXMLElement::loadAttributes(), DDXMLElement::loadText(), names_, namesMap_, and DDLSAX2Handler::nmspace_.
{ DCOUT_V('P', "DDLSAX2FileHandler::startElement started"); std::string myElementName(StrX(qname).localForm()); size_t i = 0; for (; i < namesMap_.size(); ++i) { if ( myElementName == namesMap_.at(i) ) { names_.push_back(i); break; } } if (i >= namesMap_.size()) { namesMap_.push_back(myElementName); names_.push_back(namesMap_.size() - 1); } ++elementTypeCounter_[myElementName]; //final way // DDXMLElement* myElement = xmlelems_.getElement(myElementName); //myRegistry_->getElement(myElementName); //temporary way: DDXMLElement* myElement = DDLGlobalRegistry::instance().getElement(myElementName); unsigned int numAtts = attrs.getLength(); std::vector<std::string> attrNames, attrValues; for (unsigned int i = 0; i < numAtts; ++i) { // char* temp2 = XMLString::transcode(attrs.getLocalName(i)); // char* temp3 = XMLString::transcode(attrs.getValue(i)); attrNames.push_back(std::string(StrX(attrs.getLocalName(i)).localForm())); attrValues.push_back(std::string(StrX(attrs.getValue(i)).localForm())); // XMLString::release(&temp2); // XMLString::release(&temp3); } myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_); // initialize text myElement->loadText(std::string()); DCOUT_V('P', "DDLSAX2FileHandler::startElement completed"); }
DDCompactView& DDLSAX2FileHandler::cpv_ [protected] |
Definition at line 85 of file DDLSAX2FileHandler.h.
Referenced by endElement(), and startElement().
std::map< std::string, int> DDLSAX2FileHandler::elementTypeCounter_ [protected] |
Definition at line 82 of file DDLSAX2FileHandler.h.
Referenced by DDLSAX2ExpressionHandler::startElement(), and startElement().
std::vector< size_t > DDLSAX2FileHandler::names_ [protected] |
Definition at line 84 of file DDLSAX2FileHandler.h.
Referenced by endElement(), init(), parent(), self(), and startElement().
std::vector<std::string> DDLSAX2FileHandler::namesMap_ [protected] |
Definition at line 83 of file DDLSAX2FileHandler.h.
Referenced by init(), parent(), self(), and startElement().
DDLElementRegistry DDLSAX2FileHandler::xmlelems_ [protected] |
Definition at line 86 of file DDLSAX2FileHandler.h.