| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 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.

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

## 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 31 of file XMLFileCatalog.cpp.

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