1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
29 #define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
31 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
32 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
33 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <cppuhelper/implbase4.hxx>
37 #include "saxhelper.hxx"
38 //#include "libxml/parserInternals.h"
39 //#include "libxslt/xslt.h"
41 #define NODEPOSITION_NORMAL 1
42 #define NODEPOSITION_STARTELEMENT 2
43 #define NODEPOSITION_ENDELEMENT 3
45 #include <libxml/tree.h>
47 class XMLDocumentWrapper_XmlSecImpl
: public cppu::WeakImplHelper4
49 com::sun::star::xml::wrapper::XXMLDocumentWrapper
,
50 com::sun::star::xml::sax::XDocumentHandler
,
51 com::sun::star::xml::csax::XCompressedDocumentHandler
,
52 com::sun::star::lang::XServiceInfo
54 /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl *
57 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
61 * Converts SAX events into a libxml2 document, converts the document back
62 * into SAX event stream, and manipulate nodes in the document.
65 * 05.01.2004 - Interface supported: XXMLDocumentWrapper,
66 * XDocumentHandler, XCompressedDocumentHandler,
71 * Email: michael.mi@sun.com
72 ******************************************************************************/
78 /* the document used to convert SAX events to */
79 xmlDocPtr m_pDocument
;
81 /* the root element */
82 xmlNodePtr m_pRootElement
;
85 * the current active element. The next incoming SAX event will be
86 * appended to this element
88 xmlNodePtr m_pCurrentElement
;
91 * This variable is used when converting the document or part of it into
92 * SAX events. See getNextSAXEvent method.
94 sal_Int32 m_nCurrentPosition
;
97 * used for recursive deletion. See recursiveDelete method
99 xmlNodePtr m_pStopAtNode
;
100 xmlNodePtr m_pCurrentReservedNode
;
101 com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
102 com::sun::star::xml::wrapper::XXMLElementWrapper
> > m_aReservedNodes
;
103 sal_Int32 m_nReservedNodeIndex
;
106 void getNextSAXEvent();
108 void sendStartElement(
109 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
110 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
111 const xmlNodePtr pNode
) const
112 throw (com::sun::star::xml::sax::SAXException
);
115 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
116 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
117 const xmlNodePtr pNode
) const
118 throw (com::sun::star::xml::sax::SAXException
);
121 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
122 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
123 const xmlNodePtr pNode
) const
124 throw (com::sun::star::xml::sax::SAXException
);
126 rtl::OString
getNodeQName(const xmlNodePtr pNode
) const;
128 sal_Int32
recursiveDelete( const xmlNodePtr pNode
);
130 void getNextReservedNode();
132 void removeNode( const xmlNodePtr pNode
) const;
134 xmlNodePtr
checkElement(
135 const com::sun::star::uno::Reference
<
136 com::sun::star::xml::wrapper::XXMLElementWrapper
>& xXMLElement
) const;
138 void buildIDAttr( xmlNodePtr pNode
) const;
139 void rebuildIDLink( xmlNodePtr pNode
) const;
142 XMLDocumentWrapper_XmlSecImpl();
143 virtual ~XMLDocumentWrapper_XmlSecImpl();
145 /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */
146 virtual com::sun::star::uno::Reference
<
147 com::sun::star::xml::wrapper::XXMLElementWrapper
> SAL_CALL
getCurrentElement( )
148 throw (com::sun::star::uno::RuntimeException
);
150 virtual void SAL_CALL
setCurrentElement( const com::sun::star::uno::Reference
<
151 com::sun::star::xml::wrapper::XXMLElementWrapper
>& element
)
152 throw (com::sun::star::uno::RuntimeException
);
154 virtual void SAL_CALL
removeCurrentElement( )
155 throw (com::sun::star::uno::RuntimeException
);
157 virtual sal_Bool SAL_CALL
isCurrent( const com::sun::star::uno::Reference
<
158 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
159 throw (com::sun::star::uno::RuntimeException
);
161 virtual sal_Bool SAL_CALL
isCurrentElementEmpty( )
162 throw (com::sun::star::uno::RuntimeException
);
164 virtual rtl::OUString SAL_CALL
getNodeName( const com::sun::star::uno::Reference
<
165 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
166 throw (com::sun::star::uno::RuntimeException
);
168 virtual void SAL_CALL
clearUselessData(
169 const com::sun::star::uno::Reference
<
170 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
,
171 const com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
172 com::sun::star::xml::wrapper::XXMLElementWrapper
> >& reservedDescendants
,
173 const com::sun::star::uno::Reference
<
174 com::sun::star::xml::wrapper::XXMLElementWrapper
>& stopAtNode
)
175 throw (com::sun::star::uno::RuntimeException
);
177 virtual void SAL_CALL
collapse( const com::sun::star::uno::Reference
<
178 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
179 throw (com::sun::star::uno::RuntimeException
);
181 virtual void SAL_CALL
generateSAXEvents(
182 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
,
183 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xEventKeeperHandler
,
184 const com::sun::star::uno::Reference
<
185 com::sun::star::xml::wrapper::XXMLElementWrapper
>& startNode
,
186 const com::sun::star::uno::Reference
<
187 com::sun::star::xml::wrapper::XXMLElementWrapper
>& endNode
)
188 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
190 virtual void SAL_CALL
getTree(
191 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
)
192 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
194 virtual void SAL_CALL
rebuildIDLink(
195 const com::sun::star::uno::Reference
< com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
196 throw (com::sun::star::uno::RuntimeException
);
198 /* com::sun::star::xml::sax::XDocumentHandler */
199 virtual void SAL_CALL
startDocument( )
200 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
202 virtual void SAL_CALL
endDocument( )
203 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
205 virtual void SAL_CALL
startElement(
206 const rtl::OUString
& aName
,
207 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttribs
)
208 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
210 virtual void SAL_CALL
endElement( const rtl::OUString
& aName
)
211 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
213 virtual void SAL_CALL
characters( const rtl::OUString
& aChars
)
214 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
216 virtual void SAL_CALL
ignorableWhitespace( const rtl::OUString
& aWhitespaces
)
217 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
219 virtual void SAL_CALL
processingInstruction( const rtl::OUString
& aTarget
, const rtl::OUString
& aData
)
220 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
222 virtual void SAL_CALL
setDocumentLocator( const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XLocator
>& xLocator
)
223 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
225 /* com::sun::star::xml::csax::XCompressedDocumentHandler */
226 virtual void SAL_CALL
_startDocument( )
227 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
229 virtual void SAL_CALL
_endDocument( )
230 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
232 virtual void SAL_CALL
_startElement(
233 const rtl::OUString
& aName
,
234 const com::sun::star::uno::Sequence
<
235 com::sun::star::xml::csax::XMLAttribute
>& aAttributes
)
236 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
238 virtual void SAL_CALL
_endElement( const rtl::OUString
& aName
)
239 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
241 virtual void SAL_CALL
_characters( const rtl::OUString
& aChars
)
242 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
244 virtual void SAL_CALL
_ignorableWhitespace( const rtl::OUString
& aWhitespaces
)
245 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
247 virtual void SAL_CALL
_processingInstruction( const rtl::OUString
& aTarget
, const rtl::OUString
& aData
)
248 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
250 virtual void SAL_CALL
_setDocumentLocator(
251 sal_Int32 columnNumber
,
252 sal_Int32 lineNumber
,
253 const rtl::OUString
& publicId
,
254 const rtl::OUString
& systemId
)
255 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
257 /* com::sun::star::lang::XServiceInfo */
258 virtual rtl::OUString SAL_CALL
getImplementationName( )
259 throw (com::sun::star::uno::RuntimeException
);
261 virtual sal_Bool SAL_CALL
supportsService( const rtl::OUString
& ServiceName
)
262 throw (com::sun::star::uno::RuntimeException
);
264 virtual com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames( )
265 throw (com::sun::star::uno::RuntimeException
);
268 rtl::OUString
XMLDocumentWrapper_XmlSecImpl_getImplementationName()
269 throw ( com::sun::star::uno::RuntimeException
);
271 sal_Bool SAL_CALL
XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString
& ServiceName
)
272 throw ( com::sun::star::uno::RuntimeException
);
274 com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
275 XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( )
276 throw ( com::sun::star::uno::RuntimeException
);
278 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
279 SAL_CALL
XMLDocumentWrapper_XmlSecImpl_createInstance(
280 const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> & rSMgr
)
281 throw ( com::sun::star::uno::Exception
);