xref: /aoo41x/main/l10ntools/source/xmlparse.cxx (revision cdf0e10c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_l10ntools.hxx"
30*cdf0e10cSrcweir #include <iterator> /* std::iterator*/
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <stdio.h>
33*cdf0e10cSrcweir #include <sal/alloca.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "xmlparse.hxx"
36*cdf0e10cSrcweir #include <fstream>
37*cdf0e10cSrcweir #include <iostream>
38*cdf0e10cSrcweir #include <osl/mutex.hxx>
39*cdf0e10cSrcweir #include <osl/thread.hxx>
40*cdf0e10cSrcweir #ifdef __MINGW32__
41*cdf0e10cSrcweir #include <tools/prewin.h>
42*cdf0e10cSrcweir #include <tools/postwin.h>
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir using namespace std;
45*cdf0e10cSrcweir using namespace osl;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //
48*cdf0e10cSrcweir // class XMLChildNode
49*cdf0e10cSrcweir //
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /*****************************************************************************/
52*cdf0e10cSrcweir XMLChildNode::XMLChildNode( XMLParentNode *pPar )
53*cdf0e10cSrcweir /*****************************************************************************/
54*cdf0e10cSrcweir 				: pParent( pPar )
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	if ( pParent )
57*cdf0e10cSrcweir 		pParent->AddChild( this );
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir /*****************************************************************************/
62*cdf0e10cSrcweir XMLChildNode::XMLChildNode( const XMLChildNode& obj)
63*cdf0e10cSrcweir /*****************************************************************************/
64*cdf0e10cSrcweir :   XMLNode(obj),
65*cdf0e10cSrcweir     pParent(obj.pParent){}
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir /*****************************************************************************/
68*cdf0e10cSrcweir XMLChildNode& XMLChildNode::operator=(const XMLChildNode& obj){
69*cdf0e10cSrcweir /*****************************************************************************/
70*cdf0e10cSrcweir 	if(this != &obj){
71*cdf0e10cSrcweir         pParent=obj.pParent;
72*cdf0e10cSrcweir     }
73*cdf0e10cSrcweir     return *this;
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir //
76*cdf0e10cSrcweir // class XMLParentNode
77*cdf0e10cSrcweir //
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir /*****************************************************************************/
81*cdf0e10cSrcweir XMLParentNode::~XMLParentNode()
82*cdf0e10cSrcweir /*****************************************************************************/
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	if( pChildList ){
85*cdf0e10cSrcweir             RemoveAndDeleteAllChilds();
86*cdf0e10cSrcweir             delete pChildList;
87*cdf0e10cSrcweir 			pChildList = NULL;
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir 	pChildList = NULL;
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir /*****************************************************************************/
92*cdf0e10cSrcweir XMLParentNode::XMLParentNode( const XMLParentNode& obj)
93*cdf0e10cSrcweir /*****************************************************************************/
94*cdf0e10cSrcweir : XMLChildNode( obj )
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir 	if( obj.pChildList ){
97*cdf0e10cSrcweir         pChildList=new XMLChildNodeList();
98*cdf0e10cSrcweir         XMLChildNode* pNode = NULL;
99*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < obj.pChildList->Count(); i++ ){
100*cdf0e10cSrcweir 			pNode = obj.pChildList->GetObject( i );
101*cdf0e10cSrcweir             if( pNode != NULL){
102*cdf0e10cSrcweir                 switch(pNode->GetNodeType()){
103*cdf0e10cSrcweir                     case XML_NODE_TYPE_ELEMENT:
104*cdf0e10cSrcweir                         AddChild( new XMLElement( *static_cast<XMLElement* >(pNode) ) ); break;
105*cdf0e10cSrcweir                     case XML_NODE_TYPE_DATA:
106*cdf0e10cSrcweir                         AddChild( new XMLData   ( *static_cast<XMLData* >   (pNode) ) ); break;
107*cdf0e10cSrcweir                     case XML_NODE_TYPE_COMMENT:
108*cdf0e10cSrcweir                         AddChild( new XMLComment( *static_cast<XMLComment* >(pNode) ) ); break;
109*cdf0e10cSrcweir                     case XML_NODE_TYPE_DEFAULT:
110*cdf0e10cSrcweir                         AddChild( new XMLDefault( *static_cast<XMLDefault* >(pNode) ) ); break;
111*cdf0e10cSrcweir                     default:    fprintf(stdout,"XMLParentNode::XMLParentNode( const XMLParentNode& obj) strange obj");
112*cdf0e10cSrcweir                 }
113*cdf0e10cSrcweir             }
114*cdf0e10cSrcweir         }
115*cdf0e10cSrcweir     }else pChildList = NULL;
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir /*****************************************************************************/
118*cdf0e10cSrcweir XMLParentNode& XMLParentNode::operator=(const XMLParentNode& obj){
119*cdf0e10cSrcweir /*****************************************************************************/
120*cdf0e10cSrcweir 	if(this!=&obj){
121*cdf0e10cSrcweir         XMLChildNode::operator=(obj);
122*cdf0e10cSrcweir         if( pChildList ){
123*cdf0e10cSrcweir             RemoveAndDeleteAllChilds();
124*cdf0e10cSrcweir             delete pChildList;
125*cdf0e10cSrcweir 			pChildList = NULL;
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir         if( obj.pChildList ){
128*cdf0e10cSrcweir             pChildList=new XMLChildNodeList();
129*cdf0e10cSrcweir             for ( sal_uLong i = 0; i < obj.pChildList->Count(); i++ )
130*cdf0e10cSrcweir 			    AddChild( obj.pChildList->GetObject( i ) );
131*cdf0e10cSrcweir         }else pChildList = NULL;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir     return *this;
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir /*****************************************************************************/
137*cdf0e10cSrcweir void XMLParentNode::AddChild( XMLChildNode *pChild )
138*cdf0e10cSrcweir /*****************************************************************************/
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	if ( !pChildList )
141*cdf0e10cSrcweir 		pChildList = new XMLChildNodeList();
142*cdf0e10cSrcweir 	pChildList->Insert( pChild, LIST_APPEND );
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir /*****************************************************************************/
146*cdf0e10cSrcweir void XMLParentNode::AddChild( XMLChildNode *pChild , int pos )
147*cdf0e10cSrcweir /*****************************************************************************/
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	if ( !pChildList )
150*cdf0e10cSrcweir 		pChildList = new XMLChildNodeList();
151*cdf0e10cSrcweir     pChildList->Insert( pChild, pos );
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir /*****************************************************************************/
155*cdf0e10cSrcweir int XMLParentNode::GetPosition( ByteString id ){
156*cdf0e10cSrcweir /*****************************************************************************/
157*cdf0e10cSrcweir     XMLElement* a;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     static const ByteString sEnusStr = ByteString(String::CreateFromAscii(ENGLISH_US_ISO).ToLowerAscii() , RTL_TEXTENCODING_ASCII_US ).ToLowerAscii();
160*cdf0e10cSrcweir     static const ByteString sDeStr   = ByteString(String::CreateFromAscii(GERMAN_ISO2).ToLowerAscii()    , RTL_TEXTENCODING_ASCII_US ).ToLowerAscii();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     if ( pChildList ){
163*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < pChildList->Count(); i++ ) {
164*cdf0e10cSrcweir 		    XMLChildNode *pChild = pChildList->GetObject( i );
165*cdf0e10cSrcweir             if ( pChild->GetNodeType() == XML_NODE_TYPE_ELEMENT ){
166*cdf0e10cSrcweir 			    a = static_cast<XMLElement* >(pChild);
167*cdf0e10cSrcweir                 ByteString elemid( a->GetId() );
168*cdf0e10cSrcweir                 elemid.ToLowerAscii();
169*cdf0e10cSrcweir                 if (   elemid.Equals( id.ToLowerAscii() ) ){
170*cdf0e10cSrcweir                     ByteString elemLID( a->GetLanguageId() );
171*cdf0e10cSrcweir                     elemLID.ToLowerAscii();
172*cdf0e10cSrcweir                     if( elemLID.Equals( sEnusStr) ) {
173*cdf0e10cSrcweir                         return i;
174*cdf0e10cSrcweir                     }
175*cdf0e10cSrcweir                     else if( elemLID.Equals( sDeStr) ) {
176*cdf0e10cSrcweir                         return i;
177*cdf0e10cSrcweir                     }
178*cdf0e10cSrcweir                 }
179*cdf0e10cSrcweir             }
180*cdf0e10cSrcweir         }
181*cdf0e10cSrcweir     }
182*cdf0e10cSrcweir     return -1;
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir /*****************************************************************************/
186*cdf0e10cSrcweir int XMLParentNode::RemoveChild( XMLElement *pRefElement )
187*cdf0e10cSrcweir /*****************************************************************************/
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     XMLElement* a;
190*cdf0e10cSrcweir     if ( pChildList ){
191*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < pChildList->Count(); i++ ) {
192*cdf0e10cSrcweir 		    XMLChildNode *pChild = pChildList->GetObject( i );
193*cdf0e10cSrcweir             if ( pChild->GetNodeType() == XML_NODE_TYPE_ELEMENT ){
194*cdf0e10cSrcweir 			    a = static_cast<XMLElement* >(pChild);
195*cdf0e10cSrcweir                 ByteString elemid( a->GetId() );
196*cdf0e10cSrcweir                 elemid.ToLowerAscii();
197*cdf0e10cSrcweir                 ByteString elemLID( a->GetLanguageId() );
198*cdf0e10cSrcweir                 elemLID.ToLowerAscii();
199*cdf0e10cSrcweir                 ByteString pRefLID( pRefElement->GetLanguageId() );
200*cdf0e10cSrcweir                 pRefLID.ToLowerAscii();
201*cdf0e10cSrcweir                 if ( elemid.Equals(pRefElement->GetId())
202*cdf0e10cSrcweir                     && elemLID.Equals( pRefLID ) )
203*cdf0e10cSrcweir 			    {
204*cdf0e10cSrcweir                     if( pRefElement->ToOString().compareTo( a->ToOString() )==0 ){
205*cdf0e10cSrcweir 						pChildList->Remove( i );
206*cdf0e10cSrcweir                         delete a; // Test
207*cdf0e10cSrcweir                         return i;
208*cdf0e10cSrcweir                     }
209*cdf0e10cSrcweir                 }
210*cdf0e10cSrcweir             }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir     return -1;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir /*****************************************************************************/
218*cdf0e10cSrcweir void XMLParentNode::RemoveAndDeleteAllChilds(){
219*cdf0e10cSrcweir /*****************************************************************************/
220*cdf0e10cSrcweir 	if ( pChildList ) {
221*cdf0e10cSrcweir 		for ( sal_uLong i = 0; i < pChildList->Count(); i++ )
222*cdf0e10cSrcweir 			delete pChildList->GetObject( i );
223*cdf0e10cSrcweir 		pChildList->Clear();
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir /*****************************************************************************/
228*cdf0e10cSrcweir XMLElement *XMLParentNode::GetChildElement( XMLElement *pRefElement )
229*cdf0e10cSrcweir /*****************************************************************************/
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	for ( sal_uLong i = 0; i < pChildList->Count(); i++ ) {
232*cdf0e10cSrcweir 		XMLChildNode *pChild = pChildList->GetObject( i );
233*cdf0e10cSrcweir 		if ( pChild->GetNodeType() == XML_NODE_TYPE_ELEMENT )
234*cdf0e10cSrcweir 			if ((( XMLElement * ) pChild )->GetName() ==
235*cdf0e10cSrcweir 				pRefElement->GetName())
236*cdf0e10cSrcweir 			{
237*cdf0e10cSrcweir 				XMLAttributeList *pList = pRefElement->GetAttributeList();
238*cdf0e10cSrcweir 				if ( !pList )
239*cdf0e10cSrcweir 					return ( XMLElement * ) pChild;
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 				sal_Bool bMatch = sal_False;
242*cdf0e10cSrcweir 				for ( sal_uLong j = 0; j < pList->Count() && bMatch; j++ ) {
243*cdf0e10cSrcweir 					XMLAttribute *pAttribute = pList->GetObject( j );
244*cdf0e10cSrcweir 					XMLAttribute *pCandidate =
245*cdf0e10cSrcweir 						(( XMLElement * ) pChild )->GetAttribute(
246*cdf0e10cSrcweir 							*pAttribute );
247*cdf0e10cSrcweir 					if ( !pCandidate || !pAttribute->IsEqual( *pCandidate ))
248*cdf0e10cSrcweir 						bMatch = sal_False;
249*cdf0e10cSrcweir 				}
250*cdf0e10cSrcweir 				if ( bMatch )
251*cdf0e10cSrcweir 					return ( XMLElement * ) pChild;
252*cdf0e10cSrcweir 			}
253*cdf0e10cSrcweir 	}
254*cdf0e10cSrcweir 	return NULL;
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir //
258*cdf0e10cSrcweir // class XMLFile
259*cdf0e10cSrcweir //
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir /*****************************************************************************/
262*cdf0e10cSrcweir sal_uInt16 XMLFile::GetNodeType()
263*cdf0e10cSrcweir /*****************************************************************************/
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir 	return XML_NODE_TYPE_FILE;
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir /*****************************************************************************/
269*cdf0e10cSrcweir sal_Bool XMLFile::Write( ByteString &aFilename )
270*cdf0e10cSrcweir /*****************************************************************************/
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     if ( aFilename.Len()) {
274*cdf0e10cSrcweir 		// retry harder if there is a NFS problem,
275*cdf0e10cSrcweir         for( int x = 1 ; x < 3 ; x++ ){	// this looks strange...yes!
276*cdf0e10cSrcweir 			ofstream aFStream( aFilename.GetBuffer() , ios::out | ios::trunc );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir             if( !aFStream )		// From time to time the stream can not be opened the first time on NFS volumes,
279*cdf0e10cSrcweir 			{					// I wasn't able to track this down. I think this is an NFS issue .....
280*cdf0e10cSrcweir                 //cerr << "ERROR: - helpex - Can't write to tempfile " << aFilename.GetBuffer() << " No#" << x << "\n";
281*cdf0e10cSrcweir                 TimeValue aTime;
282*cdf0e10cSrcweir                 aTime.Seconds = 3;
283*cdf0e10cSrcweir                 aTime.Nanosec = 0;
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir                 osl::Thread::wait( aTime );
286*cdf0e10cSrcweir             }
287*cdf0e10cSrcweir             else
288*cdf0e10cSrcweir             {
289*cdf0e10cSrcweir                 // write out
290*cdf0e10cSrcweir 				Write( aFStream );
291*cdf0e10cSrcweir                 aFStream.close();
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 				// check!
294*cdf0e10cSrcweir 				DirEntry aTarget( aFilename );
295*cdf0e10cSrcweir                 FileStat aFileStat( aTarget );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 				if( aFileStat.GetSize() < 1 )
298*cdf0e10cSrcweir 				{
299*cdf0e10cSrcweir                     //retry
300*cdf0e10cSrcweir 					//cerr << "WARNING: - helpex - Can't create file " << aFilename.GetBuffer() << " No#" << x << "\n";
301*cdf0e10cSrcweir                     aTarget.Kill();
302*cdf0e10cSrcweir                 }
303*cdf0e10cSrcweir 				else
304*cdf0e10cSrcweir 				{
305*cdf0e10cSrcweir                     //everything ok!
306*cdf0e10cSrcweir 					return true;
307*cdf0e10cSrcweir                 }
308*cdf0e10cSrcweir             }
309*cdf0e10cSrcweir 	    }
310*cdf0e10cSrcweir 		cerr << "ERROR: - helpex - Can't create file " << aFilename.GetBuffer() << "\nPossible reason: Disk full ? Mounted NFS volume broken ? Wrong permissions ?\n";
311*cdf0e10cSrcweir         exit( -1 );
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir     cerr << "ERROR: - helpex - Empty file name\n";
314*cdf0e10cSrcweir     exit( -1 );
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir void XMLFile::WriteString( ofstream &rStream, const String &sString )
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	ByteString sText( sString, RTL_TEXTENCODING_UTF8 );
322*cdf0e10cSrcweir 	rStream << sText.GetBuffer();
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir sal_Bool XMLFile::Write( ofstream &rStream , XMLNode *pCur )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     XMLUtil& xmlutil = XMLUtil::Instance();
329*cdf0e10cSrcweir     (void) xmlutil;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     if ( !pCur )
332*cdf0e10cSrcweir 		Write( rStream, this );
333*cdf0e10cSrcweir 	else {
334*cdf0e10cSrcweir 		switch( pCur->GetNodeType()) {
335*cdf0e10cSrcweir 			case XML_NODE_TYPE_FILE: {
336*cdf0e10cSrcweir 				if( GetChildList())
337*cdf0e10cSrcweir 					for ( sal_uLong i = 0; i < GetChildList()->Count(); i++ )
338*cdf0e10cSrcweir 						Write( rStream, GetChildList()->GetObject( i ));
339*cdf0e10cSrcweir 			}
340*cdf0e10cSrcweir 			break;
341*cdf0e10cSrcweir 			case XML_NODE_TYPE_ELEMENT: {
342*cdf0e10cSrcweir 				XMLElement *pElement = ( XMLElement * ) pCur;
343*cdf0e10cSrcweir 				rStream  << "<";
344*cdf0e10cSrcweir 				WriteString( rStream, pElement->GetName());
345*cdf0e10cSrcweir 				if ( pElement->GetAttributeList())
346*cdf0e10cSrcweir 					for ( sal_uLong j = 0; j < pElement->GetAttributeList()->Count(); j++ ) {
347*cdf0e10cSrcweir 						rStream << " ";
348*cdf0e10cSrcweir 						String sData(*pElement->GetAttributeList()->GetObject( j ));
349*cdf0e10cSrcweir 						xmlutil.QuotHTML( sData );
350*cdf0e10cSrcweir 						WriteString( rStream , sData );
351*cdf0e10cSrcweir 						rStream << "=\"";
352*cdf0e10cSrcweir 						sData=pElement->GetAttributeList()->GetObject( j )->GetValue();
353*cdf0e10cSrcweir 						xmlutil.QuotHTML(  sData );
354*cdf0e10cSrcweir 						WriteString( rStream , sData  );
355*cdf0e10cSrcweir 						rStream << "\"";
356*cdf0e10cSrcweir 					}
357*cdf0e10cSrcweir 				if ( !pElement->GetChildList())
358*cdf0e10cSrcweir 					rStream << "/>";
359*cdf0e10cSrcweir 				else {
360*cdf0e10cSrcweir 					rStream << ">";
361*cdf0e10cSrcweir 					for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ )
362*cdf0e10cSrcweir 						Write( rStream, pElement->GetChildList()->GetObject( k ));
363*cdf0e10cSrcweir 					rStream << "</";
364*cdf0e10cSrcweir 					WriteString( rStream, pElement->GetName());
365*cdf0e10cSrcweir 					rStream << ">";
366*cdf0e10cSrcweir    				}
367*cdf0e10cSrcweir 			}
368*cdf0e10cSrcweir 			break;
369*cdf0e10cSrcweir 			case XML_NODE_TYPE_DATA: {
370*cdf0e10cSrcweir 				XMLData *pData = ( XMLData * ) pCur;
371*cdf0e10cSrcweir 				String sData( pData->GetData());
372*cdf0e10cSrcweir                 xmlutil.QuotHTML( sData );
373*cdf0e10cSrcweir 				WriteString( rStream, sData );
374*cdf0e10cSrcweir 			}
375*cdf0e10cSrcweir 			break;
376*cdf0e10cSrcweir 			case XML_NODE_TYPE_COMMENT: {
377*cdf0e10cSrcweir 				XMLComment *pComment = ( XMLComment * ) pCur;
378*cdf0e10cSrcweir 				rStream << "<!--";
379*cdf0e10cSrcweir 				WriteString( rStream, pComment->GetComment());
380*cdf0e10cSrcweir 				rStream << "-->";
381*cdf0e10cSrcweir 			}
382*cdf0e10cSrcweir 			break;
383*cdf0e10cSrcweir 			case XML_NODE_TYPE_DEFAULT: {
384*cdf0e10cSrcweir 				XMLDefault *pDefault = ( XMLDefault * ) pCur;
385*cdf0e10cSrcweir 				WriteString( rStream, pDefault->GetDefault());
386*cdf0e10cSrcweir 			}
387*cdf0e10cSrcweir 			break;
388*cdf0e10cSrcweir 		}
389*cdf0e10cSrcweir 	}
390*cdf0e10cSrcweir 	return sal_True;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir void XMLFile::Print( XMLNode *pCur, sal_uInt16 nLevel )
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 	if ( !pCur )
398*cdf0e10cSrcweir 		Print( this );
399*cdf0e10cSrcweir 	else {
400*cdf0e10cSrcweir 		switch( pCur->GetNodeType()) {
401*cdf0e10cSrcweir 			case XML_NODE_TYPE_FILE: {
402*cdf0e10cSrcweir 				if( GetChildList())
403*cdf0e10cSrcweir 					for ( sal_uLong i = 0; i < GetChildList()->Count(); i++ )
404*cdf0e10cSrcweir 						Print( GetChildList()->GetObject( i ));
405*cdf0e10cSrcweir 			}
406*cdf0e10cSrcweir 			break;
407*cdf0e10cSrcweir 			case XML_NODE_TYPE_ELEMENT: {
408*cdf0e10cSrcweir 				XMLElement *pElement = ( XMLElement * ) pCur;
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 				fprintf( stdout, "<%s", ByteString( pElement->GetName(), RTL_TEXTENCODING_UTF8 ).GetBuffer());
411*cdf0e10cSrcweir 				if ( pElement->GetAttributeList())
412*cdf0e10cSrcweir 					for ( sal_uLong j = 0; j < pElement->GetAttributeList()->Count(); j++ ){
413*cdf0e10cSrcweir 						ByteString aAttrName( *pElement->GetAttributeList()->GetObject( j ), RTL_TEXTENCODING_UTF8 );
414*cdf0e10cSrcweir                         if( !aAttrName.EqualsIgnoreCaseAscii( XML_LANG ) ) {
415*cdf0e10cSrcweir                             fprintf( stdout, " %s=\"%s\"",
416*cdf0e10cSrcweir                                 aAttrName.GetBuffer(),
417*cdf0e10cSrcweir 							    ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),
418*cdf0e10cSrcweir 								    RTL_TEXTENCODING_UTF8 ).GetBuffer());
419*cdf0e10cSrcweir                         }
420*cdf0e10cSrcweir                     }
421*cdf0e10cSrcweir 				if ( !pElement->GetChildList())
422*cdf0e10cSrcweir 					fprintf( stdout, "/>" );
423*cdf0e10cSrcweir 				else {
424*cdf0e10cSrcweir 					fprintf( stdout, ">" );
425*cdf0e10cSrcweir 					for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ )
426*cdf0e10cSrcweir 						Print( pElement->GetChildList()->GetObject( k ), nLevel + 1 );
427*cdf0e10cSrcweir 					fprintf( stdout, "</%s>", ByteString( pElement->GetName(), RTL_TEXTENCODING_UTF8 ).GetBuffer());
428*cdf0e10cSrcweir 				}
429*cdf0e10cSrcweir 			}
430*cdf0e10cSrcweir 			break;
431*cdf0e10cSrcweir 			case XML_NODE_TYPE_DATA: {
432*cdf0e10cSrcweir 				XMLData *pData = ( XMLData * ) pCur;
433*cdf0e10cSrcweir 				String sData = pData->GetData();
434*cdf0e10cSrcweir 				fprintf( stdout, "%s", ByteString( sData, RTL_TEXTENCODING_UTF8 ).GetBuffer());
435*cdf0e10cSrcweir 			}
436*cdf0e10cSrcweir 			break;
437*cdf0e10cSrcweir 			case XML_NODE_TYPE_COMMENT: {
438*cdf0e10cSrcweir 				XMLComment *pComment = ( XMLComment * ) pCur;
439*cdf0e10cSrcweir 				fprintf( stdout, "<!--%s-->", ByteString( pComment->GetComment(), RTL_TEXTENCODING_UTF8 ).GetBuffer());
440*cdf0e10cSrcweir 			}
441*cdf0e10cSrcweir 			break;
442*cdf0e10cSrcweir 			case XML_NODE_TYPE_DEFAULT: {
443*cdf0e10cSrcweir 				XMLDefault *pDefault = ( XMLDefault * ) pCur;
444*cdf0e10cSrcweir 				fprintf( stdout, "%s", ByteString( pDefault->GetDefault(), RTL_TEXTENCODING_UTF8 ).GetBuffer());
445*cdf0e10cSrcweir 			}
446*cdf0e10cSrcweir 			break;
447*cdf0e10cSrcweir 		}
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir XMLFile::~XMLFile()
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	if( XMLStrings != NULL ){
453*cdf0e10cSrcweir 		XMLHashMap::iterator pos = XMLStrings->begin();
454*cdf0e10cSrcweir 		for( ; pos != XMLStrings->end() ; ++pos ){
455*cdf0e10cSrcweir 			delete pos->second;				// Check and delete content also ?
456*cdf0e10cSrcweir 		}
457*cdf0e10cSrcweir 		delete XMLStrings;
458*cdf0e10cSrcweir 		XMLStrings = NULL;
459*cdf0e10cSrcweir 	}
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir /*****************************************************************************/
462*cdf0e10cSrcweir XMLFile::XMLFile( const String &rFileName ) // the file name, empty if created from memory stream
463*cdf0e10cSrcweir /*****************************************************************************/
464*cdf0e10cSrcweir 				: XMLParentNode( NULL ),
465*cdf0e10cSrcweir 				  sFileName    ( rFileName ),
466*cdf0e10cSrcweir 				  ID           ( "id" ),
467*cdf0e10cSrcweir                   OLDREF       ( "oldref" ),
468*cdf0e10cSrcweir 				  XML_LANG     ( "xml-lang" ),
469*cdf0e10cSrcweir 				  XMLStrings   ( NULL )
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir {
472*cdf0e10cSrcweir //	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("bookmark_value"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
473*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("bookmark"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
474*cdf0e10cSrcweir     nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("variable"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
475*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("paragraph"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
476*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("alt"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
477*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("caption"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
478*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("title"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
479*cdf0e10cSrcweir 	nodes_localize.insert( TagMap::value_type(ByteString(String::CreateFromAscii("link"),RTL_TEXTENCODING_ASCII_US) , sal_True) );
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir /*****************************************************************************/
482*cdf0e10cSrcweir void XMLFile::Extract( XMLFile *pCur )
483*cdf0e10cSrcweir /*****************************************************************************/
484*cdf0e10cSrcweir {
485*cdf0e10cSrcweir 	if( XMLStrings != NULL ) delete XMLStrings; // Elements ?
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	XMLStrings = new XMLHashMap();
488*cdf0e10cSrcweir    	if ( !pCur )
489*cdf0e10cSrcweir         SearchL10NElements( this );
490*cdf0e10cSrcweir 	else {
491*cdf0e10cSrcweir 		if( pCur->GetNodeType()==XML_NODE_TYPE_FILE) {
492*cdf0e10cSrcweir             SearchL10NElements(pCur);
493*cdf0e10cSrcweir 		}
494*cdf0e10cSrcweir 	}
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir /*****************************************************************************/
498*cdf0e10cSrcweir void XMLFile::View(){
499*cdf0e10cSrcweir /*****************************************************************************/
500*cdf0e10cSrcweir 	XMLElement* cur;
501*cdf0e10cSrcweir 	for(XMLHashMap::iterator pos=XMLStrings->begin(); pos!=XMLStrings->end();++pos){
502*cdf0e10cSrcweir 		fprintf(stdout,"\nid=%s\n",(pos->first).GetBuffer());
503*cdf0e10cSrcweir 		LangHashMap* elem=pos->second;
504*cdf0e10cSrcweir 		for(LangHashMap::iterator pos2=elem->begin(); pos2!=elem->end();++pos2){
505*cdf0e10cSrcweir 			fprintf( stdout,"\nlanguage=%s\n",(pos2->first).GetBuffer() );
506*cdf0e10cSrcweir 			cur=pos2->second;
507*cdf0e10cSrcweir 			fprintf(stdout,"\n%s\n",((XMLElement*)cur)->ToOString().getStr());
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 		}
510*cdf0e10cSrcweir 	}
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir /*****************************************************************************/
514*cdf0e10cSrcweir void XMLFile::InsertL10NElement( XMLElement* pElement ){
515*cdf0e10cSrcweir /*****************************************************************************/
516*cdf0e10cSrcweir 	ByteString tmpStr,id,oldref,language("");
517*cdf0e10cSrcweir 	LangHashMap* elem;
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir     if( pElement->GetAttributeList() != NULL ){
520*cdf0e10cSrcweir         for ( sal_uLong j = 0; j < pElement->GetAttributeList()->Count(); j++ ){
521*cdf0e10cSrcweir 		    tmpStr=ByteString( *pElement->GetAttributeList()->GetObject( j ),RTL_TEXTENCODING_UTF8 );
522*cdf0e10cSrcweir 		    if( tmpStr.CompareTo(ID)==COMPARE_EQUAL  ){	// Get the "id" Attribute
523*cdf0e10cSrcweir 			    id = ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
524*cdf0e10cSrcweir 		    }
525*cdf0e10cSrcweir 		    if( tmpStr.CompareTo( XML_LANG ) == COMPARE_EQUAL ){	// Get the "xml-lang" Attribute
526*cdf0e10cSrcweir 			    language = ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
527*cdf0e10cSrcweir 		    }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 	    }
530*cdf0e10cSrcweir     }else{
531*cdf0e10cSrcweir         fprintf(stdout,"XMLFile::InsertL10NElement: No AttributeList found");
532*cdf0e10cSrcweir         fprintf(stdout,"++++++++++++++++++++++++++++++++++++++++++++++++++");
533*cdf0e10cSrcweir         Print( pElement , 0 );
534*cdf0e10cSrcweir         fprintf(stdout,"++++++++++++++++++++++++++++++++++++++++++++++++++");
535*cdf0e10cSrcweir     }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 	XMLHashMap::iterator pos = XMLStrings->find( id );
538*cdf0e10cSrcweir 	if( pos == XMLStrings->end() ){				// No instanze , create new one
539*cdf0e10cSrcweir         elem = new LangHashMap();
540*cdf0e10cSrcweir         (*elem)[ language ]=pElement;
541*cdf0e10cSrcweir 		XMLStrings->insert( XMLHashMap::value_type( id , elem ) );
542*cdf0e10cSrcweir         order.push_back( id );
543*cdf0e10cSrcweir 	}else{									// Already there
544*cdf0e10cSrcweir         elem=pos->second;
545*cdf0e10cSrcweir         if ( (*elem)[ language ] )
546*cdf0e10cSrcweir         {
547*cdf0e10cSrcweir             fprintf(stdout,"Error: Duplicated entry. ID = %s  LANG = %s in File %s\n", id.GetBuffer(), language.GetBuffer(), ByteString( sFullName,RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
548*cdf0e10cSrcweir             exit( -1 );
549*cdf0e10cSrcweir         }
550*cdf0e10cSrcweir         (*elem)[ language ]=pElement;
551*cdf0e10cSrcweir 	}
552*cdf0e10cSrcweir }
553*cdf0e10cSrcweir /*****************************************************************************/
554*cdf0e10cSrcweir void XMLFile::showType(XMLParentNode* node){
555*cdf0e10cSrcweir /*****************************************************************************/
556*cdf0e10cSrcweir 	switch (node->GetNodeType()){
557*cdf0e10cSrcweir 		case XML_NODE_TYPE_ELEMENT: fprintf(stdout,"ELEMENT\n") ;break;
558*cdf0e10cSrcweir 		case XML_NODE_TYPE_FILE:    fprintf(stdout,"FILE\n")    ;break;
559*cdf0e10cSrcweir 		case XML_NODE_TYPE_COMMENT: fprintf(stdout,"COMMENT\n") ;break;
560*cdf0e10cSrcweir 		case XML_NODE_TYPE_DATA:    fprintf(stdout,"DATA\n")    ;break;
561*cdf0e10cSrcweir 		case XML_NODE_TYPE_DEFAULT: fprintf(stdout,"DEFAULT\n") ;break;
562*cdf0e10cSrcweir 		default: break;
563*cdf0e10cSrcweir 	}
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir XMLFile::XMLFile()
566*cdf0e10cSrcweir /*****************************************************************************/
567*cdf0e10cSrcweir 				: XMLParentNode( NULL ),
568*cdf0e10cSrcweir 				  ID           ( "id" ),
569*cdf0e10cSrcweir                   OLDREF       ( "oldref" ),
570*cdf0e10cSrcweir 				  XML_LANG     ( "xml-lang" ),
571*cdf0e10cSrcweir 				  XMLStrings   ( NULL ){};
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir XMLFile::XMLFile( const XMLFile& obj )
575*cdf0e10cSrcweir /*****************************************************************************/
576*cdf0e10cSrcweir 				: XMLParentNode( obj ),
577*cdf0e10cSrcweir 				  sFileName    ( obj.sFileName ),
578*cdf0e10cSrcweir 				  ID           ( "id" ),
579*cdf0e10cSrcweir                   OLDREF       ( "oldref" ),
580*cdf0e10cSrcweir 				  XML_LANG     ( "xml-lang" ),
581*cdf0e10cSrcweir 				  XMLStrings   ( NULL )
582*cdf0e10cSrcweir {
583*cdf0e10cSrcweir 	if( this!=&obj )
584*cdf0e10cSrcweir 	{
585*cdf0e10cSrcweir         nodes_localize  =obj.nodes_localize;
586*cdf0e10cSrcweir         order           =obj.order;
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 	}
589*cdf0e10cSrcweir }
590*cdf0e10cSrcweir /*****************************************************************************/
591*cdf0e10cSrcweir XMLFile& XMLFile::operator=(const XMLFile& obj){
592*cdf0e10cSrcweir /*****************************************************************************/
593*cdf0e10cSrcweir     if( this!=&obj ){
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir         XMLParentNode::operator=(obj);
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir         nodes_localize  =obj.nodes_localize;
598*cdf0e10cSrcweir         order           =obj.order;
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 		if( XMLStrings )    delete XMLStrings;
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 		if( obj.XMLStrings )
603*cdf0e10cSrcweir         {
604*cdf0e10cSrcweir             XMLStrings = new XMLHashMap();
605*cdf0e10cSrcweir 	        for( XMLHashMap::iterator pos = obj.XMLStrings->begin() ; pos != obj.XMLStrings->end() ; ++pos )
606*cdf0e10cSrcweir             {
607*cdf0e10cSrcweir 		        LangHashMap* elem=pos->second;
608*cdf0e10cSrcweir 		        LangHashMap* newelem = new LangHashMap();
609*cdf0e10cSrcweir                 for(LangHashMap::iterator pos2=elem->begin(); pos2!=elem->end();++pos2){
610*cdf0e10cSrcweir                     (*newelem)[ pos2->first ] = new XMLElement( *pos2->second );
611*cdf0e10cSrcweir                     printf("*");
612*cdf0e10cSrcweir 		        }
613*cdf0e10cSrcweir                 (*XMLStrings)[ pos->first ] = newelem;
614*cdf0e10cSrcweir             }
615*cdf0e10cSrcweir         }
616*cdf0e10cSrcweir     }
617*cdf0e10cSrcweir     printf("done!\n");
618*cdf0e10cSrcweir     return *this;
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir /*****************************************************************************/
623*cdf0e10cSrcweir void XMLFile::SearchL10NElements( XMLParentNode *pCur , int pos)
624*cdf0e10cSrcweir /*****************************************************************************/
625*cdf0e10cSrcweir {
626*cdf0e10cSrcweir 	static const ByteString LOCALIZE("localize");
627*cdf0e10cSrcweir 	static const ByteString THEID("id");
628*cdf0e10cSrcweir 	bool bInsert	= true;
629*cdf0e10cSrcweir 	if ( !pCur )
630*cdf0e10cSrcweir 		SearchL10NElements( this  );
631*cdf0e10cSrcweir 	else {
632*cdf0e10cSrcweir 		switch( pCur->GetNodeType()) {
633*cdf0e10cSrcweir 			case XML_NODE_TYPE_FILE: {
634*cdf0e10cSrcweir                 XMLParentNode* pElement;
635*cdf0e10cSrcweir                 if( GetChildList()){
636*cdf0e10cSrcweir                     for ( sal_uLong i = 0; i < GetChildList()->Count(); i++ ){
637*cdf0e10cSrcweir                         pElement = (XMLParentNode*) GetChildList()->GetObject( i );
638*cdf0e10cSrcweir                         if( pElement->GetNodeType() ==  XML_NODE_TYPE_ELEMENT ) SearchL10NElements( pElement , i);
639*cdf0e10cSrcweir                     }
640*cdf0e10cSrcweir                 }
641*cdf0e10cSrcweir             }
642*cdf0e10cSrcweir 			break;
643*cdf0e10cSrcweir 			case XML_NODE_TYPE_ELEMENT: {
644*cdf0e10cSrcweir 				XMLElement *pElement = ( XMLElement * ) pCur;
645*cdf0e10cSrcweir         		ByteString sName(pElement->GetName(),RTL_TEXTENCODING_ASCII_US);
646*cdf0e10cSrcweir                 ByteString language,tmpStrVal,oldref;
647*cdf0e10cSrcweir 				if ( pElement->GetAttributeList()){
648*cdf0e10cSrcweir 					for ( sal_uLong j = 0 , cnt = pElement->GetAttributeList()->Count(); j < cnt && bInsert; j++ ){
649*cdf0e10cSrcweir 						const ByteString tmpStr( *pElement->GetAttributeList()->GetObject( j ),RTL_TEXTENCODING_UTF8 );
650*cdf0e10cSrcweir 						if( tmpStr.CompareTo(THEID)==COMPARE_EQUAL  ){	// Get the "id" Attribute
651*cdf0e10cSrcweir 							tmpStrVal=ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
652*cdf0e10cSrcweir                             //printf("Checking id = %s\n",tmpStrVal.GetBuffer() );
653*cdf0e10cSrcweir 						}
654*cdf0e10cSrcweir 						if( tmpStr.CompareTo(LOCALIZE)==COMPARE_EQUAL  ){	// Get the "localize" Attribute
655*cdf0e10cSrcweir 							bInsert=false;
656*cdf0e10cSrcweir 						}
657*cdf0e10cSrcweir 						if( tmpStr.CompareTo(XML_LANG)==COMPARE_EQUAL ){	// Get the "xml-lang" Attribute
658*cdf0e10cSrcweir 							language=ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
659*cdf0e10cSrcweir 						}
660*cdf0e10cSrcweir                         if( tmpStr.CompareTo(OLDREF)==COMPARE_EQUAL ){	// Get the "oldref" Attribute
661*cdf0e10cSrcweir 		                    oldref=ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
662*cdf0e10cSrcweir 		                }
663*cdf0e10cSrcweir 					}
664*cdf0e10cSrcweir 					pElement->SetLanguageId ( language );
665*cdf0e10cSrcweir 					pElement->SetId         ( tmpStrVal.GetBuffer() );
666*cdf0e10cSrcweir                     pElement->SetOldRef     ( oldref  );
667*cdf0e10cSrcweir                     pElement->SetPos( pos );
668*cdf0e10cSrcweir 				}
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 				if ( bInsert && ( nodes_localize.find( sName.ToLowerAscii() ) != nodes_localize.end() ) )
671*cdf0e10cSrcweir 					InsertL10NElement(pElement);
672*cdf0e10cSrcweir 				else if ( bInsert && pElement->GetChildList() ){
673*cdf0e10cSrcweir 					for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ )
674*cdf0e10cSrcweir 						SearchL10NElements( (XMLParentNode*) pElement->GetChildList()->GetObject( k ) , k);
675*cdf0e10cSrcweir 				}
676*cdf0e10cSrcweir             }
677*cdf0e10cSrcweir 			break;
678*cdf0e10cSrcweir 			case XML_NODE_TYPE_DATA: {
679*cdf0e10cSrcweir 			}
680*cdf0e10cSrcweir 			break;
681*cdf0e10cSrcweir 			case XML_NODE_TYPE_COMMENT: {
682*cdf0e10cSrcweir 			}
683*cdf0e10cSrcweir 			break;
684*cdf0e10cSrcweir 			case XML_NODE_TYPE_DEFAULT: {
685*cdf0e10cSrcweir 			}
686*cdf0e10cSrcweir 			break;
687*cdf0e10cSrcweir 		}
688*cdf0e10cSrcweir 	}
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir /*****************************************************************************/
692*cdf0e10cSrcweir bool XMLFile::CheckExportStatus( XMLParentNode *pCur )
693*cdf0e10cSrcweir /*****************************************************************************/
694*cdf0e10cSrcweir {
695*cdf0e10cSrcweir     static bool bStatusExport = true;
696*cdf0e10cSrcweir     const ByteString LOCALIZE("localize");
697*cdf0e10cSrcweir     const ByteString STATUS("status");
698*cdf0e10cSrcweir     const ByteString PUBLISH("PUBLISH");
699*cdf0e10cSrcweir     const ByteString DEPRECATED("DEPRECATED");
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir     const ByteString TOPIC("topic");
702*cdf0e10cSrcweir 	bool bInsert	= true;
703*cdf0e10cSrcweir 	if ( !pCur )
704*cdf0e10cSrcweir 		CheckExportStatus( this );
705*cdf0e10cSrcweir 	else {
706*cdf0e10cSrcweir         switch( pCur->GetNodeType()) {
707*cdf0e10cSrcweir 			case XML_NODE_TYPE_FILE: {
708*cdf0e10cSrcweir                 XMLParentNode* pElement;
709*cdf0e10cSrcweir                 if( GetChildList()){
710*cdf0e10cSrcweir                     for ( sal_uLong i = 0; i < GetChildList()->Count(); i++ ){
711*cdf0e10cSrcweir                         pElement = (XMLParentNode*) GetChildList()->GetObject( i );
712*cdf0e10cSrcweir                         if( pElement->GetNodeType() ==  XML_NODE_TYPE_ELEMENT ) CheckExportStatus( pElement );//, i);
713*cdf0e10cSrcweir                     }
714*cdf0e10cSrcweir                 }
715*cdf0e10cSrcweir             }
716*cdf0e10cSrcweir 			break;
717*cdf0e10cSrcweir 			case XML_NODE_TYPE_ELEMENT: {
718*cdf0e10cSrcweir 				XMLElement *pElement = ( XMLElement * ) pCur;
719*cdf0e10cSrcweir         		ByteString sName(pElement->GetName(),RTL_TEXTENCODING_ASCII_US);
720*cdf0e10cSrcweir                 if( sName.EqualsIgnoreCaseAscii( TOPIC ) ){
721*cdf0e10cSrcweir 				    if ( pElement->GetAttributeList()){
722*cdf0e10cSrcweir 					    for ( sal_uLong j = 0 , cnt = pElement->GetAttributeList()->Count(); j < cnt && bInsert; j++ ){
723*cdf0e10cSrcweir 						    const ByteString tmpStr( *pElement->GetAttributeList()->GetObject( j ),RTL_TEXTENCODING_UTF8 );
724*cdf0e10cSrcweir                             if( tmpStr.EqualsIgnoreCaseAscii( STATUS ) ){
725*cdf0e10cSrcweir 							    ByteString tmpStrVal=ByteString( pElement->GetAttributeList()->GetObject( j )->GetValue(),RTL_TEXTENCODING_UTF8 );
726*cdf0e10cSrcweir                                 if( !tmpStrVal.EqualsIgnoreCaseAscii( PUBLISH )  &&
727*cdf0e10cSrcweir                                     !tmpStrVal.EqualsIgnoreCaseAscii( DEPRECATED )){
728*cdf0e10cSrcweir                                     bStatusExport = false;
729*cdf0e10cSrcweir                                 }
730*cdf0e10cSrcweir 						    }
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir                         }
733*cdf0e10cSrcweir                     }
734*cdf0e10cSrcweir                 }
735*cdf0e10cSrcweir 				else if ( pElement->GetChildList() ){
736*cdf0e10cSrcweir 					for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ )
737*cdf0e10cSrcweir 						CheckExportStatus( (XMLParentNode*) pElement->GetChildList()->GetObject( k ) );//, k);
738*cdf0e10cSrcweir 				}
739*cdf0e10cSrcweir             }
740*cdf0e10cSrcweir 			break;
741*cdf0e10cSrcweir 		}
742*cdf0e10cSrcweir 	}
743*cdf0e10cSrcweir     return bStatusExport;
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir /*****************************************************************************/
747*cdf0e10cSrcweir sal_uInt16 XMLElement::GetNodeType()
748*cdf0e10cSrcweir /*****************************************************************************/
749*cdf0e10cSrcweir {
750*cdf0e10cSrcweir 	return XML_NODE_TYPE_ELEMENT;
751*cdf0e10cSrcweir }
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir /*****************************************************************************/
754*cdf0e10cSrcweir XMLElement::XMLElement(const XMLElement& obj)
755*cdf0e10cSrcweir /*****************************************************************************/
756*cdf0e10cSrcweir 	:
757*cdf0e10cSrcweir                 XMLParentNode   ( obj ),
758*cdf0e10cSrcweir 				sElementName    ( obj.sElementName ),
759*cdf0e10cSrcweir 				pAttributes     ( NULL ),
760*cdf0e10cSrcweir 				project         ( obj.project ),
761*cdf0e10cSrcweir 				filename        ( obj.filename ),
762*cdf0e10cSrcweir 				id              ( obj.id ),
763*cdf0e10cSrcweir 				sOldRef         ( obj.sOldRef ),
764*cdf0e10cSrcweir 				resourceType    ( obj.resourceType ),
765*cdf0e10cSrcweir 				languageId      ( obj.languageId ),
766*cdf0e10cSrcweir                 nPos            ( obj.nPos )
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir {
769*cdf0e10cSrcweir     if ( obj.pAttributes ){
770*cdf0e10cSrcweir         pAttributes = new XMLAttributeList();
771*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < obj.pAttributes->Count(); i++ )
772*cdf0e10cSrcweir 			AddAttribute( *obj.pAttributes->GetObject( i ) , obj.pAttributes->GetObject( i )->GetValue() );
773*cdf0e10cSrcweir     }
774*cdf0e10cSrcweir }
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir /*****************************************************************************/
777*cdf0e10cSrcweir XMLElement& XMLElement::operator=(const XMLElement& obj){
778*cdf0e10cSrcweir /*****************************************************************************/
779*cdf0e10cSrcweir     if( this!=&obj ){
780*cdf0e10cSrcweir         XMLParentNode::operator=(obj);
781*cdf0e10cSrcweir         sElementName    =obj.sElementName;
782*cdf0e10cSrcweir 		project         =obj.project;
783*cdf0e10cSrcweir 		filename        =obj.filename;
784*cdf0e10cSrcweir 		id              =obj.id;
785*cdf0e10cSrcweir 		sOldRef         =obj.sOldRef;
786*cdf0e10cSrcweir 		resourceType    =obj.resourceType;
787*cdf0e10cSrcweir 		languageId      =obj.languageId;
788*cdf0e10cSrcweir         nPos            =obj.nPos;
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir         if ( pAttributes ){
791*cdf0e10cSrcweir             for ( sal_uLong i = 0; i < pAttributes->Count(); i++ )
792*cdf0e10cSrcweir 			    delete pAttributes->GetObject( i );
793*cdf0e10cSrcweir 	        delete pAttributes;
794*cdf0e10cSrcweir 	    }
795*cdf0e10cSrcweir         if ( obj.pAttributes ){
796*cdf0e10cSrcweir             pAttributes         =new XMLAttributeList();
797*cdf0e10cSrcweir             for ( sal_uLong i = 0; i < obj.pAttributes->Count(); i++ )
798*cdf0e10cSrcweir 			    AddAttribute( *obj.pAttributes->GetObject( i ) , obj.pAttributes->GetObject( i )->GetValue() );
799*cdf0e10cSrcweir         }
800*cdf0e10cSrcweir     }
801*cdf0e10cSrcweir     return *this;
802*cdf0e10cSrcweir }
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir /*****************************************************************************/
805*cdf0e10cSrcweir void XMLElement::AddAttribute( const String &rAttribute, const String &rValue )
806*cdf0e10cSrcweir /*****************************************************************************/
807*cdf0e10cSrcweir {
808*cdf0e10cSrcweir 	if ( !pAttributes )
809*cdf0e10cSrcweir 		pAttributes = new XMLAttributeList();
810*cdf0e10cSrcweir 	pAttributes->Insert( new XMLAttribute( rAttribute, rValue ), LIST_APPEND );
811*cdf0e10cSrcweir }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir /*****************************************************************************/
814*cdf0e10cSrcweir void XMLElement::ChangeLanguageTag( const String &rValue ){
815*cdf0e10cSrcweir /*****************************************************************************/
816*cdf0e10cSrcweir     static const String rName = String::CreateFromAscii("xml-lang");
817*cdf0e10cSrcweir     SetLanguageId( ByteString(rValue,RTL_TEXTENCODING_UTF8) );
818*cdf0e10cSrcweir     if ( pAttributes ){
819*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < pAttributes->Count(); i++ ){
820*cdf0e10cSrcweir             if ( *pAttributes->GetObject( i ) == rName ){
821*cdf0e10cSrcweir                 pAttributes->GetObject( i )->setValue(rValue);
822*cdf0e10cSrcweir             }
823*cdf0e10cSrcweir         }
824*cdf0e10cSrcweir     }
825*cdf0e10cSrcweir     XMLChildNode* pNode  = NULL;
826*cdf0e10cSrcweir     XMLElement*   pElem  = NULL;
827*cdf0e10cSrcweir     XMLChildNodeList* pCList = GetChildList();
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir     if( pCList != NULL ){
830*cdf0e10cSrcweir         for ( sal_uLong i = 0; i < pCList->Count(); i++ ){
831*cdf0e10cSrcweir 			pNode = pCList->GetObject( i );
832*cdf0e10cSrcweir             if( pNode != NULL && pNode->GetNodeType() == XML_NODE_TYPE_ELEMENT ){
833*cdf0e10cSrcweir                 pElem = static_cast< XMLElement* >(pNode);
834*cdf0e10cSrcweir                 pElem->ChangeLanguageTag( rValue );
835*cdf0e10cSrcweir                 pElem->SetLanguageId( ByteString(rValue,RTL_TEXTENCODING_UTF8) );
836*cdf0e10cSrcweir                 pElem  = NULL;
837*cdf0e10cSrcweir                 pNode  = NULL;
838*cdf0e10cSrcweir             }
839*cdf0e10cSrcweir         }
840*cdf0e10cSrcweir         pCList = NULL;
841*cdf0e10cSrcweir     }
842*cdf0e10cSrcweir }
843*cdf0e10cSrcweir /*****************************************************************************/
844*cdf0e10cSrcweir XMLAttribute *XMLElement::GetAttribute( const String &rName	)
845*cdf0e10cSrcweir /*****************************************************************************/
846*cdf0e10cSrcweir {
847*cdf0e10cSrcweir 	if ( pAttributes )
848*cdf0e10cSrcweir 		for ( sal_uLong i = 0; i < pAttributes->Count(); i++ )
849*cdf0e10cSrcweir 			if ( *pAttributes->GetObject( i ) == rName )
850*cdf0e10cSrcweir 				return pAttributes->GetObject( i );
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 	return NULL;
853*cdf0e10cSrcweir }
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir /*****************************************************************************/
856*cdf0e10cSrcweir XMLElement::~XMLElement()
857*cdf0e10cSrcweir /*****************************************************************************/
858*cdf0e10cSrcweir {
859*cdf0e10cSrcweir 	if ( pAttributes ) {
860*cdf0e10cSrcweir 		for ( sal_uLong i = 0; i < pAttributes->Count(); i++ )
861*cdf0e10cSrcweir 			delete pAttributes->GetObject( i );
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir 		delete pAttributes;
864*cdf0e10cSrcweir 		pAttributes = NULL;
865*cdf0e10cSrcweir 	}
866*cdf0e10cSrcweir }
867*cdf0e10cSrcweir /*****************************************************************************/
868*cdf0e10cSrcweir bool	XMLElement::Equals(OUString refStr){
869*cdf0e10cSrcweir /*****************************************************************************/
870*cdf0e10cSrcweir 	return  refStr.equals( ToOUString() );
871*cdf0e10cSrcweir }
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir /*****************************************************************************/
874*cdf0e10cSrcweir OString XMLElement::ToOString(){
875*cdf0e10cSrcweir /*****************************************************************************/
876*cdf0e10cSrcweir     OUString ouEmpty;
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir 	OUStringBuffer* buffer = new OUStringBuffer();
879*cdf0e10cSrcweir 	Print( this, *buffer , true );
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir 	OString result( (sal_Unicode* )buffer->getStr(), buffer->getLength() , RTL_TEXTENCODING_UTF8 );
882*cdf0e10cSrcweir 	delete buffer;
883*cdf0e10cSrcweir 	return result;
884*cdf0e10cSrcweir }
885*cdf0e10cSrcweir /*****************************************************************************/
886*cdf0e10cSrcweir OUString XMLElement::ToOUString(){
887*cdf0e10cSrcweir /*****************************************************************************/
888*cdf0e10cSrcweir 	OUStringBuffer* buffer = new OUStringBuffer();
889*cdf0e10cSrcweir 	Print(this,*buffer,true);
890*cdf0e10cSrcweir 	OUString result=buffer->makeStringAndClear();
891*cdf0e10cSrcweir 	String xy(result.getStr());
892*cdf0e10cSrcweir     result=OUString(xy);
893*cdf0e10cSrcweir 	delete buffer;
894*cdf0e10cSrcweir 	return result;
895*cdf0e10cSrcweir }
896*cdf0e10cSrcweir /*****************************************************************************/
897*cdf0e10cSrcweir void XMLElement::Print(XMLNode *pCur, OUStringBuffer& buffer , bool rootelement ){
898*cdf0e10cSrcweir /*****************************************************************************/
899*cdf0e10cSrcweir     //YD FIXME somewhere COMMENT is defined as 4!
900*cdf0e10cSrcweir     static const String _COMMENT = String::CreateFromAscii("comment");
901*cdf0e10cSrcweir     static const OUString XML_LANG ( OUString::createFromAscii("xml-lang") );
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir     if(pCur!=NULL){
904*cdf0e10cSrcweir         if(rootelement){
905*cdf0e10cSrcweir             XMLElement *pElement = ( XMLElement * ) pCur;
906*cdf0e10cSrcweir             if ( pElement->GetAttributeList()){
907*cdf0e10cSrcweir                 if ( pElement->GetChildList()){
908*cdf0e10cSrcweir                     XMLChildNode* tmp=NULL;
909*cdf0e10cSrcweir                     for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ ){
910*cdf0e10cSrcweir 				        tmp=pElement->GetChildList()->GetObject( k );
911*cdf0e10cSrcweir                         Print( tmp, buffer , false);
912*cdf0e10cSrcweir                     }
913*cdf0e10cSrcweir 				}
914*cdf0e10cSrcweir 			}
915*cdf0e10cSrcweir         }
916*cdf0e10cSrcweir         else{
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir         switch( pCur->GetNodeType()) {
919*cdf0e10cSrcweir 			case XML_NODE_TYPE_ELEMENT: {
920*cdf0e10cSrcweir 				XMLElement *pElement = ( XMLElement * ) pCur;
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir                 if(  !pElement->GetName().EqualsIgnoreCaseAscii( _COMMENT ) ){
923*cdf0e10cSrcweir                     buffer.append( OUString::createFromAscii("\\<") );
924*cdf0e10cSrcweir 				    buffer.append( pElement->GetName() );
925*cdf0e10cSrcweir 				    if ( pElement->GetAttributeList()){
926*cdf0e10cSrcweir 					    for ( sal_uLong j = 0; j < pElement->GetAttributeList()->Count(); j++ ){
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir                             OUString aAttrName( *pElement->GetAttributeList()->GetObject( j ) );
929*cdf0e10cSrcweir                             if( !aAttrName.equalsIgnoreAsciiCase( XML_LANG ) ) {
930*cdf0e10cSrcweir                                 buffer.append( OUString::createFromAscii(" ") );
931*cdf0e10cSrcweir                                 buffer.append( aAttrName );
932*cdf0e10cSrcweir                                 buffer.append( OUString::createFromAscii("=") );
933*cdf0e10cSrcweir 						        buffer.append( OUString::createFromAscii("\\\"") );
934*cdf0e10cSrcweir 					            buffer.append( pElement->GetAttributeList()->GetObject( j )->GetValue() );
935*cdf0e10cSrcweir 						        buffer.append( OUString::createFromAscii("\\\"") );
936*cdf0e10cSrcweir                             }
937*cdf0e10cSrcweir 					    }
938*cdf0e10cSrcweir                     }
939*cdf0e10cSrcweir 				    if ( !pElement->GetChildList())
940*cdf0e10cSrcweir 					    buffer.append( OUString::createFromAscii("/\\>") );
941*cdf0e10cSrcweir 				    else {
942*cdf0e10cSrcweir 					    buffer.append( OUString::createFromAscii("\\>") );
943*cdf0e10cSrcweir                         XMLChildNode* tmp=NULL;
944*cdf0e10cSrcweir                         for ( sal_uLong k = 0; k < pElement->GetChildList()->Count(); k++ ){
945*cdf0e10cSrcweir 						    tmp=pElement->GetChildList()->GetObject( k );
946*cdf0e10cSrcweir                             Print( tmp, buffer , false);
947*cdf0e10cSrcweir                         }
948*cdf0e10cSrcweir 					    buffer.append( OUString::createFromAscii("\\</") );
949*cdf0e10cSrcweir 				        buffer.append( pElement->GetName() );
950*cdf0e10cSrcweir                         buffer.append( OUString::createFromAscii("\\>") );
951*cdf0e10cSrcweir 	                }
952*cdf0e10cSrcweir                 }
953*cdf0e10cSrcweir 			}
954*cdf0e10cSrcweir 			break;
955*cdf0e10cSrcweir 			case XML_NODE_TYPE_DATA: {
956*cdf0e10cSrcweir 				XMLData *pData = ( XMLData * ) pCur;
957*cdf0e10cSrcweir 				String sData = pData->GetData();
958*cdf0e10cSrcweir                 buffer.append( sData );
959*cdf0e10cSrcweir 			}
960*cdf0e10cSrcweir 			break;
961*cdf0e10cSrcweir 			case XML_NODE_TYPE_COMMENT: {
962*cdf0e10cSrcweir 				XMLComment *pComment = ( XMLComment * ) pCur;
963*cdf0e10cSrcweir 				buffer.append( OUString::createFromAscii("<!--") );
964*cdf0e10cSrcweir 			    buffer.append( pComment->GetComment() );
965*cdf0e10cSrcweir 			    buffer.append( OUString::createFromAscii("-->") );
966*cdf0e10cSrcweir 			}
967*cdf0e10cSrcweir 			break;
968*cdf0e10cSrcweir 			case XML_NODE_TYPE_DEFAULT: {
969*cdf0e10cSrcweir 				XMLDefault *pDefault = ( XMLDefault * ) pCur;
970*cdf0e10cSrcweir 				buffer.append( pDefault->GetDefault() );
971*cdf0e10cSrcweir 			}
972*cdf0e10cSrcweir 			break;
973*cdf0e10cSrcweir 		}
974*cdf0e10cSrcweir         }
975*cdf0e10cSrcweir     }else {
976*cdf0e10cSrcweir         fprintf(stdout,"\n#+------Error: NULL Pointer in XMLELement::Print------+#\n");
977*cdf0e10cSrcweir         return;
978*cdf0e10cSrcweir     }
979*cdf0e10cSrcweir }
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir //
983*cdf0e10cSrcweir // class XMLData
984*cdf0e10cSrcweir //
985*cdf0e10cSrcweir /*****************************************************************************/
986*cdf0e10cSrcweir XMLData::XMLData(const XMLData& obj)
987*cdf0e10cSrcweir /*****************************************************************************/
988*cdf0e10cSrcweir 	: XMLChildNode( obj ),
989*cdf0e10cSrcweir       sData( obj.sData ) ,
990*cdf0e10cSrcweir       isNewCreated ( obj.isNewCreated ){}
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir /*****************************************************************************/
993*cdf0e10cSrcweir XMLData& XMLData::operator=(const XMLData& obj){
994*cdf0e10cSrcweir /*****************************************************************************/
995*cdf0e10cSrcweir 	if( this!=&obj ){
996*cdf0e10cSrcweir         XMLChildNode::operator=( obj );
997*cdf0e10cSrcweir         sData           = obj.sData;
998*cdf0e10cSrcweir         isNewCreated    = obj.isNewCreated;
999*cdf0e10cSrcweir     }
1000*cdf0e10cSrcweir     return *this;
1001*cdf0e10cSrcweir }
1002*cdf0e10cSrcweir /*****************************************************************************/
1003*cdf0e10cSrcweir void XMLData::AddData( const String &rData) {
1004*cdf0e10cSrcweir /*****************************************************************************/
1005*cdf0e10cSrcweir 	sData += rData;
1006*cdf0e10cSrcweir }
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir /*****************************************************************************/
1009*cdf0e10cSrcweir sal_uInt16 XMLData::GetNodeType()
1010*cdf0e10cSrcweir /*****************************************************************************/
1011*cdf0e10cSrcweir {
1012*cdf0e10cSrcweir 	return XML_NODE_TYPE_DATA;
1013*cdf0e10cSrcweir }
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir //
1016*cdf0e10cSrcweir // class XMLComment
1017*cdf0e10cSrcweir //
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir /*****************************************************************************/
1020*cdf0e10cSrcweir sal_uInt16 XMLComment::GetNodeType()
1021*cdf0e10cSrcweir /*****************************************************************************/
1022*cdf0e10cSrcweir {
1023*cdf0e10cSrcweir 	return XML_NODE_TYPE_COMMENT;
1024*cdf0e10cSrcweir }
1025*cdf0e10cSrcweir /*****************************************************************************/
1026*cdf0e10cSrcweir XMLComment::XMLComment(const XMLComment& obj)
1027*cdf0e10cSrcweir /*****************************************************************************/
1028*cdf0e10cSrcweir 	: XMLChildNode( obj ),
1029*cdf0e10cSrcweir       sComment( obj.sComment ){}
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir /*****************************************************************************/
1032*cdf0e10cSrcweir XMLComment& XMLComment::operator=(const XMLComment& obj){
1033*cdf0e10cSrcweir /*****************************************************************************/
1034*cdf0e10cSrcweir 	if( this!=&obj ){
1035*cdf0e10cSrcweir         XMLChildNode::operator=( obj );
1036*cdf0e10cSrcweir         sComment        = obj.sComment;
1037*cdf0e10cSrcweir     }
1038*cdf0e10cSrcweir     return *this;
1039*cdf0e10cSrcweir }
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir //
1042*cdf0e10cSrcweir // class XMLDefault
1043*cdf0e10cSrcweir //
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir /*****************************************************************************/
1046*cdf0e10cSrcweir sal_uInt16 XMLDefault::GetNodeType()
1047*cdf0e10cSrcweir /*****************************************************************************/
1048*cdf0e10cSrcweir {
1049*cdf0e10cSrcweir 	return XML_NODE_TYPE_DEFAULT;
1050*cdf0e10cSrcweir }
1051*cdf0e10cSrcweir /*****************************************************************************/
1052*cdf0e10cSrcweir XMLDefault::XMLDefault(const XMLDefault& obj)
1053*cdf0e10cSrcweir /*****************************************************************************/
1054*cdf0e10cSrcweir 	: XMLChildNode( obj ),
1055*cdf0e10cSrcweir       sDefault( obj.sDefault){}
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir /*****************************************************************************/
1058*cdf0e10cSrcweir XMLDefault& XMLDefault::operator=(const XMLDefault& obj){
1059*cdf0e10cSrcweir /*****************************************************************************/
1060*cdf0e10cSrcweir 	if( this!=&obj ){
1061*cdf0e10cSrcweir         XMLChildNode::operator=( obj );
1062*cdf0e10cSrcweir         sDefault        = obj.sDefault;
1063*cdf0e10cSrcweir     }
1064*cdf0e10cSrcweir     return *this;
1065*cdf0e10cSrcweir }
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir //
1069*cdf0e10cSrcweir // class SimpleXMLParser
1070*cdf0e10cSrcweir //
1071*cdf0e10cSrcweir 
1072*cdf0e10cSrcweir #define XML_CHAR_TO_OUSTRING(x) OStringToOUString(OString(x), RTL_TEXTENCODING_UTF8)
1073*cdf0e10cSrcweir #define XML_CHAR_N_TO_OUSTRING(x,n) OStringToOUString(OString(x,n), RTL_TEXTENCODING_UTF8 )
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir /*****************************************************************************/
1077*cdf0e10cSrcweir SimpleXMLParser::SimpleXMLParser()
1078*cdf0e10cSrcweir /*****************************************************************************/
1079*cdf0e10cSrcweir 				: pXMLFile( NULL )
1080*cdf0e10cSrcweir {
1081*cdf0e10cSrcweir     aParser = XML_ParserCreate( NULL );
1082*cdf0e10cSrcweir 	XML_SetUserData( aParser, this );
1083*cdf0e10cSrcweir 	XML_SetElementHandler( aParser, (XML_StartElementHandler) StartElementHandler, (XML_EndElementHandler) EndElementHandler );
1084*cdf0e10cSrcweir 	XML_SetCharacterDataHandler( aParser, (XML_CharacterDataHandler) CharacterDataHandler );
1085*cdf0e10cSrcweir 	XML_SetCommentHandler( aParser, (XML_CommentHandler) CommentHandler );
1086*cdf0e10cSrcweir 	XML_SetDefaultHandler( aParser, (XML_DefaultHandler) DefaultHandler );
1087*cdf0e10cSrcweir }
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir /*****************************************************************************/
1090*cdf0e10cSrcweir SimpleXMLParser::~SimpleXMLParser()
1091*cdf0e10cSrcweir /*****************************************************************************/
1092*cdf0e10cSrcweir {
1093*cdf0e10cSrcweir 	XML_ParserFree( aParser );
1094*cdf0e10cSrcweir }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir /*****************************************************************************/
1097*cdf0e10cSrcweir void SimpleXMLParser::StartElementHandler(
1098*cdf0e10cSrcweir 	void *userData, const XML_Char *name, const XML_Char **atts )
1099*cdf0e10cSrcweir /*****************************************************************************/
1100*cdf0e10cSrcweir {
1101*cdf0e10cSrcweir 	(( SimpleXMLParser * ) userData )->StartElement( name, atts );
1102*cdf0e10cSrcweir }
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir /*****************************************************************************/
1106*cdf0e10cSrcweir void SimpleXMLParser::EndElementHandler(
1107*cdf0e10cSrcweir 	void *userData, const XML_Char *name )
1108*cdf0e10cSrcweir /*****************************************************************************/
1109*cdf0e10cSrcweir {
1110*cdf0e10cSrcweir 	(( SimpleXMLParser * ) userData )->EndElement( name );
1111*cdf0e10cSrcweir }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir /*****************************************************************************/
1114*cdf0e10cSrcweir void SimpleXMLParser::CharacterDataHandler(
1115*cdf0e10cSrcweir 	void *userData, const XML_Char *s, int len )
1116*cdf0e10cSrcweir /*****************************************************************************/
1117*cdf0e10cSrcweir {
1118*cdf0e10cSrcweir 	(( SimpleXMLParser * ) userData )->CharacterData( s, len );
1119*cdf0e10cSrcweir }
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir /*****************************************************************************/
1122*cdf0e10cSrcweir void SimpleXMLParser::CommentHandler(
1123*cdf0e10cSrcweir 	void *userData, const XML_Char *data )
1124*cdf0e10cSrcweir /*****************************************************************************/
1125*cdf0e10cSrcweir {
1126*cdf0e10cSrcweir 	(( SimpleXMLParser * ) userData )->Comment( data );
1127*cdf0e10cSrcweir }
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir /*****************************************************************************/
1130*cdf0e10cSrcweir void SimpleXMLParser::DefaultHandler(
1131*cdf0e10cSrcweir 	void *userData, const XML_Char *s, int len )
1132*cdf0e10cSrcweir /*****************************************************************************/
1133*cdf0e10cSrcweir {
1134*cdf0e10cSrcweir 	(( SimpleXMLParser * ) userData )->Default( s, len );
1135*cdf0e10cSrcweir }
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir /*****************************************************************************/
1138*cdf0e10cSrcweir void SimpleXMLParser::StartElement(
1139*cdf0e10cSrcweir 	const XML_Char *name, const XML_Char **atts )
1140*cdf0e10cSrcweir /*****************************************************************************/
1141*cdf0e10cSrcweir {
1142*cdf0e10cSrcweir 	String sElementName = String( XML_CHAR_TO_OUSTRING( name ));
1143*cdf0e10cSrcweir 	XMLElement *pElement = new XMLElement( sElementName, ( XMLParentNode * ) pCurNode );
1144*cdf0e10cSrcweir 	pCurNode = pElement;
1145*cdf0e10cSrcweir 	pCurData = NULL;
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir 	int i = 0;
1148*cdf0e10cSrcweir 	while( atts[i] ) {
1149*cdf0e10cSrcweir 		pElement->AddAttribute(
1150*cdf0e10cSrcweir 			String( XML_CHAR_TO_OUSTRING( atts[ i ] )),
1151*cdf0e10cSrcweir 			String( XML_CHAR_TO_OUSTRING( atts[ i + 1 ] )));
1152*cdf0e10cSrcweir 		i += 2;
1153*cdf0e10cSrcweir 	}
1154*cdf0e10cSrcweir }
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir /*****************************************************************************/
1157*cdf0e10cSrcweir void SimpleXMLParser::EndElement( const XML_Char *name )
1158*cdf0e10cSrcweir /*****************************************************************************/
1159*cdf0e10cSrcweir {
1160*cdf0e10cSrcweir 	// This variable is not used at all, but the the sax C interface can't be changed
1161*cdf0e10cSrcweir     // To prevent warnings this dummy assignment is used
1162*cdf0e10cSrcweir     // +++
1163*cdf0e10cSrcweir     (void) name;
1164*cdf0e10cSrcweir 
1165*cdf0e10cSrcweir     pCurNode = pCurNode->GetParent();
1166*cdf0e10cSrcweir 	pCurData = NULL;
1167*cdf0e10cSrcweir }
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir /*****************************************************************************/
1170*cdf0e10cSrcweir void SimpleXMLParser::CharacterData(
1171*cdf0e10cSrcweir 	const XML_Char *s, int len )
1172*cdf0e10cSrcweir /*****************************************************************************/
1173*cdf0e10cSrcweir {
1174*cdf0e10cSrcweir 	if ( !pCurData ){
1175*cdf0e10cSrcweir 		String x=String( XML_CHAR_N_TO_OUSTRING( s, len ));
1176*cdf0e10cSrcweir 		XMLUtil::UnQuotHTML(x);
1177*cdf0e10cSrcweir 		pCurData = new XMLData( x , pCurNode );
1178*cdf0e10cSrcweir 	}else{
1179*cdf0e10cSrcweir 		String x=String( XML_CHAR_N_TO_OUSTRING( s, len ));
1180*cdf0e10cSrcweir 		XMLUtil::UnQuotHTML(x);
1181*cdf0e10cSrcweir 		pCurData->AddData( x );
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir 	}
1184*cdf0e10cSrcweir }
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir /*****************************************************************************/
1187*cdf0e10cSrcweir void SimpleXMLParser::Comment(
1188*cdf0e10cSrcweir 	const XML_Char *data )
1189*cdf0e10cSrcweir /*****************************************************************************/
1190*cdf0e10cSrcweir {
1191*cdf0e10cSrcweir 	pCurData = NULL;
1192*cdf0e10cSrcweir 		new XMLComment( String( XML_CHAR_TO_OUSTRING( data )), pCurNode );
1193*cdf0e10cSrcweir }
1194*cdf0e10cSrcweir 
1195*cdf0e10cSrcweir /*****************************************************************************/
1196*cdf0e10cSrcweir void SimpleXMLParser::Default(
1197*cdf0e10cSrcweir 	const XML_Char *s, int len )
1198*cdf0e10cSrcweir /*****************************************************************************/
1199*cdf0e10cSrcweir {
1200*cdf0e10cSrcweir 	pCurData = NULL;
1201*cdf0e10cSrcweir 	new XMLDefault(
1202*cdf0e10cSrcweir 		String( XML_CHAR_N_TO_OUSTRING( s, len )), pCurNode );
1203*cdf0e10cSrcweir }
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir /*****************************************************************************/
1206*cdf0e10cSrcweir XMLFile *SimpleXMLParser::Execute( const String &rFullFileName , const String &rFileName, XMLFile* pXMLFileIn )
1207*cdf0e10cSrcweir /*****************************************************************************/
1208*cdf0e10cSrcweir {
1209*cdf0e10cSrcweir //	printf("DBG: SimpleXMLParser::Execute( %s )", ByteString( rFileName , RTL_TEXTENCODING_ASCII_US ).GetBuffer() );
1210*cdf0e10cSrcweir     aErrorInformation.eCode = XML_ERROR_NONE;
1211*cdf0e10cSrcweir 	aErrorInformation.nLine = 0;
1212*cdf0e10cSrcweir 	aErrorInformation.nColumn = 0;
1213*cdf0e10cSrcweir 	aErrorInformation.sMessage = String::CreateFromAscii( "ERROR: Unable to open file " );
1214*cdf0e10cSrcweir 	aErrorInformation.sMessage += rFileName;
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 	SvFileStream aStream( rFileName, STREAM_STD_READ );
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir 	if ( !aStream.IsOpen())
1219*cdf0e10cSrcweir 		return NULL;
1220*cdf0e10cSrcweir 
1221*cdf0e10cSrcweir 	SvMemoryStream aMemStream;
1222*cdf0e10cSrcweir 	aStream >> aMemStream;
1223*cdf0e10cSrcweir 	aMemStream.Seek( 0 );
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 	aStream.Close();
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir     pXMLFile = pXMLFileIn;
1228*cdf0e10cSrcweir     pXMLFile->SetName( rFileName );
1229*cdf0e10cSrcweir     pXMLFile->SetFullName( rFullFileName );
1230*cdf0e10cSrcweir 
1231*cdf0e10cSrcweir 	return Execute( &aMemStream );
1232*cdf0e10cSrcweir }
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir /*****************************************************************************/
1235*cdf0e10cSrcweir XMLFile *SimpleXMLParser::Execute( SvMemoryStream *pStream )
1236*cdf0e10cSrcweir /*****************************************************************************/
1237*cdf0e10cSrcweir {
1238*cdf0e10cSrcweir 	if ( !pXMLFile )
1239*cdf0e10cSrcweir 		pXMLFile = new XMLFile( String());
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir 	pCurNode = pXMLFile;
1242*cdf0e10cSrcweir 	pCurData = NULL;
1243*cdf0e10cSrcweir 
1244*cdf0e10cSrcweir 	sal_uLong nPos = pStream->Tell();
1245*cdf0e10cSrcweir 	pStream->Seek( STREAM_SEEK_TO_END );
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir 	aErrorInformation.eCode = XML_ERROR_NONE;
1248*cdf0e10cSrcweir 	aErrorInformation.nLine = 0;
1249*cdf0e10cSrcweir 	aErrorInformation.nColumn = 0;
1250*cdf0e10cSrcweir 	if ( pXMLFile->GetName().Len()) {
1251*cdf0e10cSrcweir 		aErrorInformation.sMessage = String::CreateFromAscii( "File " );
1252*cdf0e10cSrcweir 		aErrorInformation.sMessage += pXMLFile->GetName();
1253*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromAscii( " parsed succesfully" );
1254*cdf0e10cSrcweir 	}
1255*cdf0e10cSrcweir 	else
1256*cdf0e10cSrcweir 		aErrorInformation.sMessage = String::CreateFromAscii( "XML-File parsed successfully" );
1257*cdf0e10cSrcweir 
1258*cdf0e10cSrcweir 	if ( !XML_Parse(
1259*cdf0e10cSrcweir 		aParser, ( char * ) pStream->GetData() + nPos, pStream->Tell() - nPos, sal_True ))
1260*cdf0e10cSrcweir 	{
1261*cdf0e10cSrcweir 		aErrorInformation.eCode = XML_GetErrorCode( aParser );
1262*cdf0e10cSrcweir 		aErrorInformation.nLine = XML_GetErrorLineNumber( aParser );
1263*cdf0e10cSrcweir 		aErrorInformation.nColumn = XML_GetErrorColumnNumber( aParser );
1264*cdf0e10cSrcweir 
1265*cdf0e10cSrcweir 		aErrorInformation.sMessage = String::CreateFromAscii( "ERROR: " );
1266*cdf0e10cSrcweir 		if ( pXMLFile->GetName().Len())
1267*cdf0e10cSrcweir 			aErrorInformation.sMessage += pXMLFile->GetName();
1268*cdf0e10cSrcweir 		else
1269*cdf0e10cSrcweir 			aErrorInformation.sMessage += String::CreateFromAscii( "XML-File" );
1270*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromAscii( " (" );
1271*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromInt64( aErrorInformation.nLine );
1272*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromAscii( "," );
1273*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromInt64( aErrorInformation.nColumn );
1274*cdf0e10cSrcweir 		aErrorInformation.sMessage += String::CreateFromAscii( "): " );
1275*cdf0e10cSrcweir 
1276*cdf0e10cSrcweir 		switch( aErrorInformation.eCode ) {
1277*cdf0e10cSrcweir   			case XML_ERROR_NO_MEMORY: aErrorInformation.sMessage += String::CreateFromAscii( "No memory" ); break;
1278*cdf0e10cSrcweir   			case XML_ERROR_SYNTAX: aErrorInformation.sMessage += String::CreateFromAscii( "Syntax" ); break;
1279*cdf0e10cSrcweir   			case XML_ERROR_NO_ELEMENTS: aErrorInformation.sMessage += String::CreateFromAscii( "No elements" ); break;
1280*cdf0e10cSrcweir   			case XML_ERROR_INVALID_TOKEN: aErrorInformation.sMessage += String::CreateFromAscii( "Invalid token" ); break;
1281*cdf0e10cSrcweir   			case XML_ERROR_UNCLOSED_TOKEN: aErrorInformation.sMessage += String::CreateFromAscii( "Unclosed token" ); break;
1282*cdf0e10cSrcweir   			case XML_ERROR_PARTIAL_CHAR: aErrorInformation.sMessage += String::CreateFromAscii( "Partial char" ); break;
1283*cdf0e10cSrcweir   			case XML_ERROR_TAG_MISMATCH: aErrorInformation.sMessage += String::CreateFromAscii( "Tag mismatch" ); break;
1284*cdf0e10cSrcweir   			case XML_ERROR_DUPLICATE_ATTRIBUTE: aErrorInformation.sMessage += String::CreateFromAscii( "Dublicat attribute" ); break;
1285*cdf0e10cSrcweir   			case XML_ERROR_JUNK_AFTER_DOC_ELEMENT: aErrorInformation.sMessage += String::CreateFromAscii( "Junk after doc element" ); break;
1286*cdf0e10cSrcweir   			case XML_ERROR_PARAM_ENTITY_REF: aErrorInformation.sMessage += String::CreateFromAscii( "Param entity ref" ); break;
1287*cdf0e10cSrcweir   			case XML_ERROR_UNDEFINED_ENTITY: aErrorInformation.sMessage += String::CreateFromAscii( "Undefined entity" ); break;
1288*cdf0e10cSrcweir   			case XML_ERROR_RECURSIVE_ENTITY_REF: aErrorInformation.sMessage += String::CreateFromAscii( "Recursive entity ref" ); break;
1289*cdf0e10cSrcweir   			case XML_ERROR_ASYNC_ENTITY: aErrorInformation.sMessage += String::CreateFromAscii( "Async_entity" ); break;
1290*cdf0e10cSrcweir   			case XML_ERROR_BAD_CHAR_REF: aErrorInformation.sMessage += String::CreateFromAscii( "Bad char ref" ); break;
1291*cdf0e10cSrcweir   			case XML_ERROR_BINARY_ENTITY_REF: aErrorInformation.sMessage += String::CreateFromAscii( "Binary entity" ); break;
1292*cdf0e10cSrcweir   			case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF: aErrorInformation.sMessage += String::CreateFromAscii( "Attribute external entity ref" ); break;
1293*cdf0e10cSrcweir   			case XML_ERROR_MISPLACED_XML_PI: aErrorInformation.sMessage += String::CreateFromAscii( "Misplaced xml pi" ); break;
1294*cdf0e10cSrcweir   			case XML_ERROR_UNKNOWN_ENCODING: aErrorInformation.sMessage += String::CreateFromAscii( "Unknown encoding" ); break;
1295*cdf0e10cSrcweir   			case XML_ERROR_INCORRECT_ENCODING: aErrorInformation.sMessage += String::CreateFromAscii( "Incorrect encoding" ); break;
1296*cdf0e10cSrcweir   			case XML_ERROR_UNCLOSED_CDATA_SECTION: aErrorInformation.sMessage += String::CreateFromAscii( "Unclosed cdata section" ); break;
1297*cdf0e10cSrcweir   			case XML_ERROR_EXTERNAL_ENTITY_HANDLING: aErrorInformation.sMessage += String::CreateFromAscii( "External entity handling" ); break;
1298*cdf0e10cSrcweir   			case XML_ERROR_NOT_STANDALONE: aErrorInformation.sMessage += String::CreateFromAscii( "Not standalone" ); break;
1299*cdf0e10cSrcweir             case XML_ERROR_NONE: break;
1300*cdf0e10cSrcweir             default:
1301*cdf0e10cSrcweir                 break;
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 		}
1304*cdf0e10cSrcweir 		delete pXMLFile;
1305*cdf0e10cSrcweir 		pXMLFile = NULL;
1306*cdf0e10cSrcweir 	}
1307*cdf0e10cSrcweir 	pStream->Seek( nPos );
1308*cdf0e10cSrcweir 
1309*cdf0e10cSrcweir 	return pXMLFile;
1310*cdf0e10cSrcweir }
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir /*****************************************************************************/
1313*cdf0e10cSrcweir void XMLUtil::QuotHTML( String &rString )
1314*cdf0e10cSrcweir /*****************************************************************************/
1315*cdf0e10cSrcweir {
1316*cdf0e10cSrcweir 	OUStringBuffer sReturn;
1317*cdf0e10cSrcweir 	static const String LT(String::CreateFromAscii("<"));
1318*cdf0e10cSrcweir 	static const String QLT(String::CreateFromAscii("&lt;"));
1319*cdf0e10cSrcweir 	static const String GT(String::CreateFromAscii(">"));
1320*cdf0e10cSrcweir 	static const String QGT(String::CreateFromAscii("&gt;"));
1321*cdf0e10cSrcweir 	static const String QUOT(String::CreateFromAscii("\\"));
1322*cdf0e10cSrcweir 	static const String QQUOT(String::CreateFromAscii("&quot;"));
1323*cdf0e10cSrcweir 	static const String APOS(String::CreateFromAscii("\""));
1324*cdf0e10cSrcweir 	static const String QAPOS(String::CreateFromAscii("&apos;"));
1325*cdf0e10cSrcweir 	static const String AMP(String::CreateFromAscii("&"));
1326*cdf0e10cSrcweir 	static const String QAMP(String::CreateFromAscii("&amp;"));
1327*cdf0e10cSrcweir 	static const String SLASH(String::CreateFromAscii("\\"));
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rString.Len(); i++) {
1330*cdf0e10cSrcweir 		if ( i < rString.Len()) {
1331*cdf0e10cSrcweir 			switch ( rString.GetChar( i )) {
1332*cdf0e10cSrcweir 				case '\\': if( i+1 <= rString.Len() ){
1333*cdf0e10cSrcweir 							switch( rString.GetChar( i+1 ) ){
1334*cdf0e10cSrcweir                              case '<':  sReturn.append( LT );i++;break;
1335*cdf0e10cSrcweir                              case '>':  sReturn.append( GT );i++;break;
1336*cdf0e10cSrcweir                              case '\\': sReturn.append( QUOT );i++;break;
1337*cdf0e10cSrcweir                              case '\"': sReturn.append( APOS );i++;break;
1338*cdf0e10cSrcweir                              //case '\'': sReturn += "\'";i++;break;
1339*cdf0e10cSrcweir                              //case '&' : sRetrun += "&";i++;break;
1340*cdf0e10cSrcweir                              default:   sReturn.append( SLASH );break;
1341*cdf0e10cSrcweir 
1342*cdf0e10cSrcweir                            }
1343*cdf0e10cSrcweir                           }
1344*cdf0e10cSrcweir                         break;
1345*cdf0e10cSrcweir 
1346*cdf0e10cSrcweir                 case '<':
1347*cdf0e10cSrcweir                     sReturn.append( QLT );
1348*cdf0e10cSrcweir 					break;
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir 				case '>':
1351*cdf0e10cSrcweir                     sReturn.append( QGT );
1352*cdf0e10cSrcweir 					break;
1353*cdf0e10cSrcweir 
1354*cdf0e10cSrcweir 				case '\"':
1355*cdf0e10cSrcweir                     sReturn.append( QQUOT );
1356*cdf0e10cSrcweir 					break;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir /*				case '\'':
1359*cdf0e10cSrcweir                     sReturn += "&apos;";
1360*cdf0e10cSrcweir 					break;
1361*cdf0e10cSrcweir */
1362*cdf0e10cSrcweir 				case '&':
1363*cdf0e10cSrcweir 					if (
1364*cdf0e10cSrcweir 						  ( ( i + 4 ) < rString.Len()) &&
1365*cdf0e10cSrcweir 						  ( String( rString.Copy( i, 5 ) ).Equals( QAMP ) )
1366*cdf0e10cSrcweir 					   )
1367*cdf0e10cSrcweir 						sReturn.append( rString.GetChar( i ) );
1368*cdf0e10cSrcweir 					else
1369*cdf0e10cSrcweir 						sReturn.append( QAMP );
1370*cdf0e10cSrcweir 				break;
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir 				default:
1373*cdf0e10cSrcweir 					sReturn.append( rString.GetChar( i ) );
1374*cdf0e10cSrcweir 				break;
1375*cdf0e10cSrcweir 			}
1376*cdf0e10cSrcweir 		}
1377*cdf0e10cSrcweir 	}
1378*cdf0e10cSrcweir 	rString = String( sReturn.makeStringAndClear() );
1379*cdf0e10cSrcweir }
1380*cdf0e10cSrcweir 
1381*cdf0e10cSrcweir void XMLUtil::UnQuotHTML( String &rString ){
1382*cdf0e10cSrcweir     UnQuotData( rString );
1383*cdf0e10cSrcweir }
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir void XMLUtil::UnQuotData( String &rString_in ){
1386*cdf0e10cSrcweir 	ByteString sReturn;
1387*cdf0e10cSrcweir     ByteString sString( rString_in , RTL_TEXTENCODING_UTF8 );
1388*cdf0e10cSrcweir 	while ( sString.Len()) {
1389*cdf0e10cSrcweir 	    if ( sString.Copy( 0, 1 ) == "\\" ) {
1390*cdf0e10cSrcweir 			sReturn += "\\\\";
1391*cdf0e10cSrcweir 			sString.Erase( 0, 1 );
1392*cdf0e10cSrcweir 		}
1393*cdf0e10cSrcweir 		else if ( sString.Copy( 0, 5 ) == "&amp;" ) {
1394*cdf0e10cSrcweir 			sReturn += "&";
1395*cdf0e10cSrcweir 			sString.Erase( 0, 5 );
1396*cdf0e10cSrcweir 		}
1397*cdf0e10cSrcweir 		else if ( sString.Copy( 0, 4 ) == "&lt;" ) {
1398*cdf0e10cSrcweir 			sReturn += "<";
1399*cdf0e10cSrcweir 			sString.Erase( 0, 4 );
1400*cdf0e10cSrcweir 		}
1401*cdf0e10cSrcweir 		else if ( sString.Copy( 0, 4 ) == "&gt;" ) {
1402*cdf0e10cSrcweir 			sReturn += ">";
1403*cdf0e10cSrcweir 			sString.Erase( 0, 4 );
1404*cdf0e10cSrcweir 		}
1405*cdf0e10cSrcweir 		else if ( sString.Copy( 0, 6 ) == "&quot;" ) {
1406*cdf0e10cSrcweir 			sReturn += "\"";
1407*cdf0e10cSrcweir 			sString.Erase( 0, 6 );
1408*cdf0e10cSrcweir 		}
1409*cdf0e10cSrcweir 		else if ( sString.Copy( 0, 6 ) == "&apos;" ) {
1410*cdf0e10cSrcweir 			sReturn += "\'";
1411*cdf0e10cSrcweir 			sString.Erase( 0, 6 );
1412*cdf0e10cSrcweir 		}
1413*cdf0e10cSrcweir 		else {
1414*cdf0e10cSrcweir 			sReturn += sString.GetChar( 0 );
1415*cdf0e10cSrcweir 			sString.Erase( 0, 1 );
1416*cdf0e10cSrcweir 		}
1417*cdf0e10cSrcweir 	}
1418*cdf0e10cSrcweir     rString_in = String(sReturn , RTL_TEXTENCODING_UTF8 );
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir }
1422*cdf0e10cSrcweir 
1423*cdf0e10cSrcweir XMLUtil::XMLUtil(){
1424*cdf0e10cSrcweir }
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir /*****************************************************************************/
1428*cdf0e10cSrcweir void XMLUtil::dump(){
1429*cdf0e10cSrcweir /*****************************************************************************/
1430*cdf0e10cSrcweir 	int cnt=1;
1431*cdf0e10cSrcweir     printf("size=%lu\n",static_cast<unsigned long>(lMap.size()));
1432*cdf0e10cSrcweir     for(HashMap::iterator pos = lMap.begin(); pos != lMap.end() ; ++pos){
1433*cdf0e10cSrcweir         fprintf(stdout,"key=%s , value=%d , no=%d\n",pos->first.GetBuffer(),pos->second,cnt++);
1434*cdf0e10cSrcweir     }
1435*cdf0e10cSrcweir }
1436*cdf0e10cSrcweir /*****************************************************************************/
1437*cdf0e10cSrcweir XMLUtil&  XMLUtil::Instance(){
1438*cdf0e10cSrcweir /*****************************************************************************/
1439*cdf0e10cSrcweir 	static XMLUtil instance;
1440*cdf0e10cSrcweir 	return instance;
1441*cdf0e10cSrcweir }
1442*cdf0e10cSrcweir /*****************************************************************************/
1443*cdf0e10cSrcweir XMLUtil::~XMLUtil(){}
1444*cdf0e10cSrcweir /*****************************************************************************/
1445*cdf0e10cSrcweir /*****************************************************************************/
1446*cdf0e10cSrcweir ByteString XMLUtil::GetIsoLangByIndex( sal_uInt16 nIndex )
1447*cdf0e10cSrcweir /*****************************************************************************/
1448*cdf0e10cSrcweir {
1449*cdf0e10cSrcweir 	if(nIndex > 0 && MAX_LANGUAGES >= nIndex )
1450*cdf0e10cSrcweir 		return isoArray[nIndex];
1451*cdf0e10cSrcweir 	return "";
1452*cdf0e10cSrcweir }
1453*cdf0e10cSrcweir 
1454