xref: /AOO41X/main/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
29*cdf0e10cSrcweir #define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
35*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "saxhelper.hxx"
38*cdf0e10cSrcweir //#include "libxml/parserInternals.h"
39*cdf0e10cSrcweir //#include "libxslt/xslt.h"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #define NODEPOSITION_NORMAL        1
42*cdf0e10cSrcweir #define NODEPOSITION_STARTELEMENT  2
43*cdf0e10cSrcweir #define NODEPOSITION_ENDELEMENT    3
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <libxml/tree.h>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir class XMLDocumentWrapper_XmlSecImpl : public cppu::WeakImplHelper4
48*cdf0e10cSrcweir <
49*cdf0e10cSrcweir 	com::sun::star::xml::wrapper::XXMLDocumentWrapper,
50*cdf0e10cSrcweir 	com::sun::star::xml::sax::XDocumentHandler,
51*cdf0e10cSrcweir 	com::sun::star::xml::csax::XCompressedDocumentHandler,
52*cdf0e10cSrcweir 	com::sun::star::lang::XServiceInfo
53*cdf0e10cSrcweir >
54*cdf0e10cSrcweir /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl *
55*cdf0e10cSrcweir  *
56*cdf0e10cSrcweir  *   NAME
57*cdf0e10cSrcweir  *	XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
58*cdf0e10cSrcweir  *	document
59*cdf0e10cSrcweir  *
60*cdf0e10cSrcweir  *   FUNCTION
61*cdf0e10cSrcweir  *	Converts SAX events into a libxml2 document, converts the document back
62*cdf0e10cSrcweir  *	into SAX event stream, and manipulate nodes in the document.
63*cdf0e10cSrcweir  *
64*cdf0e10cSrcweir  *   HISTORY
65*cdf0e10cSrcweir  *	05.01.2004 -	Interface supported: XXMLDocumentWrapper,
66*cdf0e10cSrcweir  * 			XDocumentHandler, XCompressedDocumentHandler,
67*cdf0e10cSrcweir  *			XServiceInfo
68*cdf0e10cSrcweir  *
69*cdf0e10cSrcweir  *   AUTHOR
70*cdf0e10cSrcweir  *	Michael Mi
71*cdf0e10cSrcweir  *	Email: michael.mi@sun.com
72*cdf0e10cSrcweir  ******************************************************************************/
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir private:
75*cdf0e10cSrcweir 	/* the sax helper */
76*cdf0e10cSrcweir 	SAXHelper saxHelper;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	/* the document used to convert SAX events to */
79*cdf0e10cSrcweir 	xmlDocPtr m_pDocument;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 	/* the root element */
82*cdf0e10cSrcweir 	xmlNodePtr m_pRootElement;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	/*
85*cdf0e10cSrcweir 	 * the current active element. The next incoming SAX event will be
86*cdf0e10cSrcweir 	 * appended to this element
87*cdf0e10cSrcweir 	 */
88*cdf0e10cSrcweir 	xmlNodePtr m_pCurrentElement;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	/*
91*cdf0e10cSrcweir 	 * This variable is used when converting the document or part of it into
92*cdf0e10cSrcweir 	 * SAX events. See getNextSAXEvent method.
93*cdf0e10cSrcweir 	 */
94*cdf0e10cSrcweir 	sal_Int32 m_nCurrentPosition;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	/*
97*cdf0e10cSrcweir 	 * used for recursive deletion. See recursiveDelete method
98*cdf0e10cSrcweir 	 */
99*cdf0e10cSrcweir 	xmlNodePtr m_pStopAtNode;
100*cdf0e10cSrcweir 	xmlNodePtr m_pCurrentReservedNode;
101*cdf0e10cSrcweir 	com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
102*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes;
103*cdf0e10cSrcweir 	sal_Int32 m_nReservedNodeIndex;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir private:
106*cdf0e10cSrcweir 	void getNextSAXEvent();
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	void sendStartElement(
109*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
110*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
111*cdf0e10cSrcweir 		const xmlNodePtr pNode) const
112*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	void sendEndElement(
115*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
116*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
117*cdf0e10cSrcweir 		const xmlNodePtr pNode) const
118*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	void sendNode(
121*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
122*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
123*cdf0e10cSrcweir 		const xmlNodePtr pNode) const
124*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException);
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	rtl::OString getNodeQName(const xmlNodePtr pNode) const;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	sal_Int32 recursiveDelete( const xmlNodePtr pNode);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	void getNextReservedNode();
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	void removeNode( const xmlNodePtr pNode) const;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	xmlNodePtr checkElement(
135*cdf0e10cSrcweir 		const com::sun::star::uno::Reference<
136*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement) const;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	void buildIDAttr( xmlNodePtr pNode ) const;
139*cdf0e10cSrcweir 	void rebuildIDLink( xmlNodePtr pNode ) const;
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir public:
142*cdf0e10cSrcweir 	XMLDocumentWrapper_XmlSecImpl();
143*cdf0e10cSrcweir 	virtual ~XMLDocumentWrapper_XmlSecImpl();
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	/* com::sun::star::xml::wrapper::XXMLDocumentWrapper */
146*cdf0e10cSrcweir 	virtual com::sun::star::uno::Reference<
147*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentElement(  )
148*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	virtual void SAL_CALL setCurrentElement( const com::sun::star::uno::Reference<
151*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper >& element )
152*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	virtual void SAL_CALL removeCurrentElement(  )
155*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL isCurrent( const com::sun::star::uno::Reference<
158*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
159*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL isCurrentElementEmpty(  )
162*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	virtual rtl::OUString SAL_CALL getNodeName( const com::sun::star::uno::Reference<
165*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
166*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	virtual void SAL_CALL clearUselessData(
169*cdf0e10cSrcweir 		const com::sun::star::uno::Reference<
170*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper >& node,
171*cdf0e10cSrcweir 		const com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
172*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper > >& reservedDescendants,
173*cdf0e10cSrcweir 		const com::sun::star::uno::Reference<
174*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper >& stopAtNode )
175*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	virtual void SAL_CALL collapse( const com::sun::star::uno::Reference<
178*cdf0e10cSrcweir 		com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
179*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	virtual void SAL_CALL generateSAXEvents(
182*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler,
183*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xEventKeeperHandler,
184*cdf0e10cSrcweir 		const com::sun::star::uno::Reference<
185*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper >& startNode,
186*cdf0e10cSrcweir 		const com::sun::star::uno::Reference<
187*cdf0e10cSrcweir 			com::sun::star::xml::wrapper::XXMLElementWrapper >& endNode )
188*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	virtual void SAL_CALL getTree(
191*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler )
192*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	virtual void SAL_CALL rebuildIDLink(
195*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
196*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	/* com::sun::star::xml::sax::XDocumentHandler */
199*cdf0e10cSrcweir 	virtual void SAL_CALL startDocument(  )
200*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	virtual void SAL_CALL endDocument(  )
203*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	virtual void SAL_CALL startElement(
206*cdf0e10cSrcweir 		const rtl::OUString& aName,
207*cdf0e10cSrcweir 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs )
208*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	virtual void SAL_CALL endElement( const rtl::OUString& aName )
211*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	virtual void SAL_CALL characters( const rtl::OUString& aChars )
214*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces )
217*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	virtual void SAL_CALL processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
220*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	virtual void SAL_CALL setDocumentLocator( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator )
223*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	/* com::sun::star::xml::csax::XCompressedDocumentHandler */
226*cdf0e10cSrcweir 	virtual void SAL_CALL _startDocument(  )
227*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	virtual void SAL_CALL _endDocument(  )
230*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	virtual void SAL_CALL _startElement(
233*cdf0e10cSrcweir 		const rtl::OUString& aName,
234*cdf0e10cSrcweir 		const com::sun::star::uno::Sequence<
235*cdf0e10cSrcweir 			com::sun::star::xml::csax::XMLAttribute >& aAttributes )
236*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	virtual void SAL_CALL _endElement( const rtl::OUString& aName )
239*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	virtual void SAL_CALL _characters( const rtl::OUString& aChars )
242*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 	virtual void SAL_CALL _ignorableWhitespace( const rtl::OUString& aWhitespaces )
245*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	virtual void SAL_CALL _processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
248*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	virtual void SAL_CALL _setDocumentLocator(
251*cdf0e10cSrcweir 		sal_Int32 columnNumber,
252*cdf0e10cSrcweir 		sal_Int32 lineNumber,
253*cdf0e10cSrcweir 		const rtl::OUString& publicId,
254*cdf0e10cSrcweir 		const rtl::OUString& systemId )
255*cdf0e10cSrcweir 		throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	/* com::sun::star::lang::XServiceInfo */
258*cdf0e10cSrcweir 	virtual rtl::OUString SAL_CALL getImplementationName(  )
259*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName )
262*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(  )
265*cdf0e10cSrcweir 		throw (com::sun::star::uno::RuntimeException);
266*cdf0e10cSrcweir };
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir rtl::OUString XMLDocumentWrapper_XmlSecImpl_getImplementationName()
269*cdf0e10cSrcweir 	throw ( com::sun::star::uno::RuntimeException );
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName )
272*cdf0e10cSrcweir 	throw ( com::sun::star::uno::RuntimeException );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
275*cdf0e10cSrcweir 	XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames(  )
276*cdf0e10cSrcweir 	throw ( com::sun::star::uno::RuntimeException );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
279*cdf0e10cSrcweir SAL_CALL XMLDocumentWrapper_XmlSecImpl_createInstance(
280*cdf0e10cSrcweir 	const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr)
281*cdf0e10cSrcweir 	throw ( com::sun::star::uno::Exception );
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir #endif
284*cdf0e10cSrcweir 
285