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