LibreOffice Module xmlsecurity (master) 1
xmldocumentwrapper_xmlsecimpl.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
26
27#include <xmlsec/saxhelper.hxx>
28#include <xsecxmlsecdllapi.h>
29
30#define NODEPOSITION_NORMAL 1
31#define NODEPOSITION_STARTELEMENT 2
32#define NODEPOSITION_ENDELEMENT 3
33
34#include <libxml/tree.h>
35
36class XSECXMLSEC_DLLPUBLIC XMLDocumentWrapper_XmlSecImpl final : public cppu::WeakImplHelper
37<
38 css::xml::wrapper::XXMLDocumentWrapper,
39 css::xml::sax::XDocumentHandler,
40 css::xml::csax::XCompressedDocumentHandler,
41 css::lang::XServiceInfo
42>
52{
53private:
54 /* the sax helper */
56
57 /* the document used to convert SAX events to */
58 xmlDocPtr m_pDocument;
59
60 /* the root element */
61 xmlNodePtr m_pRootElement;
62
63 /*
64 * the current active element. The next incoming SAX event will be
65 * appended to this element
66 */
68
69 /*
70 * This variable is used when converting the document or part of it into
71 * SAX events. See getNextSAXEvent method.
72 */
74
75 /*
76 * used for recursive deletion. See recursiveDelete method
77 */
78 xmlNodePtr m_pStopAtNode;
80 css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes;
82
83private:
84 void getNextSAXEvent();
85
87 static void sendStartElement(
88 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler,
89 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler2,
90 const xmlNodePtr pNode);
91
93 static void sendEndElement(
94 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler,
95 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler2,
96 const xmlNodePtr pNode);
97
99 static void sendNode(
100 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler,
101 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xHandler2,
102 const xmlNodePtr pNode);
103
104 static OString getNodeQName(const xmlNodePtr pNode);
105
106 sal_Int32 recursiveDelete( const xmlNodePtr pNode);
107
108 void getNextReservedNode();
109
110 void removeNode( const xmlNodePtr pNode) const;
111
112 static xmlNodePtr checkElement(
113 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& xXMLElement);
114
115 void buildIDAttr( xmlNodePtr pNode ) const;
116 void rebuildIDLink( xmlNodePtr pNode ) const;
117
118public:
120 virtual ~XMLDocumentWrapper_XmlSecImpl() override;
121
122 /* css::xml::wrapper::XXMLDocumentWrapper */
123 virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentElement( ) override;
124
125 virtual void SAL_CALL setCurrentElement( const css::uno::Reference<
126 css::xml::wrapper::XXMLElementWrapper >& element ) override;
127
128 virtual void SAL_CALL removeCurrentElement( ) override;
129
130 virtual sal_Bool SAL_CALL isCurrent( const css::uno::Reference<
131 css::xml::wrapper::XXMLElementWrapper >& node ) override;
132
133 virtual sal_Bool SAL_CALL isCurrentElementEmpty( ) override;
134
135 virtual OUString SAL_CALL getNodeName( const css::uno::Reference<
136 css::xml::wrapper::XXMLElementWrapper >& node ) override;
137
138 virtual void SAL_CALL clearUselessData(
139 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& node,
140 const css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > >& reservedDescendants,
141 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& stopAtNode ) override;
142
143 virtual void SAL_CALL collapse( const css::uno::Reference<
144 css::xml::wrapper::XXMLElementWrapper >& node ) override;
145
146 virtual void SAL_CALL generateSAXEvents(
147 const css::uno::Reference< css::xml::sax::XDocumentHandler >& handler,
148 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xEventKeeperHandler,
149 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& startNode,
150 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& endNode ) override;
151
152 virtual void SAL_CALL getTree(
153 const css::uno::Reference< css::xml::sax::XDocumentHandler >& handler ) override;
154
155 virtual void SAL_CALL rebuildIDLink(
156 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& node ) override;
157
158 /* css::xml::sax::XDocumentHandler */
159 virtual void SAL_CALL startDocument( ) override;
160
161 virtual void SAL_CALL endDocument( ) override;
162
163 virtual void SAL_CALL startElement(
164 const OUString& aName,
165 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs ) override;
166
167 virtual void SAL_CALL endElement( const OUString& aName ) override;
168
169 virtual void SAL_CALL characters( const OUString& aChars ) override;
170
171 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
172
173 virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override;
174
175 virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
176
177 /* css::xml::csax::XCompressedDocumentHandler */
178 virtual void SAL_CALL compressedStartDocument( ) override;
179
180 virtual void SAL_CALL compressedEndDocument( ) override;
181
182 virtual void SAL_CALL compressedStartElement(
183 const OUString& aName,
184 const css::uno::Sequence< css::xml::csax::XMLAttribute >& aAttributes ) override;
185
186 virtual void SAL_CALL compressedEndElement( const OUString& aName ) override;
187
188 virtual void SAL_CALL compressedCharacters( const OUString& aChars ) override;
189
190 virtual void SAL_CALL compressedIgnorableWhitespace( const OUString& aWhitespaces ) override;
191
192 virtual void SAL_CALL compressedProcessingInstruction( const OUString& aTarget, const OUString& aData ) override;
193
194 virtual void SAL_CALL compressedSetDocumentLocator(
195 sal_Int32 columnNumber,
196 sal_Int32 lineNumber,
197 const OUString& publicId,
198 const OUString& systemId ) override;
199
200 /* css::lang::XServiceInfo */
201 virtual OUString SAL_CALL getImplementationName( ) override;
202
203 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
204
205 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
206};
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class represents a SAX handler which simply forwards to the corresponding libxml API and transla...
Definition: saxhelper.hxx:37
NAME XMLDocumentWrapper_XmlSecImpl – Class to manipulate a libxml2 document.
css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool
#define XSECXMLSEC_DLLPUBLIC