1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmldocumentwrapper_xmlsecimpl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
32 #define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
34 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
35 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
36 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <cppuhelper/implbase4.hxx>
40 #include "saxhelper.hxx"
41 //#include "libxml/parserInternals.h"
42 //#include "libxslt/xslt.h"
44 #define NODEPOSITION_NORMAL 1
45 #define NODEPOSITION_STARTELEMENT 2
46 #define NODEPOSITION_ENDELEMENT 3
48 #include <libxml/tree.h>
50 class XMLDocumentWrapper_XmlSecImpl
: public cppu::WeakImplHelper4
52 com::sun::star::xml::wrapper::XXMLDocumentWrapper
,
53 com::sun::star::xml::sax::XDocumentHandler
,
54 com::sun::star::xml::csax::XCompressedDocumentHandler
,
55 com::sun::star::lang::XServiceInfo
57 /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl *
60 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
64 * Converts SAX events into a libxml2 document, converts the document back
65 * into SAX event stream, and manipulate nodes in the document.
68 * 05.01.2004 - Interface supported: XXMLDocumentWrapper,
69 * XDocumentHandler, XCompressedDocumentHandler,
74 * Email: michael.mi@sun.com
75 ******************************************************************************/
81 /* the document used to convert SAX events to */
82 xmlDocPtr m_pDocument
;
84 /* the root element */
85 xmlNodePtr m_pRootElement
;
88 * the current active element. The next incoming SAX event will be
89 * appended to this element
91 xmlNodePtr m_pCurrentElement
;
94 * This variable is used when converting the document or part of it into
95 * SAX events. See getNextSAXEvent method.
97 sal_Int32 m_nCurrentPosition
;
100 * used for recursive deletion. See recursiveDelete method
102 xmlNodePtr m_pStopAtNode
;
103 xmlNodePtr m_pCurrentReservedNode
;
104 com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
105 com::sun::star::xml::wrapper::XXMLElementWrapper
> > m_aReservedNodes
;
106 sal_Int32 m_nReservedNodeIndex
;
109 void getNextSAXEvent();
111 void sendStartElement(
112 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
113 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
114 const xmlNodePtr pNode
) const
115 throw (com::sun::star::xml::sax::SAXException
);
118 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
119 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
120 const xmlNodePtr pNode
) const
121 throw (com::sun::star::xml::sax::SAXException
);
124 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
125 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
126 const xmlNodePtr pNode
) const
127 throw (com::sun::star::xml::sax::SAXException
);
129 rtl::OString
getNodeQName(const xmlNodePtr pNode
) const;
131 sal_Int32
recursiveDelete( const xmlNodePtr pNode
);
133 void getNextReservedNode();
135 void removeNode( const xmlNodePtr pNode
) const;
137 xmlNodePtr
checkElement(
138 const com::sun::star::uno::Reference
<
139 com::sun::star::xml::wrapper::XXMLElementWrapper
>& xXMLElement
) const;
141 void buildIDAttr( xmlNodePtr pNode
) const;
142 void rebuildIDLink( xmlNodePtr pNode
) const;
145 XMLDocumentWrapper_XmlSecImpl();
146 virtual ~XMLDocumentWrapper_XmlSecImpl();
148 /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */
149 virtual com::sun::star::uno::Reference
<
150 com::sun::star::xml::wrapper::XXMLElementWrapper
> SAL_CALL
getCurrentElement( )
151 throw (com::sun::star::uno::RuntimeException
);
153 virtual void SAL_CALL
setCurrentElement( const com::sun::star::uno::Reference
<
154 com::sun::star::xml::wrapper::XXMLElementWrapper
>& element
)
155 throw (com::sun::star::uno::RuntimeException
);
157 virtual void SAL_CALL
removeCurrentElement( )
158 throw (com::sun::star::uno::RuntimeException
);
160 virtual sal_Bool SAL_CALL
isCurrent( const com::sun::star::uno::Reference
<
161 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
162 throw (com::sun::star::uno::RuntimeException
);
164 virtual sal_Bool SAL_CALL
isCurrentElementEmpty( )
165 throw (com::sun::star::uno::RuntimeException
);
167 virtual rtl::OUString SAL_CALL
getNodeName( const com::sun::star::uno::Reference
<
168 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
169 throw (com::sun::star::uno::RuntimeException
);
171 virtual void SAL_CALL
clearUselessData(
172 const com::sun::star::uno::Reference
<
173 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
,
174 const com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
175 com::sun::star::xml::wrapper::XXMLElementWrapper
> >& reservedDescendants
,
176 const com::sun::star::uno::Reference
<
177 com::sun::star::xml::wrapper::XXMLElementWrapper
>& stopAtNode
)
178 throw (com::sun::star::uno::RuntimeException
);
180 virtual void SAL_CALL
collapse( const com::sun::star::uno::Reference
<
181 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
182 throw (com::sun::star::uno::RuntimeException
);
184 virtual void SAL_CALL
generateSAXEvents(
185 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
,
186 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xEventKeeperHandler
,
187 const com::sun::star::uno::Reference
<
188 com::sun::star::xml::wrapper::XXMLElementWrapper
>& startNode
,
189 const com::sun::star::uno::Reference
<
190 com::sun::star::xml::wrapper::XXMLElementWrapper
>& endNode
)
191 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
193 virtual void SAL_CALL
getTree(
194 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
)
195 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
197 virtual void SAL_CALL
rebuildIDLink(
198 const com::sun::star::uno::Reference
< com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
199 throw (com::sun::star::uno::RuntimeException
);
201 /* com::sun::star::xml::sax::XDocumentHandler */
202 virtual void SAL_CALL
startDocument( )
203 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
205 virtual void SAL_CALL
endDocument( )
206 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
208 virtual void SAL_CALL
startElement(
209 const rtl::OUString
& aName
,
210 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttribs
)
211 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
213 virtual void SAL_CALL
endElement( const rtl::OUString
& aName
)
214 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
216 virtual void SAL_CALL
characters( const rtl::OUString
& aChars
)
217 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
219 virtual void SAL_CALL
ignorableWhitespace( const rtl::OUString
& aWhitespaces
)
220 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
222 virtual void SAL_CALL
processingInstruction( const rtl::OUString
& aTarget
, const rtl::OUString
& aData
)
223 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
225 virtual void SAL_CALL
setDocumentLocator( const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XLocator
>& xLocator
)
226 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
228 /* com::sun::star::xml::csax::XCompressedDocumentHandler */
229 virtual void SAL_CALL
_startDocument( )
230 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
232 virtual void SAL_CALL
_endDocument( )
233 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
235 virtual void SAL_CALL
_startElement(
236 const rtl::OUString
& aName
,
237 const com::sun::star::uno::Sequence
<
238 com::sun::star::xml::csax::XMLAttribute
>& aAttributes
)
239 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
241 virtual void SAL_CALL
_endElement( const rtl::OUString
& aName
)
242 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
244 virtual void SAL_CALL
_characters( const rtl::OUString
& aChars
)
245 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
247 virtual void SAL_CALL
_ignorableWhitespace( const rtl::OUString
& aWhitespaces
)
248 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
250 virtual void SAL_CALL
_processingInstruction( const rtl::OUString
& aTarget
, const rtl::OUString
& aData
)
251 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
253 virtual void SAL_CALL
_setDocumentLocator(
254 sal_Int32 columnNumber
,
255 sal_Int32 lineNumber
,
256 const rtl::OUString
& publicId
,
257 const rtl::OUString
& systemId
)
258 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
);
260 /* com::sun::star::lang::XServiceInfo */
261 virtual rtl::OUString SAL_CALL
getImplementationName( )
262 throw (com::sun::star::uno::RuntimeException
);
264 virtual sal_Bool SAL_CALL
supportsService( const rtl::OUString
& ServiceName
)
265 throw (com::sun::star::uno::RuntimeException
);
267 virtual com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames( )
268 throw (com::sun::star::uno::RuntimeException
);
271 rtl::OUString
XMLDocumentWrapper_XmlSecImpl_getImplementationName()
272 throw ( com::sun::star::uno::RuntimeException
);
274 sal_Bool SAL_CALL
XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString
& ServiceName
)
275 throw ( com::sun::star::uno::RuntimeException
);
277 com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
278 XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( )
279 throw ( com::sun::star::uno::RuntimeException
);
281 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
282 SAL_CALL
XMLDocumentWrapper_XmlSecImpl_createInstance(
283 const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> & rSMgr
)
284 throw ( com::sun::star::uno::Exception
);