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 .
22 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
23 #include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <cppuhelper/implbase.hxx>
27 #include <xmlsec/saxhelper.hxx>
28 #include <xsecxmlsecdllapi.h>
30 #define NODEPOSITION_NORMAL 1
31 #define NODEPOSITION_STARTELEMENT 2
32 #define NODEPOSITION_ENDELEMENT 3
34 class XMLDocumentWrapper_XmlSecImpl final
: public cppu::WeakImplHelper
36 css::xml::wrapper::XXMLDocumentWrapper
,
37 css::xml::sax::XDocumentHandler
,
38 css::xml::csax::XCompressedDocumentHandler
,
39 css::lang::XServiceInfo
43 * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
47 * Converts SAX events into a libxml2 document, converts the document back
48 * into SAX event stream, and manipulate nodes in the document.
49 ******************************************************************************/
55 /* the document used to convert SAX events to */
56 xmlDocPtr m_pDocument
;
58 /* the root element */
59 xmlNodePtr m_pRootElement
;
62 * the current active element. The next incoming SAX event will be
63 * appended to this element
65 xmlNodePtr m_pCurrentElement
;
68 * This variable is used when converting the document or part of it into
69 * SAX events. See getNextSAXEvent method.
71 sal_Int32 m_nCurrentPosition
;
74 * used for recursive deletion. See recursiveDelete method
76 xmlNodePtr m_pStopAtNode
;
77 xmlNodePtr m_pCurrentReservedNode
;
78 css::uno::Sequence
< css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
> > m_aReservedNodes
;
79 sal_Int32 m_nReservedNodeIndex
;
82 void getNextSAXEvent();
84 /// @throws css::xml::sax::SAXException
85 static void sendStartElement(
86 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler
,
87 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler2
,
88 const xmlNodePtr pNode
);
90 /// @throws css::xml::sax::SAXException
91 static void sendEndElement(
92 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler
,
93 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler2
,
94 const xmlNodePtr pNode
);
96 /// @throws css::xml::sax::SAXException
98 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler
,
99 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xHandler2
,
100 const xmlNodePtr pNode
);
102 static OString
getNodeQName(const xmlNodePtr pNode
);
104 sal_Int32
recursiveDelete( const xmlNodePtr pNode
);
106 void getNextReservedNode();
108 void removeNode( const xmlNodePtr pNode
) const;
110 static xmlNodePtr
checkElement(
111 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& xXMLElement
);
113 void buildIDAttr( xmlNodePtr pNode
) const;
114 void rebuildIDLink( xmlNodePtr pNode
) const;
117 XSECXMLSEC_DLLPUBLIC
XMLDocumentWrapper_XmlSecImpl();
118 virtual ~XMLDocumentWrapper_XmlSecImpl() override
;
120 /* css::xml::wrapper::XXMLDocumentWrapper */
121 virtual css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
> SAL_CALL
getCurrentElement( ) override
;
123 virtual void SAL_CALL
setCurrentElement( const css::uno::Reference
<
124 css::xml::wrapper::XXMLElementWrapper
>& element
) override
;
126 virtual void SAL_CALL
removeCurrentElement( ) override
;
128 virtual sal_Bool SAL_CALL
isCurrent( const css::uno::Reference
<
129 css::xml::wrapper::XXMLElementWrapper
>& node
) override
;
131 virtual sal_Bool SAL_CALL
isCurrentElementEmpty( ) override
;
133 virtual OUString SAL_CALL
getNodeName( const css::uno::Reference
<
134 css::xml::wrapper::XXMLElementWrapper
>& node
) override
;
136 virtual void SAL_CALL
clearUselessData(
137 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& node
,
138 const css::uno::Sequence
< css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
> >& reservedDescendants
,
139 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& stopAtNode
) override
;
141 virtual void SAL_CALL
collapse( const css::uno::Reference
<
142 css::xml::wrapper::XXMLElementWrapper
>& node
) override
;
144 virtual void SAL_CALL
generateSAXEvents(
145 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& handler
,
146 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& xEventKeeperHandler
,
147 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& startNode
,
148 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& endNode
) override
;
150 virtual void SAL_CALL
getTree(
151 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& handler
) override
;
153 virtual void SAL_CALL
rebuildIDLink(
154 const css::uno::Reference
< css::xml::wrapper::XXMLElementWrapper
>& node
) override
;
156 /* css::xml::sax::XDocumentHandler */
157 virtual void SAL_CALL
startDocument( ) override
;
159 virtual void SAL_CALL
endDocument( ) override
;
161 virtual void SAL_CALL
startElement(
162 const OUString
& aName
,
163 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
) override
;
165 virtual void SAL_CALL
endElement( const OUString
& aName
) override
;
167 virtual void SAL_CALL
characters( const OUString
& aChars
) override
;
169 virtual void SAL_CALL
ignorableWhitespace( const OUString
& aWhitespaces
) override
;
171 virtual void SAL_CALL
processingInstruction( const OUString
& aTarget
, const OUString
& aData
) override
;
173 virtual void SAL_CALL
setDocumentLocator( const css::uno::Reference
< css::xml::sax::XLocator
>& xLocator
) override
;
175 /* css::xml::csax::XCompressedDocumentHandler */
176 virtual void SAL_CALL
compressedStartDocument( ) override
;
178 virtual void SAL_CALL
compressedEndDocument( ) override
;
180 virtual void SAL_CALL
compressedStartElement(
181 const OUString
& aName
,
182 const css::uno::Sequence
< css::xml::csax::XMLAttribute
>& aAttributes
) override
;
184 virtual void SAL_CALL
compressedEndElement( const OUString
& aName
) override
;
186 virtual void SAL_CALL
compressedCharacters( const OUString
& aChars
) override
;
188 virtual void SAL_CALL
compressedIgnorableWhitespace( const OUString
& aWhitespaces
) override
;
190 virtual void SAL_CALL
compressedProcessingInstruction( const OUString
& aTarget
, const OUString
& aData
) override
;
192 virtual void SAL_CALL
compressedSetDocumentLocator(
193 sal_Int32 columnNumber
,
194 sal_Int32 lineNumber
,
195 const OUString
& publicId
,
196 const OUString
& systemId
) override
;
198 /* css::lang::XServiceInfo */
199 virtual OUString SAL_CALL
getImplementationName( ) override
;
201 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
203 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */