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