1*983d4c8aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*983d4c8aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*983d4c8aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*983d4c8aSAndrew Rist * distributed with this work for additional information 6*983d4c8aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*983d4c8aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*983d4c8aSAndrew Rist * "License"); you may not use this file except in compliance 9*983d4c8aSAndrew Rist * with the License. You may obtain a copy of the License at 10*983d4c8aSAndrew Rist * 11*983d4c8aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*983d4c8aSAndrew Rist * 13*983d4c8aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*983d4c8aSAndrew Rist * software distributed under the License is distributed on an 15*983d4c8aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*983d4c8aSAndrew Rist * KIND, either express or implied. See the License for the 17*983d4c8aSAndrew Rist * specific language governing permissions and limitations 18*983d4c8aSAndrew Rist * under the License. 19*983d4c8aSAndrew Rist * 20*983d4c8aSAndrew Rist *************************************************************/ 21*983d4c8aSAndrew Rist 22*983d4c8aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef BOOTSTRP_XMLPARSE_HXX 25cdf0e10cSrcweir #define BOOTSTRP_XMLPARSE_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <signal.h> 28cdf0e10cSrcweir #include <expat.h> 29cdf0e10cSrcweir #include <rtl/ustring.hxx> 30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 31cdf0e10cSrcweir #include "tools/string.hxx" 32cdf0e10cSrcweir #include "tools/list.hxx" 33cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS 34cdf0e10cSrcweir #include "tools/stream.hxx" 35cdf0e10cSrcweir #include "tools/isofallback.hxx" 36cdf0e10cSrcweir #include "export.hxx" 37cdf0e10cSrcweir #include "xmlutil.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <fstream> 40cdf0e10cSrcweir #include <iostream> 41cdf0e10cSrcweir 42cdf0e10cSrcweir class XMLParentNode; 43cdf0e10cSrcweir class XMLElement; 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::rtl; 47cdf0e10cSrcweir using namespace std; 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include <hash_map> /* std::hashmap*/ 50cdf0e10cSrcweir #include <deque> /* std::deque*/ 51cdf0e10cSrcweir #include <iterator> /* std::iterator*/ 52cdf0e10cSrcweir #include <list> /* std::list*/ 53cdf0e10cSrcweir #include <vector> /* std::vector*/ 54cdf0e10cSrcweir #define XML_NODE_TYPE_FILE 0x001 55cdf0e10cSrcweir #define XML_NODE_TYPE_ELEMENT 0x002 56cdf0e10cSrcweir #define XML_NODE_TYPE_DATA 0x003 57cdf0e10cSrcweir #define XML_NODE_TYPE_COMMENT 0x004 58cdf0e10cSrcweir #define XML_NODE_TYPE_DEFAULT 0x005 59cdf0e10cSrcweir #define MAX_LANGUAGES 99 60cdf0e10cSrcweir 61cdf0e10cSrcweir 62cdf0e10cSrcweir //#define TESTDRIVER /* use xml2gsi testclass */ 63cdf0e10cSrcweir //------------------------------------------------------------------------- 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Holds data of Attributes 66cdf0e10cSrcweir */ 67cdf0e10cSrcweir class XMLAttribute : public String 68cdf0e10cSrcweir { 69cdf0e10cSrcweir private: 70cdf0e10cSrcweir String sValue; 71cdf0e10cSrcweir 72cdf0e10cSrcweir public: 73cdf0e10cSrcweir /// creates an attribute XMLAttribute(const String & rName,const String & rValue)74cdf0e10cSrcweir XMLAttribute( 75cdf0e10cSrcweir const String &rName, // attributes name 76cdf0e10cSrcweir const String &rValue // attributes data 77cdf0e10cSrcweir ) 78cdf0e10cSrcweir : String( rName ), sValue( rValue ) {} 79cdf0e10cSrcweir 80cdf0e10cSrcweir /// getting value of an attribue GetValue()81cdf0e10cSrcweir const String &GetValue() { return sValue; } 82cdf0e10cSrcweir setValue(const String & rValue)83cdf0e10cSrcweir void setValue(const String &rValue){sValue=rValue;} 84cdf0e10cSrcweir 85cdf0e10cSrcweir /// returns true if two attributes are equal and have the same value IsEqual(const XMLAttribute & rAttribute)86cdf0e10cSrcweir sal_Bool IsEqual( 87cdf0e10cSrcweir const XMLAttribute &rAttribute // the attribute which has to be equal 88cdf0e10cSrcweir ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return (( rAttribute == *this ) && ( rAttribute.sValue == sValue )); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir }; 93cdf0e10cSrcweir 94cdf0e10cSrcweir DECLARE_LIST( XMLAttributeList, XMLAttribute * ) 95cdf0e10cSrcweir 96cdf0e10cSrcweir //------------------------------------------------------------------------- 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** Virtual base to handle different kinds of XML nodes 99cdf0e10cSrcweir */ 100cdf0e10cSrcweir class XMLNode 101cdf0e10cSrcweir { 102cdf0e10cSrcweir protected: XMLNode()103cdf0e10cSrcweir XMLNode() {} 104cdf0e10cSrcweir 105cdf0e10cSrcweir public: 106cdf0e10cSrcweir virtual sal_uInt16 GetNodeType() = 0; ~XMLNode()107cdf0e10cSrcweir virtual ~XMLNode() {} 108cdf0e10cSrcweir }; 109cdf0e10cSrcweir 110cdf0e10cSrcweir //------------------------------------------------------------------------- 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** Virtual base to handle different kinds of child nodes 113cdf0e10cSrcweir */ 114cdf0e10cSrcweir class XMLChildNode : public XMLNode 115cdf0e10cSrcweir { 116cdf0e10cSrcweir private: 117cdf0e10cSrcweir XMLParentNode *pParent; 118cdf0e10cSrcweir 119cdf0e10cSrcweir protected: 120cdf0e10cSrcweir XMLChildNode( XMLParentNode *pPar ); XMLChildNode()121cdf0e10cSrcweir XMLChildNode():pParent( NULL ){}; 122cdf0e10cSrcweir XMLChildNode( const XMLChildNode& obj); 123cdf0e10cSrcweir XMLChildNode& operator=(const XMLChildNode& obj); 124cdf0e10cSrcweir public: 125cdf0e10cSrcweir virtual sal_uInt16 GetNodeType() = 0; 126cdf0e10cSrcweir 127cdf0e10cSrcweir /// returns the parent of this node GetParent()128cdf0e10cSrcweir XMLParentNode *GetParent() { return pParent; } ~XMLChildNode()129cdf0e10cSrcweir virtual ~XMLChildNode(){}; 130cdf0e10cSrcweir }; 131cdf0e10cSrcweir 132cdf0e10cSrcweir DECLARE_LIST( XMLChildNodeList, XMLChildNode * ) 133cdf0e10cSrcweir 134cdf0e10cSrcweir //------------------------------------------------------------------------- 135cdf0e10cSrcweir 136cdf0e10cSrcweir /** Virtual base to handle different kinds of parent nodes 137cdf0e10cSrcweir */ 138cdf0e10cSrcweir class XMLData; 139cdf0e10cSrcweir 140cdf0e10cSrcweir class XMLParentNode : public XMLChildNode 141cdf0e10cSrcweir { 142cdf0e10cSrcweir private: 143cdf0e10cSrcweir XMLChildNodeList *pChildList; 144cdf0e10cSrcweir static int dbgcnt; 145cdf0e10cSrcweir //int nParentPos; 146cdf0e10cSrcweir protected: XMLParentNode(XMLParentNode * pPar)147cdf0e10cSrcweir XMLParentNode( XMLParentNode *pPar ) 148cdf0e10cSrcweir : XMLChildNode( pPar ), pChildList( NULL ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir } XMLParentNode()151cdf0e10cSrcweir XMLParentNode(): pChildList(NULL){ 152cdf0e10cSrcweir } 153cdf0e10cSrcweir /// Copyconstructor 154cdf0e10cSrcweir XMLParentNode( const XMLParentNode& ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir XMLParentNode& operator=(const XMLParentNode& obj); 157cdf0e10cSrcweir virtual ~XMLParentNode(); 158cdf0e10cSrcweir 159cdf0e10cSrcweir 160cdf0e10cSrcweir public: 161cdf0e10cSrcweir virtual sal_uInt16 GetNodeType() = 0; 162cdf0e10cSrcweir 163cdf0e10cSrcweir /// returns child list of this node GetChildList()164cdf0e10cSrcweir XMLChildNodeList *GetChildList() { return pChildList; } 165cdf0e10cSrcweir 166cdf0e10cSrcweir /// adds a new child 167cdf0e10cSrcweir void AddChild( 168cdf0e10cSrcweir XMLChildNode *pChild /// the new child 169cdf0e10cSrcweir ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir void AddChild( 172cdf0e10cSrcweir XMLChildNode *pChild , int pos /// the new child 173cdf0e10cSrcweir ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir virtual int GetPosition( ByteString id ); 176cdf0e10cSrcweir int RemoveChild( XMLElement *pRefElement ); 177cdf0e10cSrcweir void RemoveAndDeleteAllChilds(); 178cdf0e10cSrcweir 179cdf0e10cSrcweir /// returns a child element which matches the given one 180cdf0e10cSrcweir XMLElement *GetChildElement( 181cdf0e10cSrcweir XMLElement *pRefElement // the reference elelement 182cdf0e10cSrcweir ); 183cdf0e10cSrcweir }; 184cdf0e10cSrcweir 185cdf0e10cSrcweir //------------------------------------------------------------------------- 186cdf0e10cSrcweir 187cdf0e10cSrcweir DECLARE_LIST( XMLStringList, XMLElement* ) 188cdf0e10cSrcweir 189cdf0e10cSrcweir /// Mapping numeric Language code <-> XML Element 190cdf0e10cSrcweir typedef std::hash_map< ByteString ,XMLElement* , hashByteString,equalByteString > LangHashMap; 191cdf0e10cSrcweir 192cdf0e10cSrcweir /// Mapping XML Element string identifier <-> Language Map 193cdf0e10cSrcweir typedef std::hash_map<ByteString , LangHashMap* , 194cdf0e10cSrcweir hashByteString,equalByteString> XMLHashMap; 195cdf0e10cSrcweir 196cdf0e10cSrcweir /// Mapping iso alpha string code <-> iso numeric code 197cdf0e10cSrcweir typedef std::hash_map<ByteString, int, hashByteString,equalByteString> HashMap; 198cdf0e10cSrcweir 199cdf0e10cSrcweir /// Mapping XML tag names <-> have localizable strings 200cdf0e10cSrcweir typedef std::hash_map<ByteString , sal_Bool , 201cdf0e10cSrcweir hashByteString,equalByteString> TagMap; 202cdf0e10cSrcweir 203cdf0e10cSrcweir /** Holds information of a XML file, is root node of tree 204cdf0e10cSrcweir */ 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir class XMLFile : public XMLParentNode 208cdf0e10cSrcweir { 209cdf0e10cSrcweir public: 210cdf0e10cSrcweir XMLFile() ; 211cdf0e10cSrcweir XMLFile( 212cdf0e10cSrcweir const String &rFileName // the file name, empty if created from memory stream 213cdf0e10cSrcweir ); 214cdf0e10cSrcweir XMLFile( const XMLFile& obj ) ; 215cdf0e10cSrcweir ~XMLFile(); 216cdf0e10cSrcweir 217cdf0e10cSrcweir ByteString* GetGroupID(std::deque<ByteString> &groupid); 218cdf0e10cSrcweir void Print( XMLNode *pCur = NULL, sal_uInt16 nLevel = 0 ); 219cdf0e10cSrcweir virtual void SearchL10NElements( XMLParentNode *pCur, int pos = 0 ); 220cdf0e10cSrcweir void Extract( XMLFile *pCur = NULL ); 221cdf0e10cSrcweir void View(); 222cdf0e10cSrcweir // void static Signal_handler(int signo);//void*,oslSignalInfo * pInfo); 223cdf0e10cSrcweir void showType(XMLParentNode* node); 224cdf0e10cSrcweir GetStrings()225cdf0e10cSrcweir XMLHashMap* GetStrings(){return XMLStrings;} 226cdf0e10cSrcweir sal_Bool Write( ByteString &rFilename ); 227cdf0e10cSrcweir sal_Bool Write( ofstream &rStream , XMLNode *pCur = NULL ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir bool CheckExportStatus( XMLParentNode *pCur = NULL );// , int pos = 0 ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir XMLFile& operator=(const XMLFile& obj); 232cdf0e10cSrcweir 233cdf0e10cSrcweir virtual sal_uInt16 GetNodeType(); 234cdf0e10cSrcweir 235cdf0e10cSrcweir /// returns file name GetName()236cdf0e10cSrcweir const String &GetName() { return sFileName; } SetName(const String & rFilename)237cdf0e10cSrcweir void SetName( const String &rFilename ) { sFileName = rFilename; } SetFullName(const String & rFullFilename)238cdf0e10cSrcweir void SetFullName( const String &rFullFilename ) { sFullName = rFullFilename; } getOrder()239cdf0e10cSrcweir const std::vector<ByteString> getOrder(){ return order; } 240cdf0e10cSrcweir 241cdf0e10cSrcweir protected: 242cdf0e10cSrcweir // writes a string as UTF8 with dos line ends to a given stream 243cdf0e10cSrcweir void WriteString( ofstream &rStream, const String &sString ); 244cdf0e10cSrcweir 245cdf0e10cSrcweir // quotes the given text for writing to a file 246cdf0e10cSrcweir void QuotHTML( String &rString ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir void InsertL10NElement( XMLElement* pElement); 249cdf0e10cSrcweir 250cdf0e10cSrcweir // DATA 251cdf0e10cSrcweir String sFileName; 252cdf0e10cSrcweir String sFullName; 253cdf0e10cSrcweir 254cdf0e10cSrcweir const ByteString ID,OLDREF,XML_LANG; 255cdf0e10cSrcweir 256cdf0e10cSrcweir TagMap nodes_localize; 257cdf0e10cSrcweir XMLHashMap* XMLStrings; 258cdf0e10cSrcweir 259cdf0e10cSrcweir std::vector <ByteString> order; 260cdf0e10cSrcweir }; 261cdf0e10cSrcweir 262cdf0e10cSrcweir /// An Utility class for XML 263cdf0e10cSrcweir /// See RFC 3066 / #i8252# for ISO codes 264cdf0e10cSrcweir class XMLUtil{ 265cdf0e10cSrcweir 266cdf0e10cSrcweir public: 267cdf0e10cSrcweir /// Quot the XML characters and replace \n \t 268cdf0e10cSrcweir static void QuotHTML( String &rString ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir /// UnQuot the XML characters and restore \n \t 271cdf0e10cSrcweir static void UnQuotHTML ( String &rString ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir /// Return the numeric iso language code 274cdf0e10cSrcweir //sal_uInt16 GetLangByIsoLang( const ByteString &rIsoLang ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir /// Return the alpha strings representation 277cdf0e10cSrcweir ByteString GetIsoLangByIndex( sal_uInt16 nIndex ); 278cdf0e10cSrcweir 279cdf0e10cSrcweir static XMLUtil& Instance(); 280cdf0e10cSrcweir ~XMLUtil(); 281cdf0e10cSrcweir 282cdf0e10cSrcweir void dump(); 283cdf0e10cSrcweir 284cdf0e10cSrcweir private: 285cdf0e10cSrcweir /// Mapping iso alpha string code <-> iso numeric code 286cdf0e10cSrcweir HashMap lMap; 287cdf0e10cSrcweir 288cdf0e10cSrcweir /// Mapping iso numeric code <-> iso alpha string code 289cdf0e10cSrcweir ByteString isoArray[MAX_LANGUAGES]; 290cdf0e10cSrcweir 291cdf0e10cSrcweir static void UnQuotData( String &rString ); 292cdf0e10cSrcweir static void UnQuotTags( String &rString ); 293cdf0e10cSrcweir 294cdf0e10cSrcweir XMLUtil(); 295cdf0e10cSrcweir XMLUtil(const XMLUtil&); 296cdf0e10cSrcweir 297cdf0e10cSrcweir }; 298cdf0e10cSrcweir 299cdf0e10cSrcweir 300cdf0e10cSrcweir 301cdf0e10cSrcweir //------------------------------------------------------------------------- 302cdf0e10cSrcweir 303cdf0e10cSrcweir /** Hold information of an element node 304cdf0e10cSrcweir */ 305cdf0e10cSrcweir class XMLElement : public XMLParentNode 306cdf0e10cSrcweir { 307cdf0e10cSrcweir private: 308cdf0e10cSrcweir String sElementName; 309cdf0e10cSrcweir XMLAttributeList *pAttributes; 310cdf0e10cSrcweir ByteString project, 311cdf0e10cSrcweir filename, 312cdf0e10cSrcweir id, 313cdf0e10cSrcweir sOldRef, 314cdf0e10cSrcweir resourceType, 315cdf0e10cSrcweir languageId; 316cdf0e10cSrcweir int nPos; 317cdf0e10cSrcweir 318cdf0e10cSrcweir protected: 319cdf0e10cSrcweir void Print(XMLNode *pCur, OUStringBuffer& buffer , bool rootelement); 320cdf0e10cSrcweir public: 321cdf0e10cSrcweir /// create a element node XMLElement()322cdf0e10cSrcweir XMLElement(){} XMLElement(const String & rName,XMLParentNode * Parent)323cdf0e10cSrcweir XMLElement( 324cdf0e10cSrcweir const String &rName, // the element name 325cdf0e10cSrcweir XMLParentNode *Parent // parent node of this element 326cdf0e10cSrcweir ): XMLParentNode( Parent ), 327cdf0e10cSrcweir sElementName( rName ), 328cdf0e10cSrcweir pAttributes( NULL ), 329cdf0e10cSrcweir project(""), 330cdf0e10cSrcweir filename(""), 331cdf0e10cSrcweir id(""), 332cdf0e10cSrcweir sOldRef(""), 333cdf0e10cSrcweir resourceType(""), 334cdf0e10cSrcweir languageId(""), 335cdf0e10cSrcweir nPos(0) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir } 338cdf0e10cSrcweir ~XMLElement(); 339cdf0e10cSrcweir XMLElement(const XMLElement&); 340cdf0e10cSrcweir 341cdf0e10cSrcweir XMLElement& operator=(const XMLElement& obj); 342cdf0e10cSrcweir /// returns node type XML_NODE_ELEMENT 343cdf0e10cSrcweir virtual sal_uInt16 GetNodeType(); 344cdf0e10cSrcweir 345cdf0e10cSrcweir /// returns element name GetName()346cdf0e10cSrcweir const String &GetName() { return sElementName; } 347cdf0e10cSrcweir 348cdf0e10cSrcweir /// returns list of attributes of this element GetAttributeList()349cdf0e10cSrcweir XMLAttributeList *GetAttributeList() { return pAttributes; } 350cdf0e10cSrcweir 351cdf0e10cSrcweir /// adds a new attribute to this element, typically used by parser 352cdf0e10cSrcweir void AddAttribute( const String &rAttribute, const String &rValue ); 353cdf0e10cSrcweir 354cdf0e10cSrcweir void ChangeLanguageTag( const String &rValue ); 355cdf0e10cSrcweir // Return a ASCII String representation of this object 356cdf0e10cSrcweir OString ToOString(); 357cdf0e10cSrcweir 358cdf0e10cSrcweir // Return a Unicode String representation of this object 359cdf0e10cSrcweir OUString ToOUString(); 360cdf0e10cSrcweir 361cdf0e10cSrcweir bool Equals(OUString refStr); 362cdf0e10cSrcweir 363cdf0e10cSrcweir /// returns a attribute 364cdf0e10cSrcweir XMLAttribute *GetAttribute( 365cdf0e10cSrcweir const String &rName // the attribute name 366cdf0e10cSrcweir ); SetProject(ByteString prj)367cdf0e10cSrcweir void SetProject ( ByteString prj ){ project = prj; } SetFileName(ByteString fn)368cdf0e10cSrcweir void SetFileName ( ByteString fn ){ filename = fn; } SetId(ByteString theId)369cdf0e10cSrcweir void SetId ( ByteString theId ){ id = theId; } SetResourceType(ByteString rt)370cdf0e10cSrcweir void SetResourceType ( ByteString rt ){ resourceType = rt; } SetLanguageId(ByteString lid)371cdf0e10cSrcweir void SetLanguageId ( ByteString lid ){ languageId = lid; } SetPos(int nPos_in)372cdf0e10cSrcweir void SetPos ( int nPos_in ){ nPos = nPos_in; } SetOldRef(ByteString sOldRef_in)373cdf0e10cSrcweir void SetOldRef ( ByteString sOldRef_in ){ sOldRef = sOldRef_in; } 374cdf0e10cSrcweir GetPos()375cdf0e10cSrcweir virtual int GetPos() { return nPos; } GetProject()376cdf0e10cSrcweir ByteString GetProject() { return project; } GetFileName()377cdf0e10cSrcweir ByteString GetFileName() { return filename; } GetId()378cdf0e10cSrcweir ByteString GetId() { return id; } GetOldref()379cdf0e10cSrcweir ByteString GetOldref() { return sOldRef; } GetResourceType()380cdf0e10cSrcweir ByteString GetResourceType(){ return resourceType; } GetLanguageId()381cdf0e10cSrcweir ByteString GetLanguageId() { return languageId; } 382cdf0e10cSrcweir 383cdf0e10cSrcweir 384cdf0e10cSrcweir }; 385cdf0e10cSrcweir //------------------------------------------------------------------------- 386cdf0e10cSrcweir 387cdf0e10cSrcweir 388cdf0e10cSrcweir /** Holds character data 389cdf0e10cSrcweir */ 390cdf0e10cSrcweir class XMLData : public XMLChildNode 391cdf0e10cSrcweir { 392cdf0e10cSrcweir private: 393cdf0e10cSrcweir String sData; 394cdf0e10cSrcweir bool isNewCreated; 395cdf0e10cSrcweir 396cdf0e10cSrcweir public: 397cdf0e10cSrcweir /// create a data node XMLData(const String & rData,XMLParentNode * Parent)398cdf0e10cSrcweir XMLData( 399cdf0e10cSrcweir const String &rData, // the initial data 400cdf0e10cSrcweir XMLParentNode *Parent // the parent node of this data, typically a element node 401cdf0e10cSrcweir ) 402cdf0e10cSrcweir : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){} XMLData(const String & rData,XMLParentNode * Parent,bool newCreated)403cdf0e10cSrcweir XMLData( 404cdf0e10cSrcweir const String &rData, // the initial data 405cdf0e10cSrcweir XMLParentNode *Parent, // the parent node of this data, typically a element node 406cdf0e10cSrcweir bool newCreated 407cdf0e10cSrcweir ) 408cdf0e10cSrcweir : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( newCreated ){} 409cdf0e10cSrcweir 410cdf0e10cSrcweir XMLData(const XMLData& obj); 411cdf0e10cSrcweir 412cdf0e10cSrcweir XMLData& operator=(const XMLData& obj); 413cdf0e10cSrcweir virtual sal_uInt16 GetNodeType(); 414cdf0e10cSrcweir 415cdf0e10cSrcweir /// returns the data GetData()416cdf0e10cSrcweir const String &GetData() { return sData; } 417cdf0e10cSrcweir isNew()418cdf0e10cSrcweir bool isNew() { return isNewCreated; } 419cdf0e10cSrcweir /// adds new character data to the existing one 420cdf0e10cSrcweir void AddData( 421cdf0e10cSrcweir const String &rData // the new data 422cdf0e10cSrcweir ); 423cdf0e10cSrcweir 424cdf0e10cSrcweir 425cdf0e10cSrcweir 426cdf0e10cSrcweir }; 427cdf0e10cSrcweir 428cdf0e10cSrcweir //------------------------------------------------------------------------- 429cdf0e10cSrcweir 430cdf0e10cSrcweir /** Holds comments 431cdf0e10cSrcweir */ 432cdf0e10cSrcweir class XMLComment : public XMLChildNode 433cdf0e10cSrcweir { 434cdf0e10cSrcweir private: 435cdf0e10cSrcweir String sComment; 436cdf0e10cSrcweir 437cdf0e10cSrcweir public: 438cdf0e10cSrcweir /// create a comment node XMLComment(const String & rComment,XMLParentNode * Parent)439cdf0e10cSrcweir XMLComment( 440cdf0e10cSrcweir const String &rComment, // the comment 441cdf0e10cSrcweir XMLParentNode *Parent // the parent node of this comemnt, typically a element node 442cdf0e10cSrcweir ) 443cdf0e10cSrcweir : XMLChildNode( Parent ), sComment( rComment ) {} 444cdf0e10cSrcweir 445cdf0e10cSrcweir virtual sal_uInt16 GetNodeType(); 446cdf0e10cSrcweir 447cdf0e10cSrcweir XMLComment( const XMLComment& obj ); 448cdf0e10cSrcweir 449cdf0e10cSrcweir XMLComment& operator=(const XMLComment& obj); 450cdf0e10cSrcweir 451cdf0e10cSrcweir /// returns the comment GetComment()452cdf0e10cSrcweir const String &GetComment() { return sComment; } 453cdf0e10cSrcweir }; 454cdf0e10cSrcweir 455cdf0e10cSrcweir //------------------------------------------------------------------------- 456cdf0e10cSrcweir 457cdf0e10cSrcweir /** Holds additional file content like those for which no handler exists 458cdf0e10cSrcweir */ 459cdf0e10cSrcweir class XMLDefault : public XMLChildNode 460cdf0e10cSrcweir { 461cdf0e10cSrcweir private: 462cdf0e10cSrcweir String sDefault; 463cdf0e10cSrcweir 464cdf0e10cSrcweir public: 465cdf0e10cSrcweir /// create a comment node XMLDefault(const String & rDefault,XMLParentNode * Parent)466cdf0e10cSrcweir XMLDefault( 467cdf0e10cSrcweir const String &rDefault, // the comment 468cdf0e10cSrcweir XMLParentNode *Parent // the parent node of this comemnt, typically a element node 469cdf0e10cSrcweir ) 470cdf0e10cSrcweir : XMLChildNode( Parent ), sDefault( rDefault ) {} 471cdf0e10cSrcweir 472cdf0e10cSrcweir XMLDefault(const XMLDefault& obj); 473cdf0e10cSrcweir 474cdf0e10cSrcweir XMLDefault& operator=(const XMLDefault& obj); 475cdf0e10cSrcweir 476cdf0e10cSrcweir /// returns node type XML_NODE_TYPE_COMMENT 477cdf0e10cSrcweir virtual sal_uInt16 GetNodeType(); 478cdf0e10cSrcweir 479cdf0e10cSrcweir /// returns the comment GetDefault()480cdf0e10cSrcweir const String &GetDefault() { return sDefault; } 481cdf0e10cSrcweir }; 482cdf0e10cSrcweir 483cdf0e10cSrcweir //------------------------------------------------------------------------- 484cdf0e10cSrcweir 485cdf0e10cSrcweir /** struct for error information, used by class SimpleXMLParser 486cdf0e10cSrcweir */ 487cdf0e10cSrcweir struct XMLError { 488cdf0e10cSrcweir XML_Error eCode; // the error code 489cdf0e10cSrcweir sal_uLong nLine; // error line number 490cdf0e10cSrcweir sal_uLong nColumn; // error column number 491cdf0e10cSrcweir String sMessage; // readable error message 492cdf0e10cSrcweir }; 493cdf0e10cSrcweir 494cdf0e10cSrcweir //------------------------------------------------------------------------- 495cdf0e10cSrcweir 496cdf0e10cSrcweir /** validating xml parser, creates a document tree with xml nodes 497cdf0e10cSrcweir */ 498cdf0e10cSrcweir 499cdf0e10cSrcweir 500cdf0e10cSrcweir class SimpleXMLParser 501cdf0e10cSrcweir { 502cdf0e10cSrcweir private: 503cdf0e10cSrcweir XML_Parser aParser; 504cdf0e10cSrcweir XMLError aErrorInformation; 505cdf0e10cSrcweir 506cdf0e10cSrcweir XMLFile *pXMLFile; 507cdf0e10cSrcweir XMLParentNode *pCurNode; 508cdf0e10cSrcweir XMLData *pCurData; 509cdf0e10cSrcweir 510cdf0e10cSrcweir 511cdf0e10cSrcweir static void StartElementHandler( void *userData, const XML_Char *name, const XML_Char **atts ); 512cdf0e10cSrcweir static void EndElementHandler( void *userData, const XML_Char *name ); 513cdf0e10cSrcweir static void CharacterDataHandler( void *userData, const XML_Char *s, int len ); 514cdf0e10cSrcweir static void CommentHandler( void *userData, const XML_Char *data ); 515cdf0e10cSrcweir static void DefaultHandler( void *userData, const XML_Char *s, int len ); 516cdf0e10cSrcweir 517cdf0e10cSrcweir 518cdf0e10cSrcweir void StartElement( const XML_Char *name, const XML_Char **atts ); 519cdf0e10cSrcweir void EndElement( const XML_Char *name ); 520cdf0e10cSrcweir void CharacterData( const XML_Char *s, int len ); 521cdf0e10cSrcweir void Comment( const XML_Char *data ); 522cdf0e10cSrcweir void Default( const XML_Char *s, int len ); 523cdf0e10cSrcweir 524cdf0e10cSrcweir 525cdf0e10cSrcweir public: 526cdf0e10cSrcweir /// creates a new parser 527cdf0e10cSrcweir SimpleXMLParser(); 528cdf0e10cSrcweir ~SimpleXMLParser(); 529cdf0e10cSrcweir 530cdf0e10cSrcweir /// parse a file, returns NULL on criticall errors 531cdf0e10cSrcweir XMLFile *Execute( 532cdf0e10cSrcweir const String &rFullFileName, 533cdf0e10cSrcweir const String &rFileName, // the file name 534cdf0e10cSrcweir XMLFile *pXMLFileIn // the XMLFile 535cdf0e10cSrcweir ); 536cdf0e10cSrcweir 537cdf0e10cSrcweir /// parse a memory stream, returns NULL on criticall errors 538cdf0e10cSrcweir XMLFile *Execute( 539cdf0e10cSrcweir SvMemoryStream *pStream // the stream 540cdf0e10cSrcweir ); 541cdf0e10cSrcweir 542cdf0e10cSrcweir /// returns an error struct GetError()543cdf0e10cSrcweir const XMLError &GetError() { return aErrorInformation; } 544cdf0e10cSrcweir }; 545cdf0e10cSrcweir 546cdf0e10cSrcweir #endif 547