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