1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_XMLSECURITY_SOURCE_XMLSEC_XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
21 #define INCLUDED_XMLSECURITY_SOURCE_XMLSEC_XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
23 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
24 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
25 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/implbase4.hxx>
29 #include "saxhelper.hxx"
31 #define NODEPOSITION_NORMAL 1
32 #define NODEPOSITION_STARTELEMENT 2
33 #define NODEPOSITION_ENDELEMENT 3
35 #include <libxml/tree.h>
37 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
38 class XComponentContext
;
41 class XMLDocumentWrapper_XmlSecImpl
: public cppu::WeakImplHelper4
43 com::sun::star::xml::wrapper::XXMLDocumentWrapper
,
44 com::sun::star::xml::sax::XDocumentHandler
,
45 com::sun::star::xml::csax::XCompressedDocumentHandler
,
46 com::sun::star::lang::XServiceInfo
48 /****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl *
51 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
55 * Converts SAX events into a libxml2 document, converts the document back
56 * into SAX event stream, and manipulate nodes in the document.
60 * Email: michael.mi@sun.com
61 ******************************************************************************/
67 /* the document used to convert SAX events to */
68 xmlDocPtr m_pDocument
;
70 /* the root element */
71 xmlNodePtr m_pRootElement
;
74 * the current active element. The next incoming SAX event will be
75 * appended to this element
77 xmlNodePtr m_pCurrentElement
;
80 * This variable is used when converting the document or part of it into
81 * SAX events. See getNextSAXEvent method.
83 sal_Int32 m_nCurrentPosition
;
86 * used for recursive deletion. See recursiveDelete method
88 xmlNodePtr m_pStopAtNode
;
89 xmlNodePtr m_pCurrentReservedNode
;
90 com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
91 com::sun::star::xml::wrapper::XXMLElementWrapper
> > m_aReservedNodes
;
92 sal_Int32 m_nReservedNodeIndex
;
95 void getNextSAXEvent();
97 static void sendStartElement(
98 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
99 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
100 const xmlNodePtr pNode
)
101 throw (com::sun::star::xml::sax::SAXException
);
103 static void sendEndElement(
104 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
105 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
106 const xmlNodePtr pNode
)
107 throw (com::sun::star::xml::sax::SAXException
);
109 static void sendNode(
110 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler
,
111 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xHandler2
,
112 const xmlNodePtr pNode
)
113 throw (com::sun::star::xml::sax::SAXException
);
115 static OString
getNodeQName(const xmlNodePtr pNode
);
117 sal_Int32
recursiveDelete( const xmlNodePtr pNode
);
119 void getNextReservedNode();
121 void removeNode( const xmlNodePtr pNode
) const;
123 static xmlNodePtr
checkElement(
124 const com::sun::star::uno::Reference
<
125 com::sun::star::xml::wrapper::XXMLElementWrapper
>& xXMLElement
);
127 void buildIDAttr( xmlNodePtr pNode
) const;
128 void rebuildIDLink( xmlNodePtr pNode
) const;
131 XMLDocumentWrapper_XmlSecImpl();
132 virtual ~XMLDocumentWrapper_XmlSecImpl();
134 /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */
135 virtual com::sun::star::uno::Reference
<
136 com::sun::star::xml::wrapper::XXMLElementWrapper
> SAL_CALL
getCurrentElement( )
137 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
139 virtual void SAL_CALL
setCurrentElement( const com::sun::star::uno::Reference
<
140 com::sun::star::xml::wrapper::XXMLElementWrapper
>& element
)
141 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 virtual void SAL_CALL
removeCurrentElement( )
144 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
146 virtual sal_Bool SAL_CALL
isCurrent( const com::sun::star::uno::Reference
<
147 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
148 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
150 virtual sal_Bool SAL_CALL
isCurrentElementEmpty( )
151 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 virtual OUString SAL_CALL
getNodeName( const com::sun::star::uno::Reference
<
154 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
155 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
157 virtual void SAL_CALL
clearUselessData(
158 const com::sun::star::uno::Reference
<
159 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
,
160 const com::sun::star::uno::Sequence
< com::sun::star::uno::Reference
<
161 com::sun::star::xml::wrapper::XXMLElementWrapper
> >& reservedDescendants
,
162 const com::sun::star::uno::Reference
<
163 com::sun::star::xml::wrapper::XXMLElementWrapper
>& stopAtNode
)
164 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
166 virtual void SAL_CALL
collapse( const com::sun::star::uno::Reference
<
167 com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
168 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
170 virtual void SAL_CALL
generateSAXEvents(
171 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
,
172 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& xEventKeeperHandler
,
173 const com::sun::star::uno::Reference
<
174 com::sun::star::xml::wrapper::XXMLElementWrapper
>& startNode
,
175 const com::sun::star::uno::Reference
<
176 com::sun::star::xml::wrapper::XXMLElementWrapper
>& endNode
)
177 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
179 virtual void SAL_CALL
getTree(
180 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
>& handler
)
181 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
183 virtual void SAL_CALL
rebuildIDLink(
184 const com::sun::star::uno::Reference
< com::sun::star::xml::wrapper::XXMLElementWrapper
>& node
)
185 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
187 /* com::sun::star::xml::sax::XDocumentHandler */
188 virtual void SAL_CALL
startDocument( )
189 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
191 virtual void SAL_CALL
endDocument( )
192 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
194 virtual void SAL_CALL
startElement(
195 const OUString
& aName
,
196 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttribs
)
197 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
199 virtual void SAL_CALL
endElement( const OUString
& aName
)
200 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
202 virtual void SAL_CALL
characters( const OUString
& aChars
)
203 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
205 virtual void SAL_CALL
ignorableWhitespace( const OUString
& aWhitespaces
)
206 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
208 virtual void SAL_CALL
processingInstruction( const OUString
& aTarget
, const OUString
& aData
)
209 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
211 virtual void SAL_CALL
setDocumentLocator( const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XLocator
>& xLocator
)
212 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
214 /* com::sun::star::xml::csax::XCompressedDocumentHandler */
215 virtual void SAL_CALL
compressedStartDocument( )
216 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
218 virtual void SAL_CALL
compressedEndDocument( )
219 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
221 virtual void SAL_CALL
compressedStartElement(
222 const OUString
& aName
,
223 const com::sun::star::uno::Sequence
<
224 com::sun::star::xml::csax::XMLAttribute
>& aAttributes
)
225 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
227 virtual void SAL_CALL
compressedEndElement( const OUString
& aName
)
228 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
230 virtual void SAL_CALL
compressedCharacters( const OUString
& aChars
)
231 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual void SAL_CALL
compressedIgnorableWhitespace( const OUString
& aWhitespaces
)
234 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
236 virtual void SAL_CALL
compressedProcessingInstruction( const OUString
& aTarget
, const OUString
& aData
)
237 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
239 virtual void SAL_CALL
compressedSetDocumentLocator(
240 sal_Int32 columnNumber
,
241 sal_Int32 lineNumber
,
242 const OUString
& publicId
,
243 const OUString
& systemId
)
244 throw (com::sun::star::xml::sax::SAXException
, com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
246 /* com::sun::star::lang::XServiceInfo */
247 virtual OUString SAL_CALL
getImplementationName( )
248 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
250 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
251 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
253 virtual com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( )
254 throw (com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 OUString
XMLDocumentWrapper_XmlSecImpl_getImplementationName()
258 throw ( com::sun::star::uno::RuntimeException
);
260 com::sun::star::uno::Sequence
< OUString
> SAL_CALL
261 XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( )
262 throw ( com::sun::star::uno::RuntimeException
);
264 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>
265 SAL_CALL
XMLDocumentWrapper_XmlSecImpl_createInstance(
266 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> &)
267 throw ( com::sun::star::uno::Exception
);
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */