CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

XMLDOMBlock Class Reference

#include <CalibCalorimetry/HcalTPGAlgos/interface/XMLDOMBlock.h>

Inheritance diagram for XMLDOMBlock:
HcalChannelDataXml HcalHardwareXml HcalTriggerKey LMapLoader LutXml XMLHTRPatternLoader XMLHTRZeroSuppressionLoader XMLLUTLoader XMLRBXPedestalsLoader

List of all members.

Public Member Functions

DOMElement * add_element (DOMElement *parent, XMLCh *tagname, XMLCh *value)
DOMDocument * getDocument (void)
DOMDocument * getDocumentConst (void) const
DOMDocument * getNewDocument (std::string xmlFileName)
std::string & getString (void)
std::string & getString (DOMNode *_node)
const char * getTagAttribute (const std::string &tagName, const std::string &attrName, int _item=0)
const char * getTagValue (const std::string &tagName, int _item=0, DOMDocument *_document=NULL)
const char * getTagValue (const std::string &tagName, int _item, DOMElement *_document)
std::string getTimestamp (time_t _time)
XMLDOMBlockoperator+= (const XMLDOMBlock &other)
void parse (InputSource &_source)
DOMNode * setTagAttribute (DOMElement *_elem, const std::string &tagName, const std::string &attrName, const int &attrValue, int _item=0)
DOMNode * setTagAttribute (const std::string &tagName, const std::string &attrName, const std::string &attrValue, int _item=0)
DOMNode * setTagAttribute (DOMElement *_elem, const std::string &tagName, const std::string &attrName, const std::string &attrValue, int _item=0)
DOMNode * setTagAttribute (const std::string &tagName, const std::string &attrName, const int &attrValue, int _item=0)
DOMNode * setTagValue (const std::string &tagName, const std::string &tagValue, int _item=0, DOMDocument *_document=NULL)
DOMNode * setTagValue (DOMElement *_elem, const std::string &tagName, const std::string &tagValue, int _item=0)
DOMNode * setTagValue (const std::string &tagName, const int &tagValue, int _item=0, DOMDocument *_document=NULL)
DOMNode * setTagValue (DOMElement *_elem, const std::string &tagName, const int &tagValue, int _item=0)
int write (std::string target="stdout")
 XMLDOMBlock (InputSource &_source)
 XMLDOMBlock (std::string _root, int rootElementName)
 XMLDOMBlock (std::string xmlFileName)
 XMLDOMBlock ()
virtual ~XMLDOMBlock ()

Protected Member Functions

int init (std::string _root)

Protected Attributes

DOMDocument * document
ErrorHandler * errHandler
XercesDOMParser * parser
std::string * the_string
std::string theFileName
XMLProcessortheProcessor

Friends

class XMLProcessor

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 44 of file XMLDOMBlock.h.


Constructor & Destructor Documentation

XMLDOMBlock::XMLDOMBlock ( )

Definition at line 51 of file XMLDOMBlock.cc.

References init.

{
  //std::cout << "XMLDOMBlock (or derived): default constructor called - this is meaningless!" << std::endl;
  //std::cout << "XMLDOMBlock (or derived): use yourClass( loaderBaseConfig & ) instead." << std::endl;
  init( "ROOT" );
}
XMLDOMBlock::XMLDOMBlock ( std::string  xmlFileName)

Definition at line 210 of file XMLDOMBlock.cc.

References gather_cfg::cout, XMLProcessor::getInstance(), python::rootplot::argparse::message, geometryXMLtoCSV::parser, fetchall_from_DQM_v2::release, and BuildIsoConfigs::xmlFileName.

{
  //
  //_____ following removed as a xalan-c component_____________________
  //
  /*
  // xalan objects initialization
  theSourceTreeInit = 0;
  theDOMSupport = 0;
  theLiaison = 0;
  theInputSource = 0;
  theDocument = 0;
  thePrefixResolver = 0;
  theEvaluator = 0;
  */

  theProcessor = XMLProcessor::getInstance();

  theFileName = xmlFileName;

  // initialize the parser
  parser = new XercesDOMParser();
  parser->setValidationScheme(XercesDOMParser::Val_Always);    
  parser->setDoNamespaces(true);    // optional
  
  errHandler = (ErrorHandler*) new HandlerBase();
  parser->setErrorHandler(errHandler);

  // parse the input xml file
  try
    {
      parser->parse( theFileName . c_str() );
    }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (const DOMException& toCatch) {
    char* message = XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (...) {
    std::cout << "Unexpected Exception \n" ;
    //return -1;
  }

  //get the XML document
  document = parser -> getDocument();

}
XMLDOMBlock::XMLDOMBlock ( InputSource _source)

Definition at line 66 of file XMLDOMBlock.cc.

References gather_cfg::cout, XMLProcessor::getInstance(), python::rootplot::argparse::message, geometryXMLtoCSV::parser, and fetchall_from_DQM_v2::release.

{
  //
  //_____ following removed as a xalan-c component_____________________
  //
  /*
  // xalan objects initialization
  theSourceTreeInit = 0;
  theDOMSupport = 0;
  theLiaison = 0;
  theInputSource = 0;
  theDocument = 0;
  thePrefixResolver = 0;
  theEvaluator = 0;
  */

  theProcessor = XMLProcessor::getInstance();

  //theFileName = xmlFileName;

  // initialize the parser
  parser = new XercesDOMParser();
  parser->setValidationScheme(XercesDOMParser::Val_Always);    
  parser->setDoNamespaces(true);    // optional
  
  errHandler = (ErrorHandler*) new HandlerBase();
  parser->setErrorHandler(errHandler);

  // parse the input xml file
  try
    {
      parser->parse( _source );
    }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (const DOMException& toCatch) {
    char* message = XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (...) {
    std::cout << "Unexpected Exception \n" ;
    //return -1;
  }

  //get the XML document
  document = parser -> getDocument();
}
XMLDOMBlock::XMLDOMBlock ( std::string  _root,
int  rootElementName 
)

Definition at line 58 of file XMLDOMBlock.cc.

References init.

{
  //std::cout << "XMLDOMBlock (or derived): default constructor called - this is meaningless!" << std::endl;
  //std::cout << "XMLDOMBlock (or derived): use yourClass( loaderBaseConfig & ) instead." << std::endl;
  init( _root );
}
XMLDOMBlock::~XMLDOMBlock ( ) [virtual]

Definition at line 330 of file XMLDOMBlock.cc.

References geometryXMLtoCSV::parser.

{
  delete parser;
  delete errHandler;
  //if (the_string) delete the_string;

  //
  //_____ following removed as a xalan-c component_____________________
  //
  /*
  // delete xalan objects
  delete theSourceTreeInit;
  delete theDOMSupport;
  delete theLiaison;
  delete theInputSource;
  //delete theDocument; // noneed to delete - belongs to theLiaison
  delete thePrefixResolver;
  delete theEvaluator;
  */
}

Member Function Documentation

DOMElement * XMLDOMBlock::add_element ( DOMElement *  parent,
XMLCh *  tagname,
XMLCh *  value 
)

Definition at line 524 of file XMLDOMBlock.cc.

                                                                                        {
  DOMElement * _elem = document -> createElement( tagname );
  parent -> appendChild(_elem);
  DOMText * _value = document -> createTextNode(value);
  _elem->appendChild(_value);
  return _elem;
}
DOMDocument * XMLDOMBlock::getDocument ( void  )
DOMDocument * XMLDOMBlock::getDocumentConst ( void  ) const

Definition at line 318 of file XMLDOMBlock.cc.

Referenced by operator+=().

{
  return document;
}
DOMDocument * XMLDOMBlock::getNewDocument ( std::string  xmlFileName)

Definition at line 267 of file XMLDOMBlock.cc.

References gather_cfg::cout, XMLProcessor::getInstance(), python::rootplot::argparse::message, geometryXMLtoCSV::parser, fetchall_from_DQM_v2::release, and BuildIsoConfigs::xmlFileName.

{
  delete document;

  theProcessor = XMLProcessor::getInstance();

  theFileName = xmlFileName;

  // initialize the parser
  parser = new XercesDOMParser();
  parser->setValidationScheme(XercesDOMParser::Val_Always);    
  parser->setDoNamespaces(true);    // optional
  
  errHandler = (ErrorHandler*) new HandlerBase();
  parser->setErrorHandler(errHandler);

  // parse the input xml file
  try
    {
      parser->parse( theFileName . c_str() );
    }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (const DOMException& toCatch) {
    char* message = XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (...) {
    std::cout << "Unexpected Exception \n" ;
    //return -1;
  }

  //get the XML document
  document = parser -> getDocument();

  return document;
}
std::string & XMLDOMBlock::getString ( void  )

Definition at line 460 of file XMLDOMBlock.cc.

Referenced by LutXml::getCurrentBrick().

{
  return getString( this->getDocument() );
}
std::string & XMLDOMBlock::getString ( DOMNode *  _node)

Definition at line 468 of file XMLDOMBlock.cc.

{
  if (the_string) delete the_string;
  std::string _target = "string";
  the_string = new std::string( XMLString::transcode( theProcessor->serializeDOM(_node,_target) ) );
  return (*the_string);
}
const char * XMLDOMBlock::getTagAttribute ( const std::string &  tagName,
const std::string &  attrName,
int  _item = 0 
)

Definition at line 401 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

Referenced by XMLRBXPedestalsLoader::addRBXSlot().

{
  DOMElement * _tag = (DOMElement *)(document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item ));
  const char * _result = XMLString::transcode( _tag -> getAttribute( XMLProcessor::_toXMLCh( attrName ) ) );

  return _result;
}
const char * XMLDOMBlock::getTagValue ( const std::string &  tagName,
int  _item,
DOMElement *  _document 
)

Definition at line 358 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_document) return 0;
  const char * _result = XMLString::transcode( _document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item ) -> getFirstChild()-> getNodeValue() );
  return _result;
}
const char * XMLDOMBlock::getTagValue ( const std::string &  tagName,
int  _item = 0,
DOMDocument *  _document = NULL 
)

Definition at line 351 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

Referenced by XMLRBXPedestalsLoader::addRBXSlot().

{
  if (!_document) _document = document;
  const char * _result = XMLString::transcode( _document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item ) -> getFirstChild()-> getNodeValue() );
  return _result;
}
string XMLDOMBlock::getTimestamp ( time_t  _time)

Definition at line 447 of file XMLDOMBlock.cc.

{
  char timebuf[50];
  //strftime( timebuf, 50, "%c", gmtime( &_time ) );
  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S.0", gmtime( &_time ) );
  std::string creationstamp = timebuf;

  return creationstamp;
}
int XMLDOMBlock::init ( std::string  _root) [protected]

Definition at line 168 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh(), XMLProcessor::getInstance(), and geometryXMLtoCSV::parser.

{
  theProcessor = XMLProcessor::getInstance();

  //theFileName = xmlFileName;

  // initialize the parser
  parser = new XercesDOMParser();
  parser->setValidationScheme(XercesDOMParser::Val_Always);    
  parser->setDoNamespaces(true);    // optional
  
  errHandler = (ErrorHandler*) new HandlerBase();
  parser->setErrorHandler(errHandler);

  DOMImplementation* impl =  DOMImplementation::getImplementation();
  
  document = impl->createDocument(
                                  0,                      // root element namespace URI.
                                  //XMLString::transcode("ROOT"), // root element name
                                  XMLProcessor::_toXMLCh(_root), // root element name
                                  0);                     // document type object (DTD).

  the_string = 0;

  //
  //_____ following removed as a xalan-c component_____________________
  //
  /*
  // xalan objects initialization
  theSourceTreeInit = 0;
  theDOMSupport = 0;
  theLiaison = 0;
  theInputSource = 0;
  theDocument = 0;
  thePrefixResolver = 0;
  theEvaluator = 0;
  */
  return 0;
}
XMLDOMBlock & XMLDOMBlock::operator+= ( const XMLDOMBlock other)

Definition at line 36 of file XMLDOMBlock.cc.

References _length, getDocumentConst(), and i.

{
  DOMNodeList * _children = other.getDocumentConst()->getDocumentElement()->getChildNodes();
  int _length = _children->getLength();
  //std::cout << "Children nodes:" << _length << std::endl;
  DOMNode * _node;
  for(int i=0;i!=_length;i++){
    _node = _children->item(i);
    DOMNode * i_node = this->getDocument()->importNode(_node,true);
    this->getDocument()->getDocumentElement()->appendChild(i_node);
  }
  return *this;
}
void XMLDOMBlock::parse ( InputSource _source)

Definition at line 123 of file XMLDOMBlock.cc.

References gather_cfg::cout, XMLProcessor::getInstance(), python::rootplot::argparse::message, geometryXMLtoCSV::parser, and fetchall_from_DQM_v2::release.

Referenced by HcalTriggerKey::HcalTriggerKey().

{

  theProcessor = XMLProcessor::getInstance();

  //theFileName = xmlFileName;

  // initialize the parser
  parser = new XercesDOMParser();
  parser->setValidationScheme(XercesDOMParser::Val_Always);    
  parser->setDoNamespaces(true);    // optional
  
  errHandler = (ErrorHandler*) new HandlerBase();
  parser->setErrorHandler(errHandler);

  // parse the input xml file
  try
    {
      parser->parse( _source );
    }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (const DOMException& toCatch) {
    char* message = XMLString::transcode(toCatch.msg);
    std::cout << "Exception message is: \n"
         << message << "\n";
    XMLString::release(&message);
    //return -1;
  }
  catch (...) {
    std::cout << "Unexpected Exception \n" ;
    //return -1;
  }

  //get the XML document
  document = parser -> getDocument();
}
DOMNode * XMLDOMBlock::setTagAttribute ( DOMElement *  _elem,
const std::string &  tagName,
const std::string &  attrName,
const std::string &  attrValue,
int  _item = 0 
)

Definition at line 417 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_elem) return 0;
  DOMNode * the_tag = _elem ->  getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  if (the_tag){
    DOMElement * _tag = (DOMElement *)the_tag;
    _tag -> setAttribute( XMLProcessor::_toXMLCh( attrName ), XMLProcessor::_toXMLCh( attrValue ) );
  }
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagAttribute ( DOMElement *  _elem,
const std::string &  tagName,
const std::string &  attrName,
const int &  attrValue,
int  _item = 0 
)

Definition at line 436 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_elem) return 0;
  DOMNode * the_tag = _elem -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  if (the_tag){
    DOMElement * _tag = (DOMElement *)the_tag;
    _tag -> setAttribute( XMLProcessor::_toXMLCh( attrName ), XMLProcessor::_toXMLCh( attrValue ) );
  }
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagAttribute ( const std::string &  tagName,
const std::string &  attrName,
const int &  attrValue,
int  _item = 0 
)

Definition at line 428 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  DOMNode * the_tag = document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  DOMElement * _tag = (DOMElement *)the_tag;
  _tag -> setAttribute( XMLProcessor::_toXMLCh( attrName ), XMLProcessor::_toXMLCh( attrValue ) );
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagAttribute ( const std::string &  tagName,
const std::string &  attrName,
const std::string &  attrValue,
int  _item = 0 
)

Definition at line 409 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

Referenced by XMLHTRPatternLoader::XMLHTRPatternLoader(), XMLHTRZeroSuppressionLoader::XMLHTRZeroSuppressionLoader(), XMLLUTLoader::XMLLUTLoader(), and XMLRBXPedestalsLoader::XMLRBXPedestalsLoader().

{
  DOMNode * the_tag = document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  DOMElement * _tag = (DOMElement *)the_tag;
  _tag -> setAttribute( XMLProcessor::_toXMLCh( attrName ), XMLProcessor::_toXMLCh( attrValue ) );
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagValue ( DOMElement *  _elem,
const std::string &  tagName,
const std::string &  tagValue,
int  _item = 0 
)

Definition at line 373 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_elem) return 0;
  DOMNode * the_tag = _elem -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  if (the_tag){
    the_tag -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( tagValue ) );
  }
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagValue ( const std::string &  tagName,
const int &  tagValue,
int  _item = 0,
DOMDocument *  _document = NULL 
)

Definition at line 383 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_document) _document = document;
  DOMNode * the_tag = _document -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  the_tag -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( tagValue ) );
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagValue ( DOMElement *  _elem,
const std::string &  tagName,
const int &  tagValue,
int  _item = 0 
)

Definition at line 391 of file XMLDOMBlock.cc.

References XMLProcessor::_toXMLCh().

{
  if (!_elem) return 0;
  DOMNode * the_tag = _elem -> getElementsByTagName( XMLProcessor::_toXMLCh( tagName ) ) -> item( _item );
  if(the_tag){
    the_tag -> getFirstChild() -> setNodeValue( XMLProcessor::_toXMLCh( tagValue ) );
  }
  return the_tag;
}
DOMNode * XMLDOMBlock::setTagValue ( const std::string &  tagName,
const std::string &  tagValue,
int  _item = 0,
DOMDocument *  _document = NULL 
)
int XMLDOMBlock::write ( std::string  target = "stdout")

Friends And Related Function Documentation

friend class XMLProcessor [friend]

Definition at line 47 of file XMLDOMBlock.h.


Member Data Documentation

DOMDocument* XMLDOMBlock::document [protected]
ErrorHandler* XMLDOMBlock::errHandler [protected]

Definition at line 97 of file XMLDOMBlock.h.

XercesDOMParser* XMLDOMBlock::parser [protected]

Definition at line 96 of file XMLDOMBlock.h.

std::string* XMLDOMBlock::the_string [protected]

Definition at line 100 of file XMLDOMBlock.h.

std::string XMLDOMBlock::theFileName [protected]

Definition at line 99 of file XMLDOMBlock.h.

Definition at line 95 of file XMLDOMBlock.h.