![]() |
|
|
Generated: 8 Jan 2009 |
#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"

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