xref: /AOO41X/main/xmlsecurity/source/xmlsec/saxhelper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <rtl/ustring.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "saxhelper.hxx"
34*cdf0e10cSrcweir #include "libxml/parserInternals.h"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
37*cdf0e10cSrcweir #include "libxslt/xslt.h"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace cssu = com::sun::star::uno;
41*cdf0e10cSrcweir namespace cssxs = com::sun::star::xml::sax;
42*cdf0e10cSrcweir namespace cssxcsax = com::sun::star::xml::csax;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir /**
45*cdf0e10cSrcweir  * The return value is NULL terminated. The application has the responsibilty to
46*cdf0e10cSrcweir  * deallocte the return value.
47*cdf0e10cSrcweir  */
48*cdf0e10cSrcweir xmlChar* ous_to_xmlstr( const rtl::OUString& oustr )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	rtl::OString ostr = rtl::OUStringToOString( oustr , RTL_TEXTENCODING_UTF8 ) ;
51*cdf0e10cSrcweir 	return xmlStrndup( ( xmlChar* )ostr.getStr(), ( int )ostr.getLength() ) ;
52*cdf0e10cSrcweir }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir /**
55*cdf0e10cSrcweir  * The return value is NULL terminated. The application has the responsibilty to
56*cdf0e10cSrcweir  * deallocte the return value.
57*cdf0e10cSrcweir  */
58*cdf0e10cSrcweir xmlChar* ous_to_nxmlstr( const rtl::OUString& oustr, int& length )
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	rtl::OString ostr = rtl::OUStringToOString( oustr , RTL_TEXTENCODING_UTF8 ) ;
61*cdf0e10cSrcweir 	length = ostr.getLength();
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	return xmlStrndup( ( xmlChar* )ostr.getStr(), length ) ;
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir /**
67*cdf0e10cSrcweir  * The input parameter isn't necessaryly NULL terminated.
68*cdf0e10cSrcweir  */
69*cdf0e10cSrcweir rtl::OUString xmlchar_to_ous( const xmlChar* pChar, int length )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	if( pChar != NULL )
72*cdf0e10cSrcweir 	{
73*cdf0e10cSrcweir 		return rtl::OUString( ( sal_Char* )pChar , length , RTL_TEXTENCODING_UTF8 ) ;
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir 	else
76*cdf0e10cSrcweir 	{
77*cdf0e10cSrcweir 		return rtl::OUString() ;
78*cdf0e10cSrcweir 	}
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir /**
82*cdf0e10cSrcweir  * The input parameter is NULL terminated
83*cdf0e10cSrcweir  */
84*cdf0e10cSrcweir rtl::OUString xmlstr_to_ous( const xmlChar* pStr )
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	if( pStr != NULL )
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		return xmlchar_to_ous( pStr , xmlStrlen( pStr ) ) ;
89*cdf0e10cSrcweir 	}
90*cdf0e10cSrcweir 	else
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		return rtl::OUString() ;
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir /**
97*cdf0e10cSrcweir  * The return value and the referenced value must be NULL terminated.
98*cdf0e10cSrcweir  * The application has the responsibilty to deallocte the return value.
99*cdf0e10cSrcweir  */
100*cdf0e10cSrcweir const xmlChar** attrlist_to_nxmlstr( const cssu::Sequence< cssxcsax::XMLAttribute >& aAttributes )
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir 	xmlChar* attname = NULL ;
103*cdf0e10cSrcweir 	xmlChar* attvalue = NULL ;
104*cdf0e10cSrcweir 	const xmlChar** attrs = NULL ;
105*cdf0e10cSrcweir 	rtl::OUString oustr ;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	sal_Int32 nLength = aAttributes.getLength();;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	if( nLength != 0 )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		attrs = ( const xmlChar** )xmlMalloc( ( nLength * 2 + 2 ) * sizeof( xmlChar* ) ) ;
112*cdf0e10cSrcweir 	}
113*cdf0e10cSrcweir 	else
114*cdf0e10cSrcweir 	{
115*cdf0e10cSrcweir 		return NULL ;
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	for( int i = 0 , j = 0 ; j < nLength ; ++j )
119*cdf0e10cSrcweir 	{
120*cdf0e10cSrcweir 		attname = ous_to_xmlstr( aAttributes[j].sName ) ;
121*cdf0e10cSrcweir 		attvalue = ous_to_xmlstr( aAttributes[j].sValue ) ;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 		if( attname != NULL && attvalue != NULL )
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			attrs[i++] = attname ;
126*cdf0e10cSrcweir 			attrs[i++] = attvalue ;
127*cdf0e10cSrcweir 			attrs[i] = NULL ;
128*cdf0e10cSrcweir 			attrs[i+1] = NULL ;
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 		else
131*cdf0e10cSrcweir 		{
132*cdf0e10cSrcweir 			if( attname != NULL )
133*cdf0e10cSrcweir 				xmlFree( attname ) ;
134*cdf0e10cSrcweir 			if( attvalue != NULL )
135*cdf0e10cSrcweir 				xmlFree( attvalue ) ;
136*cdf0e10cSrcweir 		}
137*cdf0e10cSrcweir 	}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	return attrs ;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir /**
143*cdf0e10cSrcweir  * Constructor
144*cdf0e10cSrcweir  *
145*cdf0e10cSrcweir  * In this constructor, a libxml sax parser context is initialized. a libxml
146*cdf0e10cSrcweir  * default sax handler is initialized with the context.
147*cdf0e10cSrcweir  */
148*cdf0e10cSrcweir SAXHelper::SAXHelper( )
149*cdf0e10cSrcweir 	: m_pParserCtxt( NULL ),
150*cdf0e10cSrcweir 	  m_pSaxHandler( NULL )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	xmlInitParser() ;
153*cdf0e10cSrcweir 	LIBXML_TEST_VERSION ;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	/*
156*cdf0e10cSrcweir 	 * compile error:
157*cdf0e10cSrcweir 	 * xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS ;
158*cdf0e10cSrcweir 	 */
159*cdf0e10cSrcweir 	xmlSubstituteEntitiesDefault( 1 ) ;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
162*cdf0e10cSrcweir 	xmlIndentTreeOutput = 1 ;
163*cdf0e10cSrcweir #endif /* XMLSEC_NO_XSLT */
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	m_pParserCtxt = xmlNewParserCtxt() ;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	/*
168*cdf0e10cSrcweir 	 * i41748
169*cdf0e10cSrcweir 	 *
170*cdf0e10cSrcweir 	 * mmi : re-initialize the SAX handler to version 1
171*cdf0e10cSrcweir 	 */
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	xmlSAXVersion(m_pParserCtxt->sax, 1);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	/* end */
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	if( m_pParserCtxt->inputTab[0] != NULL )
178*cdf0e10cSrcweir 	{
179*cdf0e10cSrcweir 		m_pParserCtxt->inputTab[0] = NULL ;
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	if( m_pParserCtxt == NULL )
183*cdf0e10cSrcweir 	{
184*cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
185*cdf0e10cSrcweir 		xsltCleanupGlobals() ;
186*cdf0e10cSrcweir #endif
187*cdf0e10cSrcweir //      see issue i74334, we cannot call xmlCleanupParser when libxml is still used
188*cdf0e10cSrcweir //		in other parts of the office.
189*cdf0e10cSrcweir //		xmlCleanupParser() ;
190*cdf0e10cSrcweir 		throw cssu::RuntimeException() ;
191*cdf0e10cSrcweir 	}
192*cdf0e10cSrcweir 	else if( m_pParserCtxt->sax == NULL )
193*cdf0e10cSrcweir 	{
194*cdf0e10cSrcweir 		xmlFreeParserCtxt( m_pParserCtxt ) ;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
197*cdf0e10cSrcweir 		xsltCleanupGlobals() ;
198*cdf0e10cSrcweir #endif
199*cdf0e10cSrcweir //      see issue i74334, we cannot call xmlCleanupParser when libxml is still used
200*cdf0e10cSrcweir //		in other parts of the office.
201*cdf0e10cSrcweir //		xmlCleanupParser() ;
202*cdf0e10cSrcweir 		m_pParserCtxt = NULL ;
203*cdf0e10cSrcweir 		throw cssu::RuntimeException() ;
204*cdf0e10cSrcweir 	}
205*cdf0e10cSrcweir 	else
206*cdf0e10cSrcweir 	{
207*cdf0e10cSrcweir 		m_pSaxHandler = m_pParserCtxt->sax ;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		//Adjust the context
210*cdf0e10cSrcweir 		m_pParserCtxt->recovery = 1 ;
211*cdf0e10cSrcweir 	}
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir /**
215*cdf0e10cSrcweir  * Destructor
216*cdf0e10cSrcweir  *
217*cdf0e10cSrcweir  * In this destructor, a libxml sax parser context is desturcted. The XML tree
218*cdf0e10cSrcweir  * in the context is not deallocated because the tree is bind with a document
219*cdf0e10cSrcweir  * model by the setTargetDocument method, which delegate the target document to
220*cdf0e10cSrcweir  * destruct the xml tree.
221*cdf0e10cSrcweir  */
222*cdf0e10cSrcweir SAXHelper::~SAXHelper() {
223*cdf0e10cSrcweir 	if( m_pParserCtxt != NULL )
224*cdf0e10cSrcweir 	{
225*cdf0e10cSrcweir 		/*
226*cdf0e10cSrcweir 		 * In the situation that no object refer the Document, this destructor
227*cdf0e10cSrcweir 		 * must deallocate the Document memory
228*cdf0e10cSrcweir 		 */
229*cdf0e10cSrcweir 		if( m_pSaxHandler == m_pParserCtxt->sax )
230*cdf0e10cSrcweir 		{
231*cdf0e10cSrcweir 			m_pSaxHandler = NULL ;
232*cdf0e10cSrcweir 		}
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 		xmlFreeParserCtxt( m_pParserCtxt ) ;
235*cdf0e10cSrcweir 		m_pParserCtxt = NULL ;
236*cdf0e10cSrcweir 	}
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	if( m_pSaxHandler != NULL )
239*cdf0e10cSrcweir 	{
240*cdf0e10cSrcweir 		xmlFree( m_pSaxHandler ) ;
241*cdf0e10cSrcweir 		m_pSaxHandler = NULL ;
242*cdf0e10cSrcweir 	}
243*cdf0e10cSrcweir //      see issue i74334, we cannot call xmlCleanupParser when libxml is still used
244*cdf0e10cSrcweir //		in other parts of the office.
245*cdf0e10cSrcweir //	xmlCleanupParser() ;
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir xmlNodePtr SAXHelper::getCurrentNode()
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	return m_pParserCtxt->node;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void SAXHelper::setCurrentNode(const xmlNodePtr pNode)
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	/*
256*cdf0e10cSrcweir 	 * This is really a black trick.
257*cdf0e10cSrcweir 	 * When the current node is replaced, the nodeTab
258*cdf0e10cSrcweir 	 * stack's top has to been replaced with the same
259*cdf0e10cSrcweir 	 * node, in order to make compatibility.
260*cdf0e10cSrcweir 	 */
261*cdf0e10cSrcweir 	m_pParserCtxt->nodeTab[m_pParserCtxt->nodeNr - 1]
262*cdf0e10cSrcweir 		= m_pParserCtxt->node
263*cdf0e10cSrcweir 			= pNode;
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir xmlDocPtr SAXHelper::getDocument()
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir 	return m_pParserCtxt->myDoc;
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir /**
272*cdf0e10cSrcweir  * XDocumentHandler -- start an xml document
273*cdf0e10cSrcweir  */
274*cdf0e10cSrcweir void SAXHelper::startDocument( void )
275*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir 	/*
278*cdf0e10cSrcweir 	 * Adjust inputTab
279*cdf0e10cSrcweir 	 */
280*cdf0e10cSrcweir 	xmlParserInputPtr pInput = xmlNewInputStream( m_pParserCtxt ) ;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	if( m_pParserCtxt->inputTab != NULL && m_pParserCtxt->inputMax != 0 )
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 		m_pParserCtxt->inputTab[0] = pInput ;
285*cdf0e10cSrcweir 		m_pParserCtxt->input = pInput ;
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	m_pSaxHandler->startDocument( m_pParserCtxt ) ;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	if( m_pParserCtxt == NULL || m_pParserCtxt->myDoc == NULL )
291*cdf0e10cSrcweir 	{
292*cdf0e10cSrcweir 		throw cssu::RuntimeException() ;
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir /**
297*cdf0e10cSrcweir  * XDocumentHandler -- end an xml document
298*cdf0e10cSrcweir  */
299*cdf0e10cSrcweir void SAXHelper::endDocument( void )
300*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir 	m_pSaxHandler->endDocument( m_pParserCtxt ) ;
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir /**
306*cdf0e10cSrcweir  * XDocumentHandler -- start an xml element
307*cdf0e10cSrcweir  */
308*cdf0e10cSrcweir void SAXHelper::startElement(
309*cdf0e10cSrcweir 	const rtl::OUString& aName,
310*cdf0e10cSrcweir 	const cssu::Sequence< cssxcsax::XMLAttribute >& aAttributes )
311*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	const xmlChar* fullName = NULL ;
314*cdf0e10cSrcweir 	const xmlChar** attrs = NULL ;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	fullName = ous_to_xmlstr( aName ) ;
317*cdf0e10cSrcweir 	attrs = attrlist_to_nxmlstr( aAttributes ) ;
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	if( fullName != NULL || attrs != NULL )
320*cdf0e10cSrcweir 	{
321*cdf0e10cSrcweir 		m_pSaxHandler->startElement( m_pParserCtxt , fullName , attrs ) ;
322*cdf0e10cSrcweir 	}
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 	if( fullName != NULL )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )fullName ) ;
327*cdf0e10cSrcweir 		fullName = NULL ;
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	if( attrs != NULL )
331*cdf0e10cSrcweir 	{
332*cdf0e10cSrcweir 		for( int i = 0 ; attrs[i] != NULL ; ++i )
333*cdf0e10cSrcweir 		{
334*cdf0e10cSrcweir 			xmlFree( ( xmlChar* )attrs[i] ) ;
335*cdf0e10cSrcweir 			attrs[i] = NULL ;
336*cdf0e10cSrcweir 		}
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 		xmlFree( ( void* ) attrs ) ;
339*cdf0e10cSrcweir 		attrs = NULL ;
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir /**
344*cdf0e10cSrcweir  * XDocumentHandler -- end an xml element
345*cdf0e10cSrcweir  */
346*cdf0e10cSrcweir void SAXHelper::endElement( const rtl::OUString& aName )
347*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
348*cdf0e10cSrcweir {
349*cdf0e10cSrcweir 	xmlChar* fullname = NULL ;
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 	fullname = ous_to_xmlstr( aName ) ;
352*cdf0e10cSrcweir 	m_pSaxHandler->endElement( m_pParserCtxt , fullname ) ;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 	if( fullname != NULL )
355*cdf0e10cSrcweir 	{
356*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )fullname ) ;
357*cdf0e10cSrcweir 		fullname = NULL ;
358*cdf0e10cSrcweir 	}
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir /**
362*cdf0e10cSrcweir  * XDocumentHandler -- an xml element or cdata characters
363*cdf0e10cSrcweir  */
364*cdf0e10cSrcweir void SAXHelper::characters( const rtl::OUString& aChars )
365*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir 	const xmlChar* chars = NULL ;
368*cdf0e10cSrcweir 	int length = 0 ;
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 	chars = ous_to_nxmlstr( aChars, length ) ;
371*cdf0e10cSrcweir 	m_pSaxHandler->characters( m_pParserCtxt , chars , length ) ;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 	if( chars != NULL )
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )chars ) ;
376*cdf0e10cSrcweir 	}
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir /**
380*cdf0e10cSrcweir  * XDocumentHandler -- ignorable xml white space
381*cdf0e10cSrcweir  */
382*cdf0e10cSrcweir void SAXHelper::ignorableWhitespace( const rtl::OUString& aWhitespaces )
383*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir 	const xmlChar* chars = NULL ;
386*cdf0e10cSrcweir 	int length = 0 ;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	chars = ous_to_nxmlstr( aWhitespaces, length ) ;
389*cdf0e10cSrcweir 	m_pSaxHandler->ignorableWhitespace( m_pParserCtxt , chars , length ) ;
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	if( chars != NULL )
392*cdf0e10cSrcweir 	{
393*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )chars ) ;
394*cdf0e10cSrcweir 	}
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir /**
398*cdf0e10cSrcweir  * XDocumentHandler -- preaorocessing instruction
399*cdf0e10cSrcweir  */
400*cdf0e10cSrcweir void SAXHelper::processingInstruction(
401*cdf0e10cSrcweir 	const rtl::OUString& aTarget,
402*cdf0e10cSrcweir 	const rtl::OUString& aData )
403*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir 	xmlChar* target = NULL ;
406*cdf0e10cSrcweir 	xmlChar* data = NULL ;
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	target = ous_to_xmlstr( aTarget ) ;
409*cdf0e10cSrcweir 	data = ous_to_xmlstr( aData ) ;
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 	m_pSaxHandler->processingInstruction( m_pParserCtxt , target , data ) ;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	if( target != NULL )
414*cdf0e10cSrcweir 	{
415*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )target ) ;
416*cdf0e10cSrcweir 		target = NULL ;
417*cdf0e10cSrcweir 	}
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	if( data != NULL )
420*cdf0e10cSrcweir 	{
421*cdf0e10cSrcweir 		xmlFree( ( xmlChar* )data ) ;
422*cdf0e10cSrcweir 		data = NULL ;
423*cdf0e10cSrcweir 	}
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir /**
427*cdf0e10cSrcweir  * XDocumentHandler -- set document locator
428*cdf0e10cSrcweir  * In this case, locator is useless.
429*cdf0e10cSrcweir  */
430*cdf0e10cSrcweir void SAXHelper::setDocumentLocator(
431*cdf0e10cSrcweir 	const cssu::Reference< cssxs::XLocator > &)
432*cdf0e10cSrcweir 	throw( cssxs::SAXException , cssu::RuntimeException )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	//--Pseudo code if necessary
435*cdf0e10cSrcweir 	//--m_pSaxLocator is a member defined as xmlSAXHabdlerPtr
436*cdf0e10cSrcweir 	//--m_pSaxLocatorHdl is a member defined as Sax_Locator
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 	//if( m_pSaxLocator != NULL ) {
439*cdf0e10cSrcweir 	//	//Deallocate the memory
440*cdf0e10cSrcweir 	//}
441*cdf0e10cSrcweir 	//if( m_pSaxLocatorHdl != NULL ) {
442*cdf0e10cSrcweir 	//	//Deallocate the memory
443*cdf0e10cSrcweir 	//}
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	//m_pSaxLocatorHdl = new Sax_Locator( xLocator ) ;
446*cdf0e10cSrcweir 	//m_pSaxLocator = { m_pSaxLocatorHdl->getPublicId , m_pSaxLocatorHdl->getSystemId , m_pSaxLocatorHdl->getLineNumber , m_pSaxLocatorHdl->getColumnNumber } ;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	//m_pSaxHandler->setDocumentLocator( m_pParserCtxt , m_pSaxLocator ) ;
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451