| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# XMLFileCatalog.cpp File Reference

`#include "xercesc/framework/LocalFileFormatTarget.hpp"`
`#include "xercesc/framework/MemBufInputSource.hpp"`
`#include "xercesc/sax/SAXParseException.hpp"`
`#include "xercesc/sax/EntityResolver.hpp"`
`#include "xercesc/sax/InputSource.hpp"`
`#include "xercesc/parsers/XercesDOMParser.hpp"`
`#include "xercesc/util/PlatformUtils.hpp"`
`#include "xercesc/util/XercesDefs.hpp"`
`#include "xercesc/util/XMLUni.hpp"`
`#include "xercesc/util/XMLURL.hpp"`
`#include "xercesc/util/XMLString.hpp"`
`#include "xercesc/dom/DOM.hpp"`
`#include "GaudiKernel/MsgStream.h"`
`#include "GaudiKernel/Service.h"`
`#include "Reflex/PluginService.h"`
`#include "XMLFileCatalog.h"`
`#include <fstream>`
`#include <iostream>`
`#include <stdexcept>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include "uuid/uuid.h"`

Include dependency graph for XMLFileCatalog.cpp:

Go to the source code of this file.

## Defines
#define | setIdAttribute(a, b) setIdAttribute(a)
## Functions
| PLUGINSVC_FACTORY (XMLFileCatalog, IInterface *(std::string, IMessageSvc *)) namespace
std::string | Gaudi::createGuidAsString ()
| Create file identifier using UUID mechanism.

## Define Documentation

#define setIdAttribute | ( | a,
|  | b |  | ) | setIdAttribute(a)

Definition at line 33 of file XMLFileCatalog.cpp.

## Function Documentation

PLUGINSVC_FACTORY | ( | XMLFileCatalog | ,
|  | IInterface * | std::string, IMessageSvc * |
| ) |  |  |

Reference to catalog object

Constructor

Reset errors (Noop)

Warnings callback. Ignore them

Error handler

Fatal error handler

Definition at line 36 of file XMLFileCatalog.cpp.

    00038           {
    00039
    00040   typedef const string& CSTR;
    00041   inline string _toString(const XMLCh *toTranscode)  {
    00042     char * buff = XMLString::transcode(toTranscode);
    00043     string tmp(buff==0 ? "" : buff);
    00044     XMLString::release(&buff);
    00045     return tmp;
    00046   }
    00047   struct __Init  {
    00048     __Init() {
    00049       try { XMLPlatformUtils::Initialize();      }
    00050       catch (const XMLException& e)   {
    00051         cout << "Xerces-c error in initialization:" << _toString(e.getMessage()) << endl;
    00052       }
    00053     }
    00054     ~__Init() {
    00055       XMLPlatformUtils::Terminate();
    00056     }
    00057   };
    00058   __Init __In__;
    00059
    00060   struct XMLStr  {
    00061     XMLCh* m_xml;
    00062     XMLStr(CSTR c)                { m_xml=XMLString::transcode(c.c_str());  }
    00063     ~XMLStr()                     { if (m_xml) XMLString::release(&m_xml);  }
    00064     operator const XMLCh*() const { return m_xml;                           }
    00065   };
    00066   struct XMLTag : public XMLStr {
    00067     string m_str;
    00068     XMLTag(CSTR s) : XMLStr(s), m_str(s) {  }
    00069     ~XMLTag()                            {  }
    00070     operator CSTR () const  { return m_str; }
    00071   };
    00072   // bool operator==(const XMLTag& b, CSTR c) {  return c==b.m_str; }
    00073   bool operator==(CSTR c, const XMLTag& b) {  return c==b.m_str; }
    00074   struct XMLCollection  {
    00075     DOMElement* m_node;
    00076     XMLCollection(DOMNode* n, bool use_children=true) : m_node((DOMElement*)n) {
    00077       if ( use_children )  {
    00078         if ( m_node ) m_node = (DOMElement*)m_node->getFirstChild();
    00079         if ( m_node && m_node->getNodeType() != DOMNode::ELEMENT_NODE ) ++(*this);
    00080       }
    00081     }
    00082     operator bool()  const                { return 0 != m_node;                         }
    00083     operator DOMNode* () const            { return m_node;                              }
    00084     operator DOMElement* () const         { return m_node;                              }
    00085     DOMElement* operator->() const        { return m_node;                              }
    00086     string attr(const XMLTag& tag) const  { return _toString(m_node->getAttribute(tag));}
    00087     string attr(CSTR tag)  const          { return attr(XMLTag(tag));                   }
    00088     string tag() const                    { return _toString(m_node->getTagName());     }
    00089     void operator++()   {
    00090       while(m_node)  {
    00091         m_node = (DOMElement*)m_node->getNextSibling();
    00092         if ( m_node && m_node->getNodeType() == DOMNode::ELEMENT_NODE ) {
    00093           return;
    00094         }
    00095       }
    00096     }
    00097   };
    00098   struct ErrHandler : public ErrorHandler    {
    00100     IMessageSvc* m_msg;
    00102     ErrHandler(IMessageSvc* m) : m_msg(m) {}
    00104     void resetErrors()                          {      }
    00106     void warning(const SAXParseException& /* e */)    {     }
    00108     void error(const SAXParseException& e);
    00110     void fatalError(const SAXParseException& e);
    00111   };
    00112   struct DTDRedirect : public EntityResolver  {
    00113     InputSource* resolveEntity(const XMLCh* const /* pubId */, const XMLCh* const /* sysId */)  {
    00114       static const char* dtdID = "redirectinmem.dtd";
    00115       static const char* dtd = \
    00116         "\
    00117         <!ELEMENT POOLFILECATALOG (META*,File*)>\
    00118         <!ELEMENT META EMPTY>\
    00119         <!ELEMENT File (physical,logical,metadata*)>\
    00120         <!ATTLIST META name CDATA #REQUIRED>\
    00121         <!ATTLIST META type CDATA #REQUIRED>\
    00122         <!ELEMENT physical (pfn)+>\
    00123         <!ELEMENT logical (lfn)*>\
    00124         <!ELEMENT metadata EMPTY>\
    00125         <!ELEMENT lfn EMPTY>\
    00126         <!ELEMENT pfn EMPTY>\
    00127         <!ATTLIST File ID ID  #REQUIRED>\
    00128         <!ATTLIST pfn name ID #REQUIRED>\
    00129         <!ATTLIST pfn filetype CDATA #IMPLIED>\
    00130         <!ATTLIST lfn name ID #REQUIRED>\
    00131         <!ATTLIST metadata att_name  CDATA #REQUIRED>\
    00132         <!ATTLIST metadata att_value CDATA #REQUIRED>\
    00133         ";
    00134       static const size_t len = strlen(dtd);
    00135       return new MemBufInputSource((const XMLByte*)dtd,len,dtdID,false);
    00136     }
    00137   };
    00138
    00139   void ErrHandler::error(const SAXParseException& e)  {
    00140     string m(_toString(e.getMessage()));
    00141     if (m.find("The values for attribute 'name' must be names or name tokens")!=string::npos ||
    00142       m.find("The values for attribute 'ID' must be names or name tokens")!=string::npos   ||
    00143       m.find("for attribute 'name' must be Name or Nmtoken")!=string::npos                 ||
    00144       m.find("for attribute 'ID' must be Name or Nmtoken")!=string::npos                   ||
    00145       m.find("for attribute 'name' is invalid Name or NMTOKEN value")!=string::npos        ||
    00146       m.find("for attribute 'ID' is invalid Name or NMTOKEN value")!=string::npos      )
    00147       return;
    00148     string sys(_toString(e.getSystemId()));
    00149     MsgStream log(m_msg,"XMLCatalog");
    00150     log << MSG::ERROR << "Error at file \""  << sys
    00151       << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endmsg
    00152       << "Message: " << m << endmsg;
    00153   }
    00154   void ErrHandler::fatalError(const SAXParseException& e)  {
    00155     MsgStream log(m_msg,"XMLCatalog");
    00156     string m(_toString(e.getMessage()));
    00157     string sys(_toString(e.getSystemId()));
    00158     log << MSG::ERROR << "Fatal Error at file \"" << sys
    00159       << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endmsg
    00160       << "Message: " << m << endmsg;
    00161     throw runtime_error( "Standard pool exception : Fatal Error on the DOM Parser" );
    00162   }
    00163
    00164   const XMLTag EmptyCatalog("<!-- Edited By POOL -->\n"
    00165                               "<!DOCTYPE POOLFILECATALOG SYSTEM \"InMemory\">\n"
    00166                               "<POOLFILECATALOG>\n"
    00167                               "</POOLFILECATALOG>\n");
    00168   const XMLTag PFNCOLL         ("physical");
    00169   const XMLTag LFNCOLL         ("logical");
    00170   const XMLTag PFNNODE         ( "pfn");
    00171   const XMLTag LFNNODE         ( "lfn");
    00172   const XMLTag Attr_type       ( "type");
    00173   const XMLTag Attr_ID         ( "ID");
    00174   const XMLTag Attr_name       ( "name");
    00175   const XMLTag Attr_ftype      ( "filetype");
    00176   const XMLTag MetaNode        ( "metadata");
    00177   const XMLTag Attr_metaName   ( "att_name");
    00178   const XMLTag Attr_metaValue  ( "att_value");
    00179 }