Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

dom_tools.h

Go to the documentation of this file.
00001 /* dom_tools.h    $Revision: 1.3 $ $Date: 2005/12/17 16:06:11 $
00002    Copyright (C) 2000 University of Bonn.
00003    http://www.ikp.uni-bonn.de/boss
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA  02111-1307, USA.
00019 */
00020 
00025 #ifndef DOM_TOOLS_H
00026 #define DOM_TOOLS_H
00027 
00028 using namespace std;
00029 
00030 #include <xercesc/dom/DOM.hpp>
00031 #include <xercesc/util/BinInputStream.hpp>
00032 #include <xercesc/dom/DOMInputSource.hpp>
00033 #include <xercesc/util/PlatformUtils.hpp>
00034 #include <xercesc/parsers/XercesDOMParser.hpp>
00035 #include <xercesc/sax/HandlerBase.hpp>
00036 #include <xercesc/util/XMLString.hpp>
00037 #include <xercesc/util/TransService.hpp>
00038 
00039 #include <string>
00040 #include <vector>
00041 #include <iostream>
00042 #include <sstream>
00043 #include <fstream>
00044 #include <locale.h>
00045 
00046 
00047 
00048 
00049 ostream & operator << (ostream & target, xercesc::DOMNode * toWrite);
00050 ostream & operator << (ostream & target, const XMLCh * x);
00051 
00052 //xercesc::XMLTranscoder* UTF8Transcoder = NULL;
00053 //xercesc::XMLTranscoder* UTF16Transcoder = NULL;
00054 
00055 class BOSSString
00056 {
00057  public:
00058   unsigned char* data;
00059   BOSSString & operator = (const XMLCh* source);
00060 };
00061 
00062 namespace BOSS{
00063 
00064   typedef vector< xercesc::DOMNode* > DOMNodeVector;
00065 
00066   //void BOSS::docOutput (xercesc::DOMNode * toWrite)
00067   //ostream & operator << (ostream& target, const DOMString & s);
00068   //string getAttrByName(const DOMNode & element, const DOMString & key);
00069   bool hasAttribute(const xercesc::DOMNode* n, string as);
00070   bool hasAttribute(const xercesc::DOMElement * e, string as);
00071   string getAttrByName(const xercesc::DOMElement * e, string as);
00072   string getAttrByName(const xercesc::DOMNode * n, string as);
00073   //UnicodeString* getAttrByNameUni(const xercesc::DOMElement * e, string as);
00074   void createLists(const xercesc::DOMNode * start_node, const char* node_name, DOMNodeVector & list);
00075   void setAttribute(xercesc::DOMElement* e, const char* name, const char* value);
00076   xercesc::DOMNodeList* getElementsByTagName (const xercesc::DOMElement* e, const char* name);
00077   xercesc::DOMNodeList* getElementsByTagName (const xercesc::DOMDocument* d, const char* name);
00078   xercesc::DOMElement* createElement(xercesc::DOMDocument* doc, const char* name);
00079   bool compareNodeName(const xercesc::DOMNode* node, const string & name);
00080   string getNodeName(const xercesc::DOMNode* node);
00081   string getNodeValue(const xercesc::DOMNode* node);
00082   //UnicodeString BOSS::getNodeValueUni(const xercesc::DOMNode* node);
00083   void* getUserData(const xercesc::DOMNode* node);
00084   void setUserData(const xercesc::DOMNode* node, void* data);
00085   
00086   void initXML();
00087   void initTranscoder();
00088   xercesc::XMLTranscoder* initTranscoder(string name);
00089   xercesc::DOMDocument* parseXMLFile(const char* xml_file);
00090   xercesc::DOMDocument* parseXMLFromMemory(const string input);
00091 
00092 
00093 class MMFInputStream :
00094    public xercesc::BinInputStream
00095 {
00096 
00097 public:
00098    MMFInputStream(const char *xml)
00099    {
00100      m_xml = xml;
00101       m_pStart = (XMLByte*) xml;
00102       m_pCurrent = m_pStart;
00103    }
00104 
00105    virtual ~MMFInputStream(void)
00106    {
00107    }
00108 
00109    // BinInputStream methods
00110 public:
00111 
00112     virtual unsigned int curPos() const
00113     {
00114        return  m_pCurrent - m_pStart;
00115     }
00116 
00117     virtual unsigned int readBytes(XMLByte* const toFill, const unsigned int maxToRead)
00118     {
00119        // init to bytes available
00120        unsigned int nRead = strlen(m_xml) - curPos();
00121        if (nRead > maxToRead)
00122           nRead = maxToRead;
00123 
00124        memcpy(toFill, m_pCurrent, nRead);
00125        m_pCurrent += nRead;
00126        return nRead;
00127     }
00128 
00129 protected:
00130 
00131    const char* m_xml;
00132    XMLByte*          m_pStart;
00133    XMLByte*          m_pCurrent;
00134 
00135 };
00136 
00137 class MMFInputSource :
00138    public xercesc::DOMInputSource
00139 {
00140 
00141 public:
00142 
00143    MMFInputSource(const char *xml)
00144    {
00145      m_xml = xml;
00146    }
00147 
00148    virtual ~MMFInputSource(void)
00149    {
00150    }
00151 
00152    virtual xercesc::BinInputStream* makeStream() const
00153    {
00154       return new MMFInputStream(m_xml);
00155    }
00156 
00157   const XMLCh *         getEncoding () const {return NULL;}
00158   const XMLCh *         getPublicId () const {return NULL;}
00159   const XMLCh *         getSystemId () const {return NULL;}
00160   const XMLCh *         getBaseURI ()  const {return NULL;}
00161   void  setEncoding (const XMLCh *const encodingStr){}
00162   void  setPublicId (const XMLCh *const publicId){}
00163   void  setSystemId (const XMLCh *const systemId){}
00164   void  setBaseURI (const XMLCh *const baseURI){}
00165   void  setIssueFatalErrorIfNotFound (const bool flag){}
00166   bool  getIssueFatalErrorIfNotFound () const{return false;}
00167   void  release (){}
00168 
00169 
00170 protected:
00171 
00172    const char* m_xml;
00173 
00174 };
00175 
00176 };
00177  
00178 #endif

Generated on Tue Dec 20 23:14:38 2005 for BOSS by doxygen 1.3.6